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();
102 finishArgs();
103 byte[] bs = null;
104 try {
105 bs = lib.readClass(mid, cn);
106 if (bs == null)
107 throw new Command.Exception("%s: No such class in module %s",
108 cn, mid);
109 OutputStream fout = null;
110 try {
111 fout = (ops.equals("-")
112 ? System.out
113 : new FileOutputStream(ops));
114 fout.write(bs);
115 } finally {
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());
188 throws Command.Exception
189 {
190 String key = takeArg();
191 File kf = new File(key);
192 boolean verifySignature = !opts.has("noverify");
193 boolean strip = opts.has("G");
194
195 // Old form: install <classes-dir> <module-name> ...
196 //
197 if (kf.exists() && kf.isDirectory()) {
198 noDry();
199 List<Manifest> mfs = new ArrayList<>();
200 while (hasArg())
201 mfs.add(Manifest.create(takeArg(), kf));
202 finishArgs();
203 if (mfs.isEmpty())
204 throw new Command.Exception("%s: no module-name specified",
205 command);
206 try {
207 lib.installFromManifests(mfs, strip);
208 } catch (ConfigurationException x) {
209 throw new Command.Exception(x);
210 } catch (IOException x) {
211 throw new Command.Exception(x);
212 }
213 return;
214 }
215
216 // Install one or more module file(s)
217 //
218 if (kf.exists() && kf.isFile()) {
219 noDry();
220 List<File> fs = new ArrayList<>();
221 fs.add(kf);
222 while (hasArg())
223 fs.add(new File(takeArg()));
224 finishArgs();
225 try {
226 lib.install(fs, verifySignature, strip);
227 } catch (ConfigurationException x) {
228 throw new Command.Exception(x);
229 } catch (IOException x) {
230 throw new Command.Exception(x);
231 } catch (SignatureException x) {
232 throw new Command.Exception(x);
233 }
234 return;
235 }
236
237 // Otherwise treat args as module-id queries
238 List<ModuleIdQuery> midqs = new ArrayList<>();
239 String s = key;
240 for (;;) {
241 ModuleIdQuery mq = null;
242 try {
243 mq = jms.parseModuleIdQuery(s);
244 } catch (IllegalArgumentException x) {
245 throw new Command.Exception(x);
246 }
247 midqs.add(mq);
248 if (!hasArg())
249 break;
250 s = takeArg();
251 }
252 try {
253 boolean quiet = false; // ## Need -q
254 Resolution res = lib.resolve(midqs);
255 if (res.modulesNeeded().isEmpty()) {
256 if (!quiet)
257 out.format("Nothing to install%n");
258 return;
259 }
260 if (!quiet) {
261 out.format("To install: %s%n",
262 res.modulesNeeded()
263 .toString().replaceAll("^\\[|\\]$", ""));
264 out.format("%d bytes to download/transfer%n",
265 res.downloadRequired());
266 out.format("%d bytes to store%n",
267 res.spaceRequired());
268 }
269 if (dry)
270 return;
271 lib.install(res, verifySignature, strip);
272 } catch (ConfigurationException | IOException | SignatureException x) {
273 throw new Command.Exception(x);
274 }
275
276 }
277 }
278
279 // ## preinstall is used by jpkg for creating debian package.
280 // ## need to revisit this
281 static class PreInstall extends Command<SimpleLibrary> {
282 protected void go(SimpleLibrary lib)
283 throws Command.Exception
284 {
285 noDry();
286 File classes = new File(takeArg());
287 File dst = new File(takeArg());
288 List<Manifest> mfs = new ArrayList<Manifest>();
289 while (hasArg())
290 mfs.add(Manifest.create(takeArg(), classes));
291 finishArgs();
292 try {
293 lib.preInstall(mfs, dst);
294 } catch (IOException x) {
295 throw new Command.Exception(x);
296 }
297 }
298 }
299
300 static class Remove extends Command<SimpleLibrary> {
301 protected void go(SimpleLibrary lib)
302 throws Command.Exception
303 {
304 if (dry && force)
305 throw new Command.Exception("%s: specify only one of "
306 + "-n (--dry-run) or -f (--force)",
307 command);
308 List<ModuleId> mids = new ArrayList<ModuleId>();
309 try {
310 while (hasArg())
311 mids.add(jms.parseModuleId(takeArg()));
312 } catch (IllegalArgumentException x) {
313 throw new Command.Exception(x.getMessage());
314 }
315 boolean quiet = false; // ## Need -q
316 try {
317 if (force)
318 lib.removeForcibly(mids);
319 else
320 lib.remove(mids, dry);
321 } catch (ConfigurationException x) {
322 throw new Command.Exception(x);
323 } catch (IOException x) {
324 if (!quiet) {
325 for (Throwable t : x.getSuppressed())
326 err.format("Warning: %s%n", t.getMessage());
327 }
328 throw new Command.Exception(x);
329 }
330 }
331 }
332
333 static class DumpConfig extends Command<SimpleLibrary> {
334 protected void go(SimpleLibrary lib)
335 throws Command.Exception
345 finishArgs();
346 try {
347 ModuleId mid = lib.findLatestModuleId(midq);
348 if (mid == null)
349 throw new Command.Exception(midq + ": No such module");
350 Configuration<Context> cf = lib.readConfiguration(mid);
351 if (cf == null)
352 throw new Command.Exception(mid + ": Not a root module");
353 cf.dump(out, verbose);
354 } catch (IOException x) {
355 throw new Command.Exception(x);
356 }
357 }
358 }
359
360 static class Config extends Command<SimpleLibrary> {
361 protected void go(SimpleLibrary lib)
362 throws Command.Exception
363 {
364 noDry();
365 List<ModuleId> mids = new ArrayList<ModuleId>();
366 try {
367 while (hasArg())
368 mids.add(jms.parseModuleId(takeArg()));
369 } catch (IllegalArgumentException x) {
370 throw new Command.Exception(x.getMessage());
371 }
372 try {
373 lib.configure(mids);
374 } catch (ConfigurationException x) {
375 throw new Command.Exception(x);
376 } catch (IOException x) {
377 throw new Command.Exception(x);
378 }
379 }
380 }
381
382 static class ReIndex extends Command<SimpleLibrary> {
383 protected void go(SimpleLibrary lib)
384 throws Command.Exception
385 {
386 noDry();
387 List<ModuleId> mids = new ArrayList<ModuleId>();
388 try {
389 while (hasArg())
390 mids.add(jms.parseModuleId(takeArg()));
391 } catch (IllegalArgumentException x) {
392 throw new Command.Exception(x.getMessage());
393 }
394 try {
395 lib.reIndex(mids);
396 } catch (ConfigurationException x) {
397 throw new Command.Exception(x);
398 } catch (IOException x) {
399 throw new Command.Exception(x);
400 }
401 }
402 }
403
404 static class Repos extends Command<SimpleLibrary> {
405 protected void go(SimpleLibrary lib)
406 throws Command.Exception
407 {
408 noDry();
409 finishArgs();
410 try {
411 RemoteRepositoryList rl = lib.repositoryList();
412 int i = 0;
413 for (RemoteRepository rr : rl.repositories())
414 out.format("%d %s%n", i++, rr.location());
415 } catch (IOException x) {
416 throw new Command.Exception(x);
417 }
418 }
419 }
544 commands.put("refresh", Refresh.class);
545 commands.put("reindex", ReIndex.class);
546 commands.put("remove", Remove.class);
547 commands.put("rm", Remove.class);
548 commands.put("repos", Repos.class);
549 }
550
551 private OptionParser parser;
552
553 private static OptionSpec<Integer> repoIndex; // ##
554 private static OptionSpec<File> libPath;
555 private static OptionSpec<File> parentPath;
556 private static OptionSpec<File> nativeLibs;
557 private static OptionSpec<File> nativeCmds;
558 private static OptionSpec<File> configFiles;
559
560 private void usage() {
561 out.format("%n");
562 out.format("usage: jmod add-repo [-i <index>] URL%n");
563 out.format(" jmod config [<module-id> ...]%n");
564 out.format(" jmod create [-L <library>] [-P <parent>]" +
565 " [--natlib <natlib>] [--natcmd <natcmd>] [--config <config>]%n");
566 out.format(" jmod del-repo URL%n");
567 out.format(" jmod dump-class <module-id> <class-name> <output-file>%n");
568 out.format(" jmod dump-config <module-id>%n");
569 out.format(" jmod extract <module-file> ...%n");
570 out.format(" jmod identify%n");
571 out.format(" jmod install [--noverify] [-n] <module-id-query> ...%n");
572 out.format(" jmod install [--noverify] <module-file> ...%n");
573 out.format(" jmod install <classes-dir> <module-name> ...%n");
574 out.format(" jmod list [-v] [-p] [-R] [<module-id-query>]%n");
575 out.format(" jmod preinstall <classes-dir> <dst-dir> <module-name> ...%n");
576 out.format(" jmod refresh [-f] [-n] [-v]%n");
577 out.format(" jmod reindex [<module-id> ...]%n");
578 out.format(" jmod remove [-f] [-n] [<module-id> ...]%n");
579 out.format(" jmod repos [-v]%n");
580 out.format("%n");
581 try {
582 parser.printHelpOn(out);
583 } catch (IOException x) {
584 throw new AssertionError(x);
585 }
586 out.format("%n");
587 System.exit(0);
588 }
589
590 public static void run(String [] args) throws OptionException, Command.Exception {
591 new Librarian().exec(args);
592 }
593
594 private void exec(String[] args) throws OptionException, Command.Exception {
595 parser = new OptionParser();
596
597 // ## Need subcommand-specific option parsing
598 libPath
626 parser.acceptsAll(Arrays.asList("N", "no-parent"),
627 "Use no parent library when creating");
628 parser.acceptsAll(Arrays.asList("v", "verbose"),
629 "Enable verbose output");
630 parser.acceptsAll(Arrays.asList("h", "?", "help"),
631 "Show this help message");
632 parser.acceptsAll(Arrays.asList("p", "parent"),
633 "Apply operation to parent library, if any");
634 parser.acceptsAll(Arrays.asList("z", "enable-compression"),
635 "Enable compression of module contents");
636 repoIndex
637 = (parser.acceptsAll(Arrays.asList("i"),
638 "Repository-list index")
639 .withRequiredArg()
640 .describedAs("index")
641 .ofType(Integer.class));
642 parser.acceptsAll(Arrays.asList("f", "force"),
643 "Force the requested operation");
644 parser.acceptsAll(Arrays.asList("n", "dry-run"),
645 "Dry-run the requested operation");
646 parser.acceptsAll(Arrays.asList("R", "repos"),
647 "List contents of associated repositories");
648 parser.acceptsAll(Arrays.asList("noverify"),
649 "Do not verify module signatures. "
650 + "Treat as unsigned.");
651 parser.acceptsAll(Arrays.asList("G", "strip-debug"),
652 "Strip debug attributes during installation");
653
654 if (args.length == 0)
655 usage();
656
657 OptionSet opts = parser.parse(args);
658 if (opts.has("h"))
659 usage();
660 List<String> words = opts.nonOptionArguments();
661 if (words.isEmpty())
662 usage();
663 String verb = words.get(0);
664 Class<? extends Command<SimpleLibrary>> cmd = commands.get(verb);
665 if (cmd == null)
674 lib = SimpleLibrary.open(lp);
675 } catch (FileNotFoundException x) {
676 String msg = null;
677 File f = new File(x.getMessage());
678 try {
679 f = f.getCanonicalFile();
680 if (lp.getCanonicalFile().equals(f))
681 msg = "No such library";
682 else
683 msg = "Cannot open parent library " + f;
684 } catch (IOException y) {
685 throw new Command.Exception(y);
686 }
687 throw new Command.Exception("%s: %s", lp, msg);
688 } catch (IOException x) {
689 throw new Command.Exception(x);
690 }
691 }
692 try {
693 cmd.newInstance().run(lib, opts);
694 } catch (InstantiationException x) {
695 throw new AssertionError(x);
696 } catch (IllegalAccessException x) {
697 throw new AssertionError(x);
698 }
699 }
700
701 private static File libPath(OptionSet opts) {
702 if (opts.has(libPath)) {
703 return opts.valueOf(libPath);
704 } else {
705 String jm = System.getenv("JAVA_MODULES");
706 if (jm != null)
707 return new File(jm);
708 else
709 return homeLibrary;
710 }
711 }
712
713 private Librarian() { }
714
715 public static void main(String[] args) {
716 try {
717 run(args);
|
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();
102 finishArgs();
103 byte[] bs = null;
104 try {
105 bs = lib.readClass(mid, cn);
106 if (bs == null)
107 throw new Command.Exception("%s: No such class in module %s",
108 cn, mid);
109 try (OutputStream fout = (ops.equals("-") ? System.out
110 : new FileOutputStream(ops))) {
111 fout.write(bs);
112 }
113 } catch (IllegalArgumentException x) {
114 throw new Command.Exception(x.getMessage());
115 } catch (IOException x) {
116 throw new Command.Exception(x);
117 }
118 }
119 }
120
121 static class Identify extends Command<SimpleLibrary> {
122 protected void go(SimpleLibrary lib)
123 throws Command.Exception
124 {
125 noDry();
126 finishArgs();
127 out.format("path %s%n", lib.root());
128 out.format("version %d.%d%n",
129 lib.majorVersion(), lib.minorVersion());
130 if (lib.natlibs() != null)
131 out.format("natlibs %s%n", lib.natlibs());
182 throws Command.Exception
183 {
184 String key = takeArg();
185 File kf = new File(key);
186 boolean verifySignature = !opts.has("noverify");
187 boolean strip = opts.has("G");
188
189 // Old form: install <classes-dir> <module-name> ...
190 //
191 if (kf.exists() && kf.isDirectory()) {
192 noDry();
193 List<Manifest> mfs = new ArrayList<>();
194 while (hasArg())
195 mfs.add(Manifest.create(takeArg(), kf));
196 finishArgs();
197 if (mfs.isEmpty())
198 throw new Command.Exception("%s: no module-name specified",
199 command);
200 try {
201 lib.installFromManifests(mfs, strip);
202 } catch (ConfigurationException | IOException x) {
203 throw new Command.Exception(x);
204 }
205 return;
206 }
207
208 // Install one or more module file(s)
209 //
210 if (kf.exists() && kf.isFile()) {
211 noDry();
212 List<File> fs = new ArrayList<>();
213 fs.add(kf);
214 while (hasArg())
215 fs.add(new File(takeArg()));
216 finishArgs();
217 try {
218 lib.install(fs, verifySignature, strip);
219 } catch (ConfigurationException |IOException | SignatureException x) {
220 throw new Command.Exception(x);
221 }
222 return;
223 }
224
225 // Otherwise treat args as module-id queries
226 List<ModuleIdQuery> midqs = new ArrayList<>();
227 String s = key;
228 for (;;) {
229 ModuleIdQuery mq = null;
230 try {
231 mq = jms.parseModuleIdQuery(s);
232 } catch (IllegalArgumentException x) {
233 throw new Command.Exception(x);
234 }
235 midqs.add(mq);
236 if (!hasArg())
237 break;
238 s = takeArg();
239 }
240 try {
241 Resolution res = lib.resolve(midqs);
242 if (res.modulesNeeded().isEmpty()) {
243 if (!quiet)
244 out.format("Nothing to install%n");
245 return;
246 }
247 if (!quiet) {
248 out.format("To install: %s%n",
249 res.modulesNeeded()
250 .toString().replaceAll("^\\[|\\]$", ""));
251 out.format("%d bytes to download/transfer%n",
252 res.downloadRequired());
253 out.format("%d bytes to store%n",
254 res.spaceRequired());
255 }
256 if (dry)
257 return;
258 lib.install(res, verifySignature, strip);
259 } catch (ConfigurationException | IOException | SignatureException x) {
260 throw new Command.Exception(x);
261 }
262
263 }
264 }
265
266 // ## preinstall is used by jpkg for creating debian package.
267 // ## need to revisit this
268 static class PreInstall extends Command<SimpleLibrary> {
269 protected void go(SimpleLibrary lib)
270 throws Command.Exception
271 {
272 noDry();
273 File classes = new File(takeArg());
274 File dst = new File(takeArg());
275 List<Manifest> mfs = new ArrayList<>();
276 while (hasArg())
277 mfs.add(Manifest.create(takeArg(), classes));
278 finishArgs();
279 try {
280 lib.preInstall(mfs, dst);
281 } catch (IOException x) {
282 throw new Command.Exception(x);
283 }
284 }
285 }
286
287 static class Remove extends Command<SimpleLibrary> {
288 protected void go(SimpleLibrary lib)
289 throws Command.Exception
290 {
291 if (dry && force)
292 throw new Command.Exception("%s: specify only one of "
293 + "-n (--dry-run) or -f (--force)",
294 command);
295 List<ModuleId> mids = new ArrayList<>();
296 try {
297 while (hasArg())
298 mids.add(jms.parseModuleId(takeArg()));
299 } catch (IllegalArgumentException x) {
300 throw new Command.Exception(x.getMessage());
301 }
302 try {
303 if (force)
304 lib.removeForcibly(mids);
305 else
306 lib.remove(mids, dry);
307 } catch (ConfigurationException x) {
308 throw new Command.Exception(x);
309 } catch (IOException x) {
310 if (!quiet) {
311 for (Throwable t : x.getSuppressed())
312 err.format("Warning: %s%n", t.getMessage());
313 }
314 throw new Command.Exception(x);
315 }
316 }
317 }
318
319 static class DumpConfig extends Command<SimpleLibrary> {
320 protected void go(SimpleLibrary lib)
321 throws Command.Exception
331 finishArgs();
332 try {
333 ModuleId mid = lib.findLatestModuleId(midq);
334 if (mid == null)
335 throw new Command.Exception(midq + ": No such module");
336 Configuration<Context> cf = lib.readConfiguration(mid);
337 if (cf == null)
338 throw new Command.Exception(mid + ": Not a root module");
339 cf.dump(out, verbose);
340 } catch (IOException x) {
341 throw new Command.Exception(x);
342 }
343 }
344 }
345
346 static class Config extends Command<SimpleLibrary> {
347 protected void go(SimpleLibrary lib)
348 throws Command.Exception
349 {
350 noDry();
351 List<ModuleId> mids = new ArrayList<>();
352 try {
353 while (hasArg())
354 mids.add(jms.parseModuleId(takeArg()));
355 } catch (IllegalArgumentException x) {
356 throw new Command.Exception(x.getMessage());
357 }
358 try {
359 lib.configure(mids);
360 } catch (ConfigurationException | IOException x) {
361 throw new Command.Exception(x);
362 }
363 }
364 }
365
366 static class ReIndex extends Command<SimpleLibrary> {
367 protected void go(SimpleLibrary lib)
368 throws Command.Exception
369 {
370 noDry();
371 List<ModuleId> mids = new ArrayList<>();
372 try {
373 while (hasArg())
374 mids.add(jms.parseModuleId(takeArg()));
375 } catch (IllegalArgumentException x) {
376 throw new Command.Exception(x.getMessage());
377 }
378 try {
379 lib.reIndex(mids);
380 } catch (ConfigurationException | IOException x) {
381 throw new Command.Exception(x);
382 }
383 }
384 }
385
386 static class Repos extends Command<SimpleLibrary> {
387 protected void go(SimpleLibrary lib)
388 throws Command.Exception
389 {
390 noDry();
391 finishArgs();
392 try {
393 RemoteRepositoryList rl = lib.repositoryList();
394 int i = 0;
395 for (RemoteRepository rr : rl.repositories())
396 out.format("%d %s%n", i++, rr.location());
397 } catch (IOException x) {
398 throw new Command.Exception(x);
399 }
400 }
401 }
526 commands.put("refresh", Refresh.class);
527 commands.put("reindex", ReIndex.class);
528 commands.put("remove", Remove.class);
529 commands.put("rm", Remove.class);
530 commands.put("repos", Repos.class);
531 }
532
533 private OptionParser parser;
534
535 private static OptionSpec<Integer> repoIndex; // ##
536 private static OptionSpec<File> libPath;
537 private static OptionSpec<File> parentPath;
538 private static OptionSpec<File> nativeLibs;
539 private static OptionSpec<File> nativeCmds;
540 private static OptionSpec<File> configFiles;
541
542 private void usage() {
543 out.format("%n");
544 out.format("usage: jmod add-repo [-i <index>] URL%n");
545 out.format(" jmod config [<module-id> ...]%n");
546 out.format(" jmod create [-L <library>] [-P <parent>] ");
547 out.format( "[--natlib <natlib>] [--natcmd <natcmd>] ");
548 out.format( "[--config <config>]%n");
549 out.format(" jmod del-repo URL%n");
550 out.format(" jmod dump-class <module-id> <class-name> <output-file>%n");
551 out.format(" jmod dump-config <module-id>%n");
552 out.format(" jmod extract <module-file> ...%n");
553 out.format(" jmod [identify|id]%n");
554 out.format(" jmod install [--noverify] [-n] [-q] <module-id-query> ...%n");
555 out.format(" jmod install [--noverify] <module-file> ...%n");
556 out.format(" jmod install <classes-dir> <module-name> ...%n");
557 out.format(" jmod [list|ls] [-v] [-p] [-R] [<module-id-query>]%n");
558 out.format(" jmod preinstall <classes-dir> <dst-dir> <module-name> ...%n");
559 out.format(" jmod refresh [-f] [-n] [-v]%n");
560 out.format(" jmod reindex [<module-id> ...]%n");
561 out.format(" jmod [remove|rm] [-f] [-n] [-q] [<module-id> ...]%n");
562 out.format(" jmod repos [-v]%n");
563 out.format("%n");
564 try {
565 parser.printHelpOn(out);
566 } catch (IOException x) {
567 throw new AssertionError(x);
568 }
569 out.format("%n");
570 System.exit(0);
571 }
572
573 public static void run(String [] args) throws OptionException, Command.Exception {
574 new Librarian().exec(args);
575 }
576
577 private void exec(String[] args) throws OptionException, Command.Exception {
578 parser = new OptionParser();
579
580 // ## Need subcommand-specific option parsing
581 libPath
609 parser.acceptsAll(Arrays.asList("N", "no-parent"),
610 "Use no parent library when creating");
611 parser.acceptsAll(Arrays.asList("v", "verbose"),
612 "Enable verbose output");
613 parser.acceptsAll(Arrays.asList("h", "?", "help"),
614 "Show this help message");
615 parser.acceptsAll(Arrays.asList("p", "parent"),
616 "Apply operation to parent library, if any");
617 parser.acceptsAll(Arrays.asList("z", "enable-compression"),
618 "Enable compression of module contents");
619 repoIndex
620 = (parser.acceptsAll(Arrays.asList("i"),
621 "Repository-list index")
622 .withRequiredArg()
623 .describedAs("index")
624 .ofType(Integer.class));
625 parser.acceptsAll(Arrays.asList("f", "force"),
626 "Force the requested operation");
627 parser.acceptsAll(Arrays.asList("n", "dry-run"),
628 "Dry-run the requested operation");
629 parser.acceptsAll(Arrays.asList("q", "quiet"),
630 "Suppress chattering output");
631 parser.acceptsAll(Arrays.asList("R", "repos"),
632 "List contents of associated repositories");
633 parser.acceptsAll(Arrays.asList("noverify"),
634 "Do not verify module signatures. "
635 + "Treat as unsigned.");
636 parser.acceptsAll(Arrays.asList("G", "strip-debug"),
637 "Strip debug attributes during installation");
638
639 if (args.length == 0)
640 usage();
641
642 OptionSet opts = parser.parse(args);
643 if (opts.has("h"))
644 usage();
645 List<String> words = opts.nonOptionArguments();
646 if (words.isEmpty())
647 usage();
648 String verb = words.get(0);
649 Class<? extends Command<SimpleLibrary>> cmd = commands.get(verb);
650 if (cmd == null)
659 lib = SimpleLibrary.open(lp);
660 } catch (FileNotFoundException x) {
661 String msg = null;
662 File f = new File(x.getMessage());
663 try {
664 f = f.getCanonicalFile();
665 if (lp.getCanonicalFile().equals(f))
666 msg = "No such library";
667 else
668 msg = "Cannot open parent library " + f;
669 } catch (IOException y) {
670 throw new Command.Exception(y);
671 }
672 throw new Command.Exception("%s: %s", lp, msg);
673 } catch (IOException x) {
674 throw new Command.Exception(x);
675 }
676 }
677 try {
678 cmd.newInstance().run(lib, opts);
679 } catch (InstantiationException | IllegalAccessException x) {
680 throw new AssertionError(x);
681 }
682 }
683
684 private static File libPath(OptionSet opts) {
685 if (opts.has(libPath)) {
686 return opts.valueOf(libPath);
687 } else {
688 String jm = System.getenv("JAVA_MODULES");
689 if (jm != null)
690 return new File(jm);
691 else
692 return homeLibrary;
693 }
694 }
695
696 private Librarian() { }
697
698 public static void main(String[] args) {
699 try {
700 run(args);
|