src/share/classes/org/openjdk/jigsaw/cli/Librarian.java
Print this page
@@ -45,18 +45,47 @@
public class Librarian {
private static JigsawModuleSystem jms
= JigsawModuleSystem.instance();
+ private static final File homeLibrary
+ = new File(System.getProperty("java.home"), "lib/modules");
+
static class Create extends Command<SimpleLibrary> {
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<StorageOption> 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);
}
}
+ }
static class DumpClass extends Command<SimpleLibrary> {
protected void go(SimpleLibrary lib)
throws Command.Exception
{
@@ -471,17 +500,21 @@
}
private OptionParser parser;
private static OptionSpec<Integer> repoIndex; // ##
+ private static OptionSpec<File> libPath;
+ private static OptionSpec<File> parentPath;
+ private static OptionSpec<File> nativeLibs;
+ private static OptionSpec<File> nativeCmds;
private void usage() {
out.format("%n");
out.format("usage: jmod add-repo [-i <index>] URL%n");
out.format(" jmod extract <module-file> ...%n");
out.format(" jmod config [<module-id> ...]%n");
- out.format(" jmod create [-L <library>] [-P <parent>]%n");
+ out.format(" jmod create [-L <library>] [-P <parent>] [-natlibs <natlibs>] [-natcmds <natcmds>]%n");
out.format(" jmod del-repo URL%n");
out.format(" jmod dump-class <module-id> <class-name> <output-file>%n");
out.format(" jmod dump-config <module-id>%n");
out.format(" jmod identify%n");
out.format(" jmod install [--noverify] [-n] <module-id-query> ...%n");
@@ -508,23 +541,34 @@
private void exec(String[] args) throws OptionException, Command.Exception {
parser = new OptionParser();
// ## Need subcommand-specific option parsing
- OptionSpec<File> libPath
+ libPath
= (parser.acceptsAll(Arrays.asList("L", "library"),
"Module-library location"
+ " (default $JAVA_MODULES)")
.withRequiredArg()
.describedAs("path")
.ofType(File.class));
- OptionSpec<File> 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"),
"Enable verbose output");
parser.acceptsAll(Arrays.asList("h", "?", "help"),
@@ -552,13 +596,10 @@
"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();
List<String> words = opts.nonOptionArguments();
if (words.isEmpty())
@@ -565,36 +606,17 @@
usage();
String verb = words.get(0);
Class<? extends Command<SimpleLibrary>> 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;
+ if (!verb.equals("create")) {
+ File lp = libPath(opts);
try {
- if (verb.equals("create")) {
- Set<StorageOption> createOpts = new HashSet<>();
- if (opts.has("z"))
- createOpts.add(StorageOption.DEFLATED);
- lib = SimpleLibrary.create(lp, pp, createOpts);
- } else {
lib = SimpleLibrary.open(lp);
- }
} catch (FileNotFoundException x) {
String msg = null;
File f = new File(x.getMessage());
try {
f = f.getCanonicalFile();
@@ -607,18 +629,31 @@
}
throw new Command.Exception("%s: %s", lp, msg);
} catch (IOException x) {
throw new Command.Exception(x);
}
+ }
try {
cmd.newInstance().run(lib, opts);
} catch (InstantiationException x) {
throw new AssertionError(x);
} catch (IllegalAccessException x) {
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() { }
public static void main(String[] args) {
try {