src/share/classes/org/openjdk/jigsaw/cli/Librarian.java

Print this page

        

@@ -104,19 +104,13 @@
             try {
                 bs = lib.readClass(mid, cn);
                 if (bs == null)
                     throw new Command.Exception("%s: No such class in module %s",
                                                 cn, mid);
-                OutputStream fout = null;
-                try {
-                    fout = (ops.equals("-")
-                            ? System.out
-                            : new FileOutputStream(ops));
+                try (OutputStream fout = (ops.equals("-") ? System.out
+                            : new FileOutputStream(ops))) {
                     fout.write(bs);
-                } finally {
-                    if (fout != null)
-                        fout.close();
                 }
             } catch (IllegalArgumentException x) {
                 throw new Command.Exception(x.getMessage());
             } catch (IOException x) {
                 throw new Command.Exception(x);

@@ -203,14 +197,12 @@
                 if (mfs.isEmpty())
                     throw new Command.Exception("%s: no module-name specified",
                                                  command);
                 try {
                     lib.installFromManifests(mfs, strip);
-                } catch (ConfigurationException x) {
+                } catch (ConfigurationException | IOException x) {
                     throw new Command.Exception(x);
-                } catch (IOException x) {
-                    throw new Command.Exception(x);
                 }
                 return;
             }
 
             // Install one or more module file(s)

@@ -222,16 +214,12 @@
                 while (hasArg())
                     fs.add(new File(takeArg()));
                 finishArgs();
                 try {
                     lib.install(fs, verifySignature, strip);
-                } catch (ConfigurationException x) {
+                } catch (ConfigurationException |IOException | SignatureException x) {
                     throw new Command.Exception(x);
-                } catch (IOException x) {
-                    throw new Command.Exception(x);
-                } catch (SignatureException x) {
-                    throw new Command.Exception(x);
                 }
                 return;
             }
 
             // Otherwise treat args as module-id queries

@@ -248,11 +236,10 @@
                 if (!hasArg())
                     break;
                 s = takeArg();
             }
             try {
-                boolean quiet = false;  // ## Need -q
                 Resolution res = lib.resolve(midqs);
                 if (res.modulesNeeded().isEmpty()) {
                     if (!quiet)
                         out.format("Nothing to install%n");
                     return;

@@ -283,11 +270,11 @@
             throws Command.Exception
         {
             noDry();
             File classes = new File(takeArg());
             File dst = new File(takeArg());
-            List<Manifest> mfs = new ArrayList<Manifest>();
+            List<Manifest> mfs = new ArrayList<>();
             while (hasArg())
                 mfs.add(Manifest.create(takeArg(), classes));
             finishArgs();
             try {
                 lib.preInstall(mfs, dst);

@@ -303,18 +290,17 @@
         {
             if (dry && force)
                 throw new Command.Exception("%s: specify only one of "
                                         + "-n (--dry-run) or -f (--force)",
                                         command);
-            List<ModuleId> mids = new ArrayList<ModuleId>();
+            List<ModuleId> mids = new ArrayList<>();
             try {
                 while (hasArg())
                     mids.add(jms.parseModuleId(takeArg()));
             } catch (IllegalArgumentException x) {
                 throw new Command.Exception(x.getMessage());
             }
-            boolean quiet = false;  // ## Need -q
             try {
                 if (force)
                     lib.removeForcibly(mids);
                 else
                     lib.remove(mids, dry);

@@ -360,45 +346,41 @@
     static class Config extends Command<SimpleLibrary> {
         protected void go(SimpleLibrary lib)
             throws Command.Exception
         {
             noDry();
-            List<ModuleId> mids = new ArrayList<ModuleId>();
+            List<ModuleId> mids = new ArrayList<>();
             try {
                 while (hasArg())
                     mids.add(jms.parseModuleId(takeArg()));
             } catch (IllegalArgumentException x) {
                 throw new Command.Exception(x.getMessage());
             }
             try {
                 lib.configure(mids);
-            } catch (ConfigurationException x) {
+            } catch (ConfigurationException | IOException x) {
                 throw new Command.Exception(x);
-            } catch (IOException x) {
-                throw new Command.Exception(x);
             }
         }
     }
 
     static class ReIndex extends Command<SimpleLibrary> {
         protected void go(SimpleLibrary lib)
             throws Command.Exception
         {
             noDry();
-            List<ModuleId> mids = new ArrayList<ModuleId>();
+            List<ModuleId> mids = new ArrayList<>();
             try {
                 while (hasArg())
                     mids.add(jms.parseModuleId(takeArg()));
             } catch (IllegalArgumentException x) {
                 throw new Command.Exception(x.getMessage());
             }
             try {
                 lib.reIndex(mids);
-            } catch (ConfigurationException x) {
+            } catch (ConfigurationException | IOException x) {
                 throw new Command.Exception(x);
-            } catch (IOException x) {
-                throw new Command.Exception(x);
             }
         }
     }
 
     static class Repos extends Command<SimpleLibrary> {

@@ -559,25 +541,26 @@
 
     private void usage() {
         out.format("%n");
         out.format("usage: jmod add-repo [-i <index>] URL%n");
         out.format("       jmod config [<module-id> ...]%n");
-        out.format("       jmod create [-L <library>] [-P <parent>]" +
-                " [--natlib <natlib>] [--natcmd <natcmd>] [--config <config>]%n");
+        out.format("       jmod create [-L <library>] [-P <parent>] ");
+        out.format(                   "[--natlib <natlib>] [--natcmd <natcmd>] ");
+        out.format(                   "[--config <config>]%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 extract <module-file> ...%n");
-        out.format("       jmod identify%n");
-        out.format("       jmod install [--noverify] [-n] <module-id-query> ...%n");
+        out.format("       jmod [identify|id]%n");
+        out.format("       jmod install [--noverify] [-n] [-q] <module-id-query> ...%n");
         out.format("       jmod install [--noverify] <module-file> ...%n");
         out.format("       jmod install <classes-dir> <module-name> ...%n");
-        out.format("       jmod list [-v] [-p] [-R] [<module-id-query>]%n");
+        out.format("       jmod [list|ls] [-v] [-p] [-R] [<module-id-query>]%n");
         out.format("       jmod preinstall <classes-dir> <dst-dir> <module-name> ...%n");
         out.format("       jmod refresh [-f] [-n] [-v]%n");
         out.format("       jmod reindex [<module-id> ...]%n");
-        out.format("       jmod remove [-f] [-n] [<module-id> ...]%n");
+        out.format("       jmod [remove|rm] [-f] [-n] [-q] [<module-id> ...]%n");
         out.format("       jmod repos [-v]%n");
         out.format("%n");
         try {
             parser.printHelpOn(out);
         } catch (IOException x) {

@@ -641,10 +624,12 @@
                .ofType(Integer.class));
         parser.acceptsAll(Arrays.asList("f", "force"),
                           "Force the requested operation");
         parser.acceptsAll(Arrays.asList("n", "dry-run"),
                           "Dry-run the requested operation");
+        parser.acceptsAll(Arrays.asList("q", "quiet"),
+                          "Suppress chattering output");
         parser.acceptsAll(Arrays.asList("R", "repos"),
                           "List contents of associated repositories");
         parser.acceptsAll(Arrays.asList("noverify"),
                           "Do not verify module signatures. "
                           + "Treat as unsigned.");

@@ -689,14 +674,12 @@
                 throw new Command.Exception(x);
             }
         }
         try {
             cmd.newInstance().run(lib, opts);
-        } catch (InstantiationException x) {
+        } catch (InstantiationException | IllegalAccessException x) {
             throw new AssertionError(x);
-        } catch (IllegalAccessException x) {
-            throw new AssertionError(x);
         }
     }
 
     private static File libPath(OptionSet opts) {
         if (opts.has(libPath)) {