--- old/src/share/classes/org/openjdk/jigsaw/cli/Librarian.java Mon Dec 12 16:27:58 2011 +++ new/src/share/classes/org/openjdk/jigsaw/cli/Librarian.java Mon Dec 12 16:27:58 2011 @@ -47,12 +47,41 @@ private static JigsawModuleSystem jms = JigsawModuleSystem.instance(); + private static final File homeLibrary + = new File(System.getProperty("java.home"), "lib/modules"); + static class Create extends Command { protected void go(SimpleLibrary lib) throws Command.Exception { + //assert lib == null; noDry(); + File lp = libPath(opts); + File pp = null; + if (opts.has(parentPath)) { + pp = opts.valueOf(parentPath); + } else if (!opts.has("N")) { + pp = homeLibrary; + } + File natlibs = null; + if (opts.has(nativeLibs)) { + natlibs = opts.valueOf(nativeLibs); + } + File natcmds = null; + if (opts.has(nativeCmds)) { + natcmds = opts.valueOf(nativeCmds); + } finishArgs(); + + Set createOpts = new HashSet<>(); + if (opts.has("z")) + createOpts.add(StorageOption.DEFLATED); + + try { + lib = SimpleLibrary.create(lp, pp, natlibs, natcmds, createOpts); + } catch (IOException x) { + throw new Command.Exception(x); + } } } @@ -121,8 +150,8 @@ File module = new File(takeArg()); File classes = null; try (FileInputStream fis = new FileInputStream(module); - DataInputStream dis = new DataInputStream(fis); - ModuleFile.Reader reader = new ModuleFile.Reader(dis)) { + DataInputStream dis = new DataInputStream(fis); + ModuleFile.Reader reader = new ModuleFile.Reader(dis)) { ModuleInfo mi = jms.parseModuleInfo(reader.readStart()); classes = new File(mi.id().name()); @@ -447,7 +476,7 @@ } } } - + private static Map>> commands = new HashMap<>(); @@ -473,6 +502,10 @@ private OptionParser parser; private static OptionSpec repoIndex; // ## + private static OptionSpec libPath; + private static OptionSpec parentPath; + private static OptionSpec nativeLibs; + private static OptionSpec nativeCmds; private void usage() { out.format("%n"); @@ -479,7 +512,7 @@ out.format("usage: jmod add-repo [-i ] URL%n"); out.format(" jmod extract ...%n"); out.format(" jmod config [ ...]%n"); - out.format(" jmod create [-L ] [-P ]%n"); + out.format(" jmod create [-L ] [-P ] [-natlibs ] [-natcmds ]%n"); out.format(" jmod del-repo URL%n"); out.format(" jmod dump-class %n"); out.format(" jmod dump-config %n"); @@ -510,7 +543,7 @@ parser = new OptionParser(); // ## Need subcommand-specific option parsing - OptionSpec libPath + libPath = (parser.acceptsAll(Arrays.asList("L", "library"), "Module-library location" + " (default $JAVA_MODULES)") @@ -517,12 +550,23 @@ .withRequiredArg() .describedAs("path") .ofType(File.class)); - OptionSpec parentPath + parentPath = (parser.acceptsAll(Arrays.asList("P", "parent-path"), "Parent module-library location") .withRequiredArg() .describedAs("path") .ofType(File.class)); + nativeLibs + = (parser.accepts("natlibs", "Directory with native libs") + .withRequiredArg() + .describedAs("dir") + .ofType(File.class)); + + nativeCmds + = (parser.accepts("natcmds", "Directory with native launchers") + .withRequiredArg() + .describedAs("dir") + .ofType(File.class)); parser.acceptsAll(Arrays.asList("N", "no-parent"), "Use no parent library when creating"); parser.acceptsAll(Arrays.asList("v", "verbose"), @@ -550,13 +594,10 @@ + "Treat as unsigned."); parser.acceptsAll(Arrays.asList("G", "strip-debug"), "Strip debug attributes during installation"); - + if (args.length == 0) usage(); - File homeLibrary = new File(System.getProperty("java.home"), - "lib/modules"); - OptionSet opts = parser.parse(args); if (opts.has("h")) usage(); @@ -567,47 +608,29 @@ Class> cmd = commands.get(verb); if (cmd == null) throw new Command.Exception("%s: unknown command", verb); - File lp = null; - if (opts.has(libPath)) { - lp = opts.valueOf(libPath); - } else { - String jm = System.getenv("JAVA_MODULES"); - if (jm != null) - lp = new File(jm); - else - lp = homeLibrary; - } - File pp = null; - if (opts.has(parentPath)) { - pp = opts.valueOf(parentPath); - } else if (!opts.has("N")) { - pp = homeLibrary; - } + + // every command, except create, needs to be passed a reference to the library SimpleLibrary lib = null; - try { - if (verb.equals("create")) { - Set createOpts = new HashSet<>(); - if (opts.has("z")) - createOpts.add(StorageOption.DEFLATED); - lib = SimpleLibrary.create(lp, pp, createOpts); - } else { + if (!verb.equals("create")) { + File lp = libPath(opts); + try { lib = SimpleLibrary.open(lp); + } catch (FileNotFoundException x) { + String msg = null; + File f = new File(x.getMessage()); + try { + f = f.getCanonicalFile(); + if (lp.getCanonicalFile().equals(f)) + msg = "No such library"; + else + msg = "Cannot open parent library " + f; + } catch (IOException y) { + throw new Command.Exception(y); + } + throw new Command.Exception("%s: %s", lp, msg); + } catch (IOException x) { + throw new Command.Exception(x); } - } catch (FileNotFoundException x) { - String msg = null; - File f = new File(x.getMessage()); - try { - f = f.getCanonicalFile(); - if (lp.getCanonicalFile().equals(f)) - msg = "No such library"; - else - msg = "Cannot open parent library " + f; - } catch (IOException y) { - throw new Command.Exception(y); - } - throw new Command.Exception("%s: %s", lp, msg); - } catch (IOException x) { - throw new Command.Exception(x); } try { cmd.newInstance().run(lib, opts); @@ -617,6 +640,18 @@ throw new AssertionError(x); } } + + private static File libPath(OptionSet opts) { + if (opts.has(libPath)) { + return opts.valueOf(libPath); + } else { + String jm = System.getenv("JAVA_MODULES"); + if (jm != null) + return new File(jm); + else + return homeLibrary; + } + } private Librarian() { }