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

Print this page

        

@@ -42,11 +42,11 @@
 import org.openjdk.internal.joptsimple.*;
 
 
 public class Librarian {
 
-    private static JigsawModuleSystem jms
+    private static final JigsawModuleSystem jms
         = JigsawModuleSystem.instance();
 
     private static final File homeLibrary = Library.systemLibraryPath();
 
     static class Create extends Command<SimpleLibrary> {

@@ -198,10 +198,13 @@
                 noDry();
                 List<Manifest> mfs = new ArrayList<>();
                 while (hasArg())
                     mfs.add(Manifest.create(takeArg(), kf));
                 finishArgs();
+                if (mfs.isEmpty())
+                    throw new Command.Exception("%s: no module-name specified",
+                                                 command);
                 try {
                     lib.installFromManifests(mfs, strip);
                 } catch (ConfigurationException x) {
                     throw new Command.Exception(x);
                 } catch (IOException x) {

@@ -292,10 +295,44 @@
                 throw new Command.Exception(x);
             }
         }
     }
 
+    static class Remove extends Command<SimpleLibrary> {
+        protected void go(SimpleLibrary lib)
+            throws Command.Exception
+        {
+            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>();
+            try {
+                while (hasArg())
+                    mids.add(jms.parseModuleId(takeArg()));
+            } catch (IllegalArgumentException x) {
+                throw new Command.Exception(x.getMessage());
+            }
+            boolean quiet = false;  // ## Need -q
+            try {
+                List<IOException> excs;
+                if (force)
+                    lib.removeForcibly(mids);
+                else
+                    lib.remove(mids, dry);
+            } catch (ConfigurationException x) {
+                throw new Command.Exception(x);
+            } catch (IOException x) {                
+                if (!quiet) {
+                    for (Throwable t : x.getSuppressed())
+                        out.format("Warning: %s%n", t.getMessage());
+                }
+                throw new Command.Exception(x);
+            }
+        }
+    }
+
     static class DumpConfig extends Command<SimpleLibrary> {
         protected void go(SimpleLibrary lib)
             throws Command.Exception
         {
             noDry();

@@ -486,11 +523,11 @@
                 throw new Command.Exception(x);
             }
         }
     }
 
-    private static Map<String,Class<? extends Command<SimpleLibrary>>> commands
+    private static final Map<String,Class<? extends Command<SimpleLibrary>>> commands
         = new HashMap<>();
 
     static {
         commands.put("add-repo", AddRepo.class);
         commands.put("config", Config.class);

@@ -505,10 +542,12 @@
         commands.put("list", Commands.ListLibrary.class);
         commands.put("ls", Commands.ListLibrary.class);
         commands.put("preinstall", PreInstall.class);
         commands.put("refresh", Refresh.class);
         commands.put("reindex", ReIndex.class);
+        commands.put("remove", Remove.class);
+        commands.put("rm", Remove.class);
         commands.put("repos", Repos.class);
     }
 
     private OptionParser parser;
 

@@ -520,25 +559,26 @@
     private static OptionSpec<File> configFiles;
 
     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>]" +
                 " [--natlib <natlib>] [--natcmd <natcmd>] [--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 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 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 repos [-v]%n");
         out.format("%n");
         try {
             parser.printHelpOn(out);
         } catch (IOException x) {