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

Print this page




 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()) {
 156                 File module = new File(takeArg());
 157                 File destination = null;
 158                 try (FileInputStream fis = new FileInputStream(module);
 159                     DataInputStream dis = new DataInputStream(fis);
 160                     ModuleFile.Reader reader = new ModuleFile.Reader(dis)) {
 161 
 162                     ModuleInfo mi = jms.parseModuleInfo(reader.readStart());
 163                     destination = new File(mi.id().name());
 164                     Path path = destination.toPath();
 165                     Files.deleteIfExists(path);
 166                     Files.createDirectory(path);
 167                     reader.readRest(destination, false);
 168                 }
 169                 catch (IOException x) {
 170                     // Try to cleanup if an exception is thrown
 171                     if (destination != null && destination.exists())
 172                         try {
 173                             FilePaths.deleteTree(destination.toPath());
 174                         }
 175                         catch (IOException y) {
 176                             throw (Command.Exception)
 177                                 new Command.Exception(y).initCause(x);
 178                         }
 179                     throw new Command.Exception(x);
 180                 }
 181             }
 182             finishArgs();
 183         }
 184     }
 185 
 186     static class Install extends Command<SimpleLibrary> {
 187         protected void go(SimpleLibrary lib)
 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 {




 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()) {
 156                 File module = new File(takeArg());
 157                 File destination = null;
 158                 try (FileInputStream fis = new FileInputStream(module)) {
 159                     ModuleFile.Reader reader = new ModuleFile.Reader(fis);

 160 
 161                     ModuleInfo mi = jms.parseModuleInfo(reader.getModuleInfoBytes());
 162                     destination = new File(mi.id().name());
 163                     Path path = destination.toPath();
 164                     Files.deleteIfExists(path);
 165                     Files.createDirectory(path);
 166                     reader.extractTo(destination, false);
 167                 } catch (IOException | ModuleFileParserException x) {

 168                     // Try to cleanup if an exception is thrown
 169                     if (destination != null && destination.exists())
 170                         try {
 171                             FilePaths.deleteTree(destination.toPath());
 172                         } catch (IOException y) {

 173                             throw (Command.Exception)
 174                                 new Command.Exception(y).initCause(x);
 175                         }
 176                     throw new Command.Exception(x);
 177                 }
 178             }
 179             finishArgs();
 180         }
 181     }
 182 
 183     static class Install extends Command<SimpleLibrary> {
 184         protected void go(SimpleLibrary lib)
 185             throws Command.Exception
 186         {
 187             String key = takeArg();
 188             File kf = new File(key);
 189             boolean verifySignature = !opts.has("noverify");
 190             boolean strip = opts.has("G");
 191 
 192             // Old form: install <classes-dir> <module-name> ...
 193             //
 194             if (kf.exists() && kf.isDirectory()) {
 195                 noDry();
 196                 List<Manifest> mfs = new ArrayList<>();
 197                 while (hasArg())
 198                     mfs.add(Manifest.create(takeArg(), kf));
 199                 finishArgs();
 200                 if (mfs.isEmpty())
 201                     throw new Command.Exception("%s: no module-name specified",
 202                                                  command);
 203                 try {
 204                     lib.installFromManifests(mfs, strip);
 205                 } catch (ConfigurationException | IOException x) {
 206                     throw new Command.Exception(x);


 207                 }
 208                 return;
 209             }
 210 
 211             // Install one or more module file(s)
 212             //
 213             if (kf.exists() && kf.isFile()) {
 214                 noDry();
 215                 List<File> fs = new ArrayList<>();
 216                 fs.add(kf);
 217                 while (hasArg())
 218                     fs.add(new File(takeArg()));
 219                 finishArgs();
 220                 try {
 221                     lib.install(fs, verifySignature, strip);
 222                 } catch (ConfigurationException | IOException |
 223                          SignatureException | ModuleFileParserException x) {
 224                     throw new Command.Exception(x);




 225                 }
 226                 return;
 227             }
 228 
 229             // Otherwise treat args as module-id queries
 230             List<ModuleIdQuery> midqs = new ArrayList<>();
 231             String s = key;
 232             for (;;) {
 233                 ModuleIdQuery mq = null;
 234                 try {
 235                     mq = jms.parseModuleIdQuery(s);
 236                 } catch (IllegalArgumentException x) {
 237                     throw new Command.Exception(x);
 238                 }
 239                 midqs.add(mq);
 240                 if (!hasArg())
 241                     break;
 242                 s = takeArg();
 243             }
 244             try {
 245                 boolean quiet = false;  // ## Need -q
 246                 Resolution res = lib.resolve(midqs);
 247                 if (res.modulesNeeded().isEmpty()) {
 248                     if (!quiet)
 249                         out.format("Nothing to install%n");
 250                     return;
 251                 }
 252                 if (!quiet) {
 253                     out.format("To install: %s%n",
 254                                res.modulesNeeded()
 255                                .toString().replaceAll("^\\[|\\]$", ""));
 256                     out.format("%d bytes to download/transfer%n",
 257                                res.downloadRequired());
 258                     out.format("%d bytes to store%n",
 259                                res.spaceRequired());
 260                 }
 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 {