From: Florian Brosch Date: Mon, 16 Jan 2012 00:03:17 +0000 (+0100) Subject: libvaladoc: ModuleLoader cleanups X-Git-Tag: 0.37.1~3^2~244 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a58dcd25cb62f22e94fb223e93cecdb902bc72d;p=thirdparty%2Fvala.git libvaladoc: ModuleLoader cleanups --- diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am index fe3115c8e..7db46be6b 100755 --- a/src/libvaladoc/Makefile.am +++ b/src/libvaladoc/Makefile.am @@ -4,18 +4,21 @@ NULL = AM_CFLAGS = \ -DPACKAGE_ICONDIR=\"$(datadir)/valadoc/icons/\" \ - $(LIBGVC_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(LIBGEE_CFLAGS) \ - $(GMODULE_CFLAGS) \ + -DPACKAGE_DATADIR=\"$(libdir)/valadoc\" \ + -DPACKAGE_VERSION=\"$(VERSION)\" \ + -DDEFAULT_DRIVER=\"$(DEFAULT_DRIVER)\" \ + $(LIBGVC_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(LIBGEE_CFLAGS) \ + $(GMODULE_CFLAGS) \ $(NULL) BUILT_SOURCES = libvaladoc.vala.stamp -lib_LTLIBRARIES = \ - libvaladoc.la \ +lib_LTLIBRARIES = \ + libvaladoc.la \ $(NULL) @@ -181,7 +184,7 @@ libvaladoc_la_LIBADD = \ $(NULL) -EXTRA_DIST = \ +EXTRA_DIST = \ $(libvaladoc_la_VALASOURCES) \ libvaladoc.vala.stamp \ valadoc-1.0.vapi \ @@ -189,7 +192,7 @@ EXTRA_DIST = \ $(NULL) -MAINTAINERCLEANFILES = \ +MAINTAINERCLEANFILES = \ valadoc-1.0.vapi \ valadoc-1.0.h \ valadoc-1.0.gir \ diff --git a/src/libvaladoc/moduleloader.vala b/src/libvaladoc/moduleloader.vala index 123d0e4d7..2bb427644 100755 --- a/src/libvaladoc/moduleloader.vala +++ b/src/libvaladoc/moduleloader.vala @@ -35,11 +35,135 @@ public class Valadoc.ModuleLoader : Object { private HashMap drivers = new HashMap (); private HashMap taglets = new HashMap (); + private static ModuleLoader instance; + + public static ModuleLoader get_instance () { + if (instance == null) { + instance = new ModuleLoader (); + Taglets.init (instance); + } + return instance; + } + + private ModuleLoader () { + } + private class ModuleData : Object { public Module module; public Type type; } + + // + // driver path helpers: + // + + private struct DriverMetaData { + public int64[] segments_min; + public int64[] segments_max; + public string driver_name; + + public DriverMetaData (int64 min_a, int64 min_b, int64 max_a, int64 max_b, string driver_name) { + this.segments_min = {min_a, min_b}; + this.segments_max = {max_a, max_b}; + this.driver_name = driver_name; + } + } + + public static bool is_driver (string path) { + string library_path = Path.build_filename (path, "libdriver." + Module.SUFFIX); + return FileUtils.test (path, FileTest.EXISTS) && FileUtils.test (library_path, FileTest.EXISTS); + } + + private static string get_plugin_path (string pluginpath, string pluginsubdir) { + if (Path.is_absolute (pluginpath) == false) { + // Test to see if the plugin exists in the expanded path and then fallback + // to using the configured plugin directory + string local_path = Path.build_filename (Environment.get_current_dir(), pluginpath); + if (FileUtils.test(local_path, FileTest.EXISTS)) { + return local_path; + } else { + return Path.build_filename (Config.plugin_dir, pluginsubdir, pluginpath); + } + } + + return pluginpath; + } + + public static string get_doclet_path (string? docletpath, ErrorReporter reporter) { + if (docletpath == null) { + return Path.build_filename (Config.plugin_dir, "doclets", "html"); + } + + return get_plugin_path (docletpath, "doclets"); + } + + public static string? get_driver_path (string? _driverpath, ErrorReporter reporter) { + string? driverpath = _driverpath; + // no driver selected + if (driverpath == null) { + driverpath = Config.default_driver; + } + + + // selected string is a plugin directory + string extended_driver_path = get_plugin_path (driverpath, "drivers"); + if (is_driver (extended_driver_path)) { + return extended_driver_path; + } + + + // selected string is a version number: + if (driverpath.has_prefix ("Vala ")) { + driverpath = driverpath.substring (5); + } + + string[] segments = driverpath.split ("."); + if (segments.length != 3 && segments.length != 4) { + reporter.simple_error ("Invalid driver version format."); + return null; + } + + + int64 segment_a; + int64 segment_b; + int64 segment_c; + bool tmp; + + tmp = int64.try_parse (segments[0], out segment_a); + tmp &= int64.try_parse (segments[1], out segment_b); + tmp &= int64.try_parse (segments[2], out segment_c); + + if (!tmp) { + reporter.simple_error ("Invalid driver version format."); + return null; + } + + DriverMetaData[] lut = { + DriverMetaData (0, 10, 0, 10, "0.10.x"), + DriverMetaData (0, 11, 0, 12, "0.12.x"), + DriverMetaData (0, 13, 0, 14, "0.14.x"), + DriverMetaData (0, 15, 0, 15, "0.16.x") + }; + + + for (int i = 0; i < lut.length ; i++) { + bool frst_seg = lut[i].segments_min[0] <= segment_a && lut[i].segments_max[0] >= segment_a; + bool scnd_seg = lut[i].segments_min[1] <= segment_b && lut[i].segments_max[1] >= segment_b; + if (frst_seg && scnd_seg) { + return Path.build_filename (Config.plugin_dir, "drivers", lut[i].driver_name); + } + } + + + reporter.simple_error ("No suitable driver found."); + return null; + } + + // + // Creation methods: + // + public Content.Taglet? create_taglet (string keyword) { return (taglets.has_key (keyword))? (Content.Taglet) GLib.Object.new (taglets.get (keyword)) : null; } diff --git a/src/valadoc/valadoc.vala b/src/valadoc/valadoc.vala index 380da9eb7..611940e09 100755 --- a/src/valadoc/valadoc.vala +++ b/src/valadoc/valadoc.vala @@ -117,30 +117,6 @@ public class ValaDoc : Object { { null } }; - private struct LibvalaVersion { - public int segment_a; - public int segment_b; - public int segment_c; - - public LibvalaVersion (int seg_a, int seg_b, int seg_c) { - segment_a = seg_a; - segment_b = seg_b; - segment_c = seg_c; - } - } - - private struct DriverMetaData { - public LibvalaVersion min; - public LibvalaVersion max; - public string driver; - - public DriverMetaData (LibvalaVersion min, LibvalaVersion max, string driver) { - this.driver = driver; - this.min = min; - this.max = max; - } - } - private static int quit (ErrorReporter reporter) { if (reporter.errors == 0) { stdout.printf ("Succeeded - %d warning(s)\n", reporter.warnings); @@ -180,103 +156,14 @@ public class ValaDoc : Object { return this.pkg_name; } - private string get_plugin_path (string pluginpath, string pluginsubdir) { - if (is_absolute (pluginpath) == false) { - // Test to see if the plugin exists in the expanded path and then fallback - // to using the configured plugin directory - string local_path = build_filename (Environment.get_current_dir(), pluginpath); - if (FileUtils.test(local_path, FileTest.EXISTS)) { - return local_path; - } else { - return build_filename (Config.plugin_dir, pluginsubdir, pluginpath); - } - } - - return pluginpath; - } - - private string get_doclet_path (ErrorReporter reporter) { - if (docletpath == null) { - return build_filename (Config.plugin_dir, "doclets", "html"); - } - - return get_plugin_path (docletpath, "doclets"); - } - - private bool is_driver (string path) { - string library_path = Path.build_filename (path, "libdriver." + Module.SUFFIX); - return FileUtils.test (path, FileTest.EXISTS) && FileUtils.test (library_path, FileTest.EXISTS); - } - - private string? get_driver_path (ErrorReporter reporter) { - // no driver selected - if (driverpath == null) { - driverpath = Config.default_driver; - } - - - // selected string is a plugin directory - string extended_driver_path = get_plugin_path (driverpath, "drivers"); - if (is_driver (extended_driver_path)) { - return extended_driver_path; - } - - - // selected string is a version number: - if (driverpath.has_prefix ("Vala ")) { - driverpath = driverpath.substring (5); - } - - string[] segments = driverpath.split ("."); - if (segments.length != 3 && segments.length != 4) { - reporter.simple_error ("Invalid driver version format."); - return null; - } - - - //TODO: add try_parse to int - int64 segment_a; - int64 segment_b; - int64 segment_c; - bool tmp; - - tmp = int64.try_parse (segments[0], out segment_a); - tmp &= int64.try_parse (segments[1], out segment_b); - tmp &= int64.try_parse (segments[2], out segment_c); - - if (!tmp) { - reporter.simple_error ("Invalid driver version format."); - return null; - } - - DriverMetaData[] lut = { - DriverMetaData (LibvalaVersion (0, 10, 0), LibvalaVersion (0, 10, -1), "0.10.x"), - DriverMetaData (LibvalaVersion (0, 12, 0), LibvalaVersion (0, 12, -1), "0.12.x"), - DriverMetaData (LibvalaVersion (0, 14, 0), LibvalaVersion (0, 14, -1), "0.14.x") - }; - - for (int i = 0; i < lut.length ; i++) { - if (lut[i].min.segment_a <= segment_a && lut[i].max.segment_a >= segment_a - && lut[i].min.segment_b <= segment_b && lut[i].max.segment_b >= segment_b - && lut[i].min.segment_c <= segment_c && (lut[i].max.segment_c >= segment_c || lut[i].max.segment_c < 0)) { - return Path.build_filename (Config.plugin_dir, "drivers", lut[i].driver); - } - } - - // return invalid driver path - reporter.simple_error ("No suitable driver found."); - return null; - } - private ModuleLoader? create_module_loader (ErrorReporter reporter, out Doclet? doclet, out Driver? driver) { - ModuleLoader modules = new ModuleLoader (); - Taglets.init (modules); + ModuleLoader modules = ModuleLoader.get_instance (); doclet = null; driver = null; // doclet: - string? pluginpath = get_doclet_path (reporter); + string? pluginpath = ModuleLoader.get_doclet_path (docletpath, reporter); if (pluginpath == null) { return null; } @@ -289,7 +176,7 @@ public class ValaDoc : Object { // driver: - pluginpath = get_driver_path (reporter); + pluginpath = ModuleLoader.get_driver_path (driverpath, reporter); if (pluginpath == null) { return null; }