54 throws Command.Exception
55 {
56 noDry();
57 finishArgs();
58 File lp = libPath(opts);
59 File pp = null;
60 if (opts.has(parentPath))
61 pp = opts.valueOf(parentPath);
62 else if (!opts.has("N"))
63 pp = homeLibrary;
64
65 File natlibs = null;
66 if (opts.has(nativeLibs))
67 natlibs = opts.valueOf(nativeLibs);
68 File natcmds = null;
69 if (opts.has(nativeCmds))
70 natcmds = opts.valueOf(nativeCmds);
71 File configs = null;
72 if (opts.has(configFiles))
73 configs = opts.valueOf(configFiles);
74
75 Set<StorageOption> createOpts = new HashSet<>();
76 if (opts.has("z"))
77 createOpts.add(StorageOption.DEFLATED);
78
79 try {
80 lib = SimpleLibrary.create(lp, pp, natlibs, natcmds,
81 configs, createOpts);
82 } catch (IOException x) {
83 throw new Command.Exception(x);
84 }
85 }
86 }
87
88 static class DumpClass extends Command<SimpleLibrary> {
89 protected void go(SimpleLibrary lib)
90 throws Command.Exception
91 {
92 noDry();
93 String mids = takeArg();
94 ModuleId mid = null;
95 try {
96 mid = jms.parseModuleId(mids);
97 } catch (IllegalArgumentException x) {
98 throw new Command.Exception(x.getMessage());
99 }
100 String cn = takeArg();
101 String ops = takeArg();
116 if (fout != null)
117 fout.close();
118 }
119 } catch (IllegalArgumentException x) {
120 throw new Command.Exception(x.getMessage());
121 } catch (IOException x) {
122 throw new Command.Exception(x);
123 }
124 }
125 }
126
127 static class Identify extends Command<SimpleLibrary> {
128 protected void go(SimpleLibrary lib)
129 throws Command.Exception
130 {
131 noDry();
132 finishArgs();
133 out.format("path %s%n", lib.root());
134 out.format("version %d.%d%n",
135 lib.majorVersion(), lib.minorVersion());
136 if (lib.natlibs() != null)
137 out.format("natlibs %s%n", lib.natlibs());
138 if (lib.natcmds() != null)
139 out.format("natcmds %s%n", lib.natcmds());
140 if (lib.configs() != null)
141 out.format("configs %s%n", lib.configs());
142 SimpleLibrary plib = lib.parent();
143 while (plib != null) {
144 out.format("parent %s%n", plib.root());
145 plib = plib.parent();
146 }
147 }
148 }
149
150 static class Extract extends Command<SimpleLibrary> {
151 protected void go(SimpleLibrary lib)
152 throws Command.Exception
153 {
154 noDry();
155 while (hasArg()) {
261 if (dry)
262 return;
263 lib.install(res, verifySignature, strip);
264 } catch (ConfigurationException | IOException | SignatureException |
265 ModuleFileParserException x) {
266 throw new Command.Exception(x);
267 }
268
269 }
270 }
271
272 // ## preinstall is used by jpkg for creating debian package.
273 // ## need to revisit this
274 static class PreInstall extends Command<SimpleLibrary> {
275 protected void go(SimpleLibrary lib)
276 throws Command.Exception
277 {
278 noDry();
279 File classes = new File(takeArg());
280 File dst = new File(takeArg());
281 List<Manifest> mfs = new ArrayList<Manifest>();
282 while (hasArg())
283 mfs.add(Manifest.create(takeArg(), classes));
284 finishArgs();
285 try {
286 lib.preInstall(mfs, dst);
287 } catch (IOException x) {
288 throw new Command.Exception(x);
289 }
290 }
291 }
292
293 static class Remove extends Command<SimpleLibrary> {
294 protected void go(SimpleLibrary lib)
295 throws Command.Exception
296 {
297 if (dry && force)
298 throw new Command.Exception("%s: specify only one of "
299 + "-n (--dry-run) or -f (--force)",
300 command);
301 List<ModuleId> mids = new ArrayList<ModuleId>();
302 try {
303 while (hasArg())
304 mids.add(jms.parseModuleId(takeArg()));
305 } catch (IllegalArgumentException x) {
306 throw new Command.Exception(x.getMessage());
307 }
308 boolean quiet = false; // ## Need -q
309 try {
310 if (force)
311 lib.removeForcibly(mids);
312 else
313 lib.remove(mids, dry);
314 } catch (ConfigurationException x) {
315 throw new Command.Exception(x);
316 } catch (IOException x) {
317 if (!quiet) {
318 for (Throwable t : x.getSuppressed())
319 err.format("Warning: %s%n", t.getMessage());
320 }
321 throw new Command.Exception(x);
338 finishArgs();
339 try {
340 ModuleId mid = lib.findLatestModuleId(midq);
341 if (mid == null)
342 throw new Command.Exception(midq + ": No such module");
343 Configuration<Context> cf = lib.readConfiguration(mid);
344 if (cf == null)
345 throw new Command.Exception(mid + ": Not a root module");
346 cf.dump(out, verbose);
347 } catch (IOException x) {
348 throw new Command.Exception(x);
349 }
350 }
351 }
352
353 static class Config extends Command<SimpleLibrary> {
354 protected void go(SimpleLibrary lib)
355 throws Command.Exception
356 {
357 noDry();
358 List<ModuleId> mids = new ArrayList<ModuleId>();
359 try {
360 while (hasArg())
361 mids.add(jms.parseModuleId(takeArg()));
362 } catch (IllegalArgumentException x) {
363 throw new Command.Exception(x.getMessage());
364 }
365 try {
366 lib.configure(mids);
367 } catch (ConfigurationException x) {
368 throw new Command.Exception(x);
369 } catch (IOException x) {
370 throw new Command.Exception(x);
371 }
372 }
373 }
374
375 static class ReIndex extends Command<SimpleLibrary> {
376 protected void go(SimpleLibrary lib)
377 throws Command.Exception
378 {
532 commands.put("identify", Identify.class);
533 commands.put("install", Install.class);
534 commands.put("list", Commands.ListLibrary.class);
535 commands.put("ls", Commands.ListLibrary.class);
536 commands.put("preinstall", PreInstall.class);
537 commands.put("refresh", Refresh.class);
538 commands.put("reindex", ReIndex.class);
539 commands.put("remove", Remove.class);
540 commands.put("rm", Remove.class);
541 commands.put("repos", Repos.class);
542 }
543
544 private OptionParser parser;
545
546 private static OptionSpec<Integer> repoIndex; // ##
547 private static OptionSpec<File> libPath;
548 private static OptionSpec<File> parentPath;
549 private static OptionSpec<File> nativeLibs;
550 private static OptionSpec<File> nativeCmds;
551 private static OptionSpec<File> configFiles;
552
553 private void usage() {
554 out.format("%n");
555 out.format("usage: jmod add-repo [-i <index>] URL%n");
556 out.format(" jmod config [<module-id> ...]%n");
557 out.format(" jmod create [-L <library>] [-P <parent>]" +
558 " [--natlib <natlib>] [--natcmd <natcmd>] [--config <config>]%n");
559 out.format(" jmod del-repo URL%n");
560 out.format(" jmod dump-class <module-id> <class-name> <output-file>%n");
561 out.format(" jmod dump-config <module-id>%n");
562 out.format(" jmod extract <module-file> ...%n");
563 out.format(" jmod identify%n");
564 out.format(" jmod install [--noverify] [-n] <module-id-query> ...%n");
565 out.format(" jmod install [--noverify] <module-file> ...%n");
566 out.format(" jmod install <classes-dir> <module-name> ...%n");
567 out.format(" jmod list [-v] [-p] [-R] [<module-id-query>]%n");
568 out.format(" jmod preinstall <classes-dir> <dst-dir> <module-name> ...%n");
569 out.format(" jmod refresh [-f] [-n] [-v]%n");
570 out.format(" jmod reindex [<module-id> ...]%n");
571 out.format(" jmod remove [-f] [-n] [<module-id> ...]%n");
572 out.format(" jmod repos [-v]%n");
573 out.format("%n");
574 try {
575 parser.printHelpOn(out);
576 } catch (IOException x) {
577 throw new AssertionError(x);
578 }
599 = (parser.acceptsAll(Arrays.asList("P", "parent-path"),
600 "Parent module-library location")
601 .withRequiredArg()
602 .describedAs("path")
603 .ofType(File.class));
604 nativeLibs
605 = (parser.accepts("natlib", "Directory to store native libs")
606 .withRequiredArg()
607 .describedAs("dir")
608 .ofType(File.class));
609 nativeCmds
610 = (parser.accepts("natcmd", "Directory to store native launchers")
611 .withRequiredArg()
612 .describedAs("dir")
613 .ofType(File.class));
614 configFiles
615 = (parser.accepts("config", "Directory to store config files")
616 .withRequiredArg()
617 .describedAs("dir")
618 .ofType(File.class));
619 parser.acceptsAll(Arrays.asList("N", "no-parent"),
620 "Use no parent library when creating");
621 parser.acceptsAll(Arrays.asList("v", "verbose"),
622 "Enable verbose output");
623 parser.acceptsAll(Arrays.asList("h", "?", "help"),
624 "Show this help message");
625 parser.acceptsAll(Arrays.asList("p", "parent"),
626 "Apply operation to parent library, if any");
627 parser.acceptsAll(Arrays.asList("z", "enable-compression"),
628 "Enable compression of module contents");
629 repoIndex
630 = (parser.acceptsAll(Arrays.asList("i"),
631 "Repository-list index")
632 .withRequiredArg()
633 .describedAs("index")
634 .ofType(Integer.class));
635 parser.acceptsAll(Arrays.asList("f", "force"),
636 "Force the requested operation");
637 parser.acceptsAll(Arrays.asList("n", "dry-run"),
638 "Dry-run the requested operation");
|
54 throws Command.Exception
55 {
56 noDry();
57 finishArgs();
58 File lp = libPath(opts);
59 File pp = null;
60 if (opts.has(parentPath))
61 pp = opts.valueOf(parentPath);
62 else if (!opts.has("N"))
63 pp = homeLibrary;
64
65 File natlibs = null;
66 if (opts.has(nativeLibs))
67 natlibs = opts.valueOf(nativeLibs);
68 File natcmds = null;
69 if (opts.has(nativeCmds))
70 natcmds = opts.valueOf(nativeCmds);
71 File configs = null;
72 if (opts.has(configFiles))
73 configs = opts.valueOf(configFiles);
74 ModuleArchitecture modArch = ModuleArchitecture.create(opts.valueOf(osOpt),
75 opts.valueOf(archOpt));
76 Set<StorageOption> createOpts = new HashSet<>();
77 if (opts.has("z"))
78 createOpts.add(StorageOption.DEFLATED);
79
80 try {
81 lib = SimpleLibrary.create(lp, pp, natlibs, natcmds,
82 configs, createOpts, modArch);
83 } catch (IOException x) {
84 throw new Command.Exception(x);
85 }
86 }
87 }
88
89 static class DumpClass extends Command<SimpleLibrary> {
90 protected void go(SimpleLibrary lib)
91 throws Command.Exception
92 {
93 noDry();
94 String mids = takeArg();
95 ModuleId mid = null;
96 try {
97 mid = jms.parseModuleId(mids);
98 } catch (IllegalArgumentException x) {
99 throw new Command.Exception(x.getMessage());
100 }
101 String cn = takeArg();
102 String ops = takeArg();
117 if (fout != null)
118 fout.close();
119 }
120 } catch (IllegalArgumentException x) {
121 throw new Command.Exception(x.getMessage());
122 } catch (IOException x) {
123 throw new Command.Exception(x);
124 }
125 }
126 }
127
128 static class Identify extends Command<SimpleLibrary> {
129 protected void go(SimpleLibrary lib)
130 throws Command.Exception
131 {
132 noDry();
133 finishArgs();
134 out.format("path %s%n", lib.root());
135 out.format("version %d.%d%n",
136 lib.majorVersion(), lib.minorVersion());
137 ModuleArchitecture modArch = lib.architecture();
138 if (!modArch.os().equals(""))
139 out.format("os: %s%n", modArch.os());
140 if (!modArch.arch().equals(""))
141 out.format("arch: %s%n", modArch.arch());
142 if (lib.natlibs() != null)
143 out.format("natlibs %s%n", lib.natlibs());
144 if (lib.natcmds() != null)
145 out.format("natcmds %s%n", lib.natcmds());
146 if (lib.configs() != null)
147 out.format("configs %s%n", lib.configs());
148 SimpleLibrary plib = lib.parent();
149 while (plib != null) {
150 out.format("parent %s%n", plib.root());
151 plib = plib.parent();
152 }
153 }
154 }
155
156 static class Extract extends Command<SimpleLibrary> {
157 protected void go(SimpleLibrary lib)
158 throws Command.Exception
159 {
160 noDry();
161 while (hasArg()) {
267 if (dry)
268 return;
269 lib.install(res, verifySignature, strip);
270 } catch (ConfigurationException | IOException | SignatureException |
271 ModuleFileParserException x) {
272 throw new Command.Exception(x);
273 }
274
275 }
276 }
277
278 // ## preinstall is used by jpkg for creating debian package.
279 // ## need to revisit this
280 static class PreInstall extends Command<SimpleLibrary> {
281 protected void go(SimpleLibrary lib)
282 throws Command.Exception
283 {
284 noDry();
285 File classes = new File(takeArg());
286 File dst = new File(takeArg());
287 List<Manifest> mfs = new ArrayList<>();
288 while (hasArg())
289 mfs.add(Manifest.create(takeArg(), classes));
290 finishArgs();
291 try {
292 lib.preInstall(mfs, dst);
293 } catch (IOException x) {
294 throw new Command.Exception(x);
295 }
296 }
297 }
298
299 static class Remove extends Command<SimpleLibrary> {
300 protected void go(SimpleLibrary lib)
301 throws Command.Exception
302 {
303 if (dry && force)
304 throw new Command.Exception("%s: specify only one of "
305 + "-n (--dry-run) or -f (--force)",
306 command);
307 List<ModuleId> mids = new ArrayList<>();
308 try {
309 while (hasArg())
310 mids.add(jms.parseModuleId(takeArg()));
311 } catch (IllegalArgumentException x) {
312 throw new Command.Exception(x.getMessage());
313 }
314 boolean quiet = false; // ## Need -q
315 try {
316 if (force)
317 lib.removeForcibly(mids);
318 else
319 lib.remove(mids, dry);
320 } catch (ConfigurationException x) {
321 throw new Command.Exception(x);
322 } catch (IOException x) {
323 if (!quiet) {
324 for (Throwable t : x.getSuppressed())
325 err.format("Warning: %s%n", t.getMessage());
326 }
327 throw new Command.Exception(x);
344 finishArgs();
345 try {
346 ModuleId mid = lib.findLatestModuleId(midq);
347 if (mid == null)
348 throw new Command.Exception(midq + ": No such module");
349 Configuration<Context> cf = lib.readConfiguration(mid);
350 if (cf == null)
351 throw new Command.Exception(mid + ": Not a root module");
352 cf.dump(out, verbose);
353 } catch (IOException x) {
354 throw new Command.Exception(x);
355 }
356 }
357 }
358
359 static class Config extends Command<SimpleLibrary> {
360 protected void go(SimpleLibrary lib)
361 throws Command.Exception
362 {
363 noDry();
364 List<ModuleId> mids = new ArrayList<>();
365 try {
366 while (hasArg())
367 mids.add(jms.parseModuleId(takeArg()));
368 } catch (IllegalArgumentException x) {
369 throw new Command.Exception(x.getMessage());
370 }
371 try {
372 lib.configure(mids);
373 } catch (ConfigurationException x) {
374 throw new Command.Exception(x);
375 } catch (IOException x) {
376 throw new Command.Exception(x);
377 }
378 }
379 }
380
381 static class ReIndex extends Command<SimpleLibrary> {
382 protected void go(SimpleLibrary lib)
383 throws Command.Exception
384 {
538 commands.put("identify", Identify.class);
539 commands.put("install", Install.class);
540 commands.put("list", Commands.ListLibrary.class);
541 commands.put("ls", Commands.ListLibrary.class);
542 commands.put("preinstall", PreInstall.class);
543 commands.put("refresh", Refresh.class);
544 commands.put("reindex", ReIndex.class);
545 commands.put("remove", Remove.class);
546 commands.put("rm", Remove.class);
547 commands.put("repos", Repos.class);
548 }
549
550 private OptionParser parser;
551
552 private static OptionSpec<Integer> repoIndex; // ##
553 private static OptionSpec<File> libPath;
554 private static OptionSpec<File> parentPath;
555 private static OptionSpec<File> nativeLibs;
556 private static OptionSpec<File> nativeCmds;
557 private static OptionSpec<File> configFiles;
558 private static OptionSpec<String> osOpt;
559 private static OptionSpec<String> archOpt;
560
561 private void usage() {
562 out.format("%n");
563 out.format("usage: jmod add-repo [-i <index>] URL%n");
564 out.format(" jmod config [<module-id> ...]%n");
565 out.format(" jmod create [-L <library>] [-P <parent>] [--natlib <natlib>]%n");
566 out.format(" [--natcmd <natcmd>] [--config <config>]%n");
567 out.format(" [-os <os>] [-arch <arch>]%n");
568 out.format(" jmod del-repo URL%n");
569 out.format(" jmod dump-class <module-id> <class-name> <output-file>%n");
570 out.format(" jmod dump-config <module-id>%n");
571 out.format(" jmod extract <module-file> ...%n");
572 out.format(" jmod identify%n");
573 out.format(" jmod install [--noverify] [-n] <module-id-query> ...%n");
574 out.format(" jmod install [--noverify] <module-file> ...%n");
575 out.format(" jmod install <classes-dir> <module-name> ...%n");
576 out.format(" jmod list [-v] [-p] [-R] [<module-id-query>]%n");
577 out.format(" jmod preinstall <classes-dir> <dst-dir> <module-name> ...%n");
578 out.format(" jmod refresh [-f] [-n] [-v]%n");
579 out.format(" jmod reindex [<module-id> ...]%n");
580 out.format(" jmod remove [-f] [-n] [<module-id> ...]%n");
581 out.format(" jmod repos [-v]%n");
582 out.format("%n");
583 try {
584 parser.printHelpOn(out);
585 } catch (IOException x) {
586 throw new AssertionError(x);
587 }
608 = (parser.acceptsAll(Arrays.asList("P", "parent-path"),
609 "Parent module-library location")
610 .withRequiredArg()
611 .describedAs("path")
612 .ofType(File.class));
613 nativeLibs
614 = (parser.accepts("natlib", "Directory to store native libs")
615 .withRequiredArg()
616 .describedAs("dir")
617 .ofType(File.class));
618 nativeCmds
619 = (parser.accepts("natcmd", "Directory to store native launchers")
620 .withRequiredArg()
621 .describedAs("dir")
622 .ofType(File.class));
623 configFiles
624 = (parser.accepts("config", "Directory to store config files")
625 .withRequiredArg()
626 .describedAs("dir")
627 .ofType(File.class));
628 osOpt
629 = (parser.accepts("os", "Target Operating System of the library")
630 .withRequiredArg()
631 .describedAs("os")
632 .ofType(String.class));
633 archOpt
634 = (parser.accepts("arch", "Target Architecture of the library")
635 .withRequiredArg()
636 .describedAs("arch")
637 .ofType(String.class));
638 parser.acceptsAll(Arrays.asList("N", "no-parent"),
639 "Use no parent library when creating");
640 parser.acceptsAll(Arrays.asList("v", "verbose"),
641 "Enable verbose output");
642 parser.acceptsAll(Arrays.asList("h", "?", "help"),
643 "Show this help message");
644 parser.acceptsAll(Arrays.asList("p", "parent"),
645 "Apply operation to parent library, if any");
646 parser.acceptsAll(Arrays.asList("z", "enable-compression"),
647 "Enable compression of module contents");
648 repoIndex
649 = (parser.acceptsAll(Arrays.asList("i"),
650 "Repository-list index")
651 .withRequiredArg()
652 .describedAs("index")
653 .ofType(Integer.class));
654 parser.acceptsAll(Arrays.asList("f", "force"),
655 "Force the requested operation");
656 parser.acceptsAll(Arrays.asList("n", "dry-run"),
657 "Dry-run the requested operation");
|