< prev index next >

src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java

Print this page




 444                     option.execute();
 445                 } else {
 446                     throw new PackagerException("ERR_InvalidOption", arg);
 447                 }
 448             }
 449 
 450             if (hasMainJar && !hasMainClass) {
 451                 // try to get main-class from manifest
 452                 String mainClass = getMainClassFromManifest();
 453                 if (mainClass != null) {
 454                     CLIOptions.setOptionValue(
 455                             CLIOptions.APPCLASS.getId(), mainClass);
 456                 }
 457             }
 458 
 459             // display error for arguments that are not supported
 460             // for current configuration.
 461 
 462             validateArguments();
 463 
 464             addResources(deployParams, input);
 465 
 466             List<Map<String, ? super Object>> launchersAsMap =
 467                     new ArrayList<>();
 468 
 469             for (AddLauncherArguments sl : addLaunchers) {
 470                 launchersAsMap.add(sl.getLauncherMap());
 471             }
 472 
 473             deployParams.addBundleArgument(
 474                     StandardBundlerParam.ADD_LAUNCHERS.getID(),
 475                     launchersAsMap);
 476 
 477             // at this point deployParams should be already configured
 478 
 479             deployParams.validate();
 480 
 481             BundleParams bp = deployParams.getBundleParams();
 482 
 483             // validate name(s)
 484             ArrayList<String> usedNames = new ArrayList<String>();


 630                         bundler.getName(), e.getMessage());
 631             }
 632         } catch (RuntimeException re) {
 633             Log.debug(re);
 634             throw new PackagerException(re, "MSG_BundlerRuntimeException",
 635                     bundler.getName(), re.toString());
 636         } finally {
 637             if (userProvidedBuildRoot) {
 638                 Log.verbose(MessageFormat.format(
 639                         I18N.getString("message.debug-working-directory"),
 640                         (new File(buildRoot)).getAbsolutePath()));
 641             } else {
 642                 // always clean up the temporary directory created
 643                 // when --temp-root option not used.
 644                 bundler.cleanup(localParams);
 645             }
 646         }
 647     }
 648 
 649     private void addResources(DeployParams deployParams,
 650             String inputdir) throws PackagerException {
 651 
 652         if (inputdir == null || inputdir.isEmpty()) {
 653             return;
 654         }
 655 
 656         File baseDir = new File(inputdir);
 657 
 658         if (!baseDir.isDirectory()) {
 659             throw new PackagerException("ERR_InputNotDirectory", inputdir);
 660         }
 661         if (!baseDir.canRead()) {
 662             throw new PackagerException("ERR_CannotReadInputDir", inputdir);
 663         }
 664 
 665         List<String> fileNames;
 666         fileNames = new ArrayList<>();
 667         try (Stream<Path> files = Files.list(baseDir.toPath())) {
 668             files.forEach(file -> fileNames.add(
 669                     file.getFileName().toString()));
 670         } catch (IOException e) {
 671             Log.error("Unable to add resources: " + e.getMessage());
 672         }
 673         fileNames.forEach(file -> deployParams.addResource(baseDir, file));
 674 
 675         deployParams.setClasspath();
 676     }
 677 
 678     static CLIOptions toCLIOption(String arg) {
 679         CLIOptions option;
 680         if ((option = argIds.get(arg)) == null) {
 681             option = argShortIds.get(arg);
 682         }
 683         return option;
 684     }
 685 
 686     static Map<String, String> getPropertiesFromFile(String filename) {
 687         Map<String, String> map = new HashMap<>();
 688         // load properties file
 689         File file = new File(filename);
 690         Properties properties = new Properties();
 691         try (FileInputStream in = new FileInputStream(file)) {
 692             properties.load(in);
 693         } catch (IOException e) {
 694             Log.error("Exception: " + e.getMessage());
 695         }




 444                     option.execute();
 445                 } else {
 446                     throw new PackagerException("ERR_InvalidOption", arg);
 447                 }
 448             }
 449 
 450             if (hasMainJar && !hasMainClass) {
 451                 // try to get main-class from manifest
 452                 String mainClass = getMainClassFromManifest();
 453                 if (mainClass != null) {
 454                     CLIOptions.setOptionValue(
 455                             CLIOptions.APPCLASS.getId(), mainClass);
 456                 }
 457             }
 458 
 459             // display error for arguments that are not supported
 460             // for current configuration.
 461 
 462             validateArguments();
 463 
 464             addResources(deployParams, input, mainJarPath);
 465 
 466             List<Map<String, ? super Object>> launchersAsMap =
 467                     new ArrayList<>();
 468 
 469             for (AddLauncherArguments sl : addLaunchers) {
 470                 launchersAsMap.add(sl.getLauncherMap());
 471             }
 472 
 473             deployParams.addBundleArgument(
 474                     StandardBundlerParam.ADD_LAUNCHERS.getID(),
 475                     launchersAsMap);
 476 
 477             // at this point deployParams should be already configured
 478 
 479             deployParams.validate();
 480 
 481             BundleParams bp = deployParams.getBundleParams();
 482 
 483             // validate name(s)
 484             ArrayList<String> usedNames = new ArrayList<String>();


 630                         bundler.getName(), e.getMessage());
 631             }
 632         } catch (RuntimeException re) {
 633             Log.debug(re);
 634             throw new PackagerException(re, "MSG_BundlerRuntimeException",
 635                     bundler.getName(), re.toString());
 636         } finally {
 637             if (userProvidedBuildRoot) {
 638                 Log.verbose(MessageFormat.format(
 639                         I18N.getString("message.debug-working-directory"),
 640                         (new File(buildRoot)).getAbsolutePath()));
 641             } else {
 642                 // always clean up the temporary directory created
 643                 // when --temp-root option not used.
 644                 bundler.cleanup(localParams);
 645             }
 646         }
 647     }
 648 
 649     private void addResources(DeployParams deployParams,
 650             String inputdir, String mainJar) throws PackagerException {
 651 
 652         if (inputdir == null || inputdir.isEmpty()) {
 653             return;
 654         }
 655 
 656         File baseDir = new File(inputdir);
 657 
 658         if (!baseDir.isDirectory()) {
 659             throw new PackagerException("ERR_InputNotDirectory", inputdir);
 660         }
 661         if (!baseDir.canRead()) {
 662             throw new PackagerException("ERR_CannotReadInputDir", inputdir);
 663         }
 664 
 665         List<String> fileNames;
 666         fileNames = new ArrayList<>();
 667         try (Stream<Path> files = Files.list(baseDir.toPath())) {
 668             files.forEach(file -> fileNames.add(
 669                     file.getFileName().toString()));
 670         } catch (IOException e) {
 671             Log.error("Unable to add resources: " + e.getMessage());
 672         }
 673         fileNames.forEach(file -> deployParams.addResource(baseDir, file));
 674 
 675         deployParams.setClasspath(mainJar);
 676     }
 677 
 678     static CLIOptions toCLIOption(String arg) {
 679         CLIOptions option;
 680         if ((option = argIds.get(arg)) == null) {
 681             option = argShortIds.get(arg);
 682         }
 683         return option;
 684     }
 685 
 686     static Map<String, String> getPropertiesFromFile(String filename) {
 687         Map<String, String> map = new HashMap<>();
 688         // load properties file
 689         File file = new File(filename);
 690         Properties properties = new Properties();
 691         try (FileInputStream in = new FileInputStream(file)) {
 692             properties.load(in);
 693         } catch (IOException e) {
 694             Log.error("Exception: " + e.getMessage());
 695         }


< prev index next >