contrib/jwrapper: add an option to search for existing wrappers in custom libs
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 23 Jul 2015 21:51:15 +0000 (17:51 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 24 Jul 2015 16:35:12 +0000 (12:35 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/src/jwrapper.nit
contrib/jwrapper/src/model.nit

index ca3fd7f..60a6ca3 100644 (file)
@@ -44,7 +44,7 @@ var opt_output = new OptionString("Output file", "-o")
 var opt_regex = new OptionString("Regex pattern to filter classes in Jar archives", "-r")
 var opt_help = new OptionBool("Show this help message", "-h", "--help")
 
-opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_regex, opt_verbose, opt_help)
+opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_libs, opt_regex, opt_verbose, opt_help)
 opts.parse args
 
 if opts.errors.not_empty or opts.rest.is_empty or opt_help.value then
index 7c49790..0f406b0 100644 (file)
@@ -263,19 +263,26 @@ redef class Sys
                var map = new DefaultMap[String, nullable NitType](null)
                var modules = new HashMap[String, NitModule]
 
-               var nit_dir = "NIT_DIR".environ
-               if nit_dir.is_empty then
-                       # Simple heuristic to find the Nit lib
-                       var dir = sys.program_name.dirname / "../../../"
-                       nit_dir = dir.simplify_path
-                       if not nit_dir.file_exists then return map
+               var lib_paths = opt_libs.value
+               if lib_paths == null then lib_paths = new Array[String]
+
+               if lib_paths.has("auto") then
+                       lib_paths.remove "auto"
+                       var nit_dir = "NIT_DIR".environ
+                       if nit_dir.is_empty then
+                               # Simple heuristic to find the Nit lib
+                               var dir = sys.program_name.dirname / "../../../lib/"
+                               dir = dir.simplify_path
+                               if dir.file_exists then lib_paths.add dir.simplify_path
+                       end
                end
 
+               if lib_paths.is_empty then return map
+
                # Use grep to find all extern classes implemented in Java
                var grep_regex = "extern class [a-zA-Z0-9]\\\+[ ]\\\+in[ ]\\\+\"Java\""
-               var grep_args = ["-r", grep_regex,
-                       nit_dir/"lib/android/",
-                       nit_dir/"lib/java/"]
+               var grep_args = ["-r", "--with-filename", grep_regex]
+               grep_args.add_all lib_paths
 
                var grep = new ProcessReader("grep", grep_args...)
                var lines = grep.read_lines
@@ -312,6 +319,9 @@ redef class Sys
 
        # Prefix used to name extern classes, if `null` use the full namespace
        var extern_class_prefix: nullable String is lazy do return opt_extern_class_prefix.value
+
+       # Libraries to search for existing wrappers
+       var opt_libs = new OptionArray("Paths to libraries with wrappers of Java classes ('auto' to use the full Nit lib)", "-i")
 end
 
 redef class Text