src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
branchJDK-8200758-branch
changeset 58114 42df7de58e39
parent 57909 c7de06ed4b54
child 58115 4a27283b542d
equal deleted inserted replaced
58113:885b0543f6e4 58114:42df7de58e39
    72     // regexp for parsing args (for example, for additional launchers)
    72     // regexp for parsing args (for example, for additional launchers)
    73     private static Pattern pattern = Pattern.compile(
    73     private static Pattern pattern = Pattern.compile(
    74           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
    74           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
    75 
    75 
    76     private DeployParams deployParams = null;
    76     private DeployParams deployParams = null;
    77     private String packageType = null;
       
    78 
    77 
    79     private int pos = 0;
    78     private int pos = 0;
    80     private List<String> argList = null;
    79     private List<String> argList = null;
    81 
    80 
    82     private List<CLIOptions> allOptions = null;
    81     private List<CLIOptions> allOptions = null;
   117         Log.verbose ("\njpackage argument list: \n" + argList + "\n");
   116         Log.verbose ("\njpackage argument list: \n" + argList + "\n");
   118         pos = 0;
   117         pos = 0;
   119 
   118 
   120         deployParams = new DeployParams();
   119         deployParams = new DeployParams();
   121 
   120 
   122         packageType = null;
       
   123 
       
   124         allOptions = new ArrayList<>();
   121         allOptions = new ArrayList<>();
   125 
   122 
   126         addLaunchers = new ArrayList<>();
   123         addLaunchers = new ArrayList<>();
   127     }
   124     }
   128 
   125 
   129     // CLIOptions is public for DeployParamsTest
   126     // CLIOptions is public for DeployParamsTest
   130     public enum CLIOptions {
   127     public enum CLIOptions {
   131         PACKAGE_TYPE("package-type", OptionCategories.PROPERTY, () -> {
   128         PACKAGE_TYPE("package-type", OptionCategories.PROPERTY, () -> {
   132             context().packageType = popArg();
   129             context().deployParams.setTargetFormat(popArg());
   133             context().deployParams.setTargetFormat(context().packageType);
       
   134         }),
   130         }),
   135 
   131 
   136         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
   132         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
   137             context().input = popArg();
   133             context().input = popArg();
   138             setOptionValue("input", context().input);
   134             setOptionValue("input", context().input);
   528             return false;
   524             return false;
   529         }
   525         }
   530     }
   526     }
   531 
   527 
   532     private void validateArguments() throws PackagerException {
   528     private void validateArguments() throws PackagerException {
   533         String packageType = deployParams.getTargetFormat();
   529         String type = deployParams.getTargetFormat();
   534         String ptype = (packageType != null) ? packageType : "default";
   530         String ptype = (type != null) ? type : "default";
   535         boolean imageOnly = (packageType == null);
   531         boolean imageOnly = deployParams.isTargetAppImage();
   536         boolean hasAppImage = allOptions.contains(
   532         boolean hasAppImage = allOptions.contains(
   537                 CLIOptions.PREDEFINED_APP_IMAGE);
   533                 CLIOptions.PREDEFINED_APP_IMAGE);
   538         boolean hasRuntime = allOptions.contains(
   534         boolean hasRuntime = allOptions.contains(
   539                 CLIOptions.PREDEFINED_RUNTIME_IMAGE);
   535                 CLIOptions.PREDEFINED_RUNTIME_IMAGE);
   540         boolean installerOnly = !imageOnly && hasAppImage;
   536         boolean installerOnly = !imageOnly && hasAppImage;
   548                         option.getIdWithPrefix());
   544                         option.getIdWithPrefix());
   549             }
   545             }
   550             if (imageOnly) {
   546             if (imageOnly) {
   551                 if (!ValidOptions.checkIfImageSupported(option)) {
   547                 if (!ValidOptions.checkIfImageSupported(option)) {
   552                     throw new PackagerException("ERR_InvalidTypeOption",
   548                     throw new PackagerException("ERR_InvalidTypeOption",
   553                         option.getIdWithPrefix(), packageType);
   549                         option.getIdWithPrefix(), type);
   554                 }
   550                 }
   555             } else if (installerOnly || runtimeInstaller) {
   551             } else if (installerOnly || runtimeInstaller) {
   556                 if (!ValidOptions.checkIfInstallerSupported(option)) {
   552                 if (!ValidOptions.checkIfInstallerSupported(option)) {
   557                     if (runtimeInstaller) {
   553                     if (runtimeInstaller) {
   558                         throw new PackagerException("ERR_NoInstallerEntryPoint",
   554                         throw new PackagerException("ERR_NoInstallerEntryPoint",
   577             throw new PackagerException("ERR_NoEntryPoint");
   573             throw new PackagerException("ERR_NoEntryPoint");
   578         }
   574         }
   579     }
   575     }
   580 
   576 
   581     private jdk.jpackage.internal.Bundler getPlatformBundler() {
   577     private jdk.jpackage.internal.Bundler getPlatformBundler() {
   582         String bundleType = (packageType == null ? "IMAGE" : "INSTALLER");
   578         boolean appImage = deployParams.isTargetAppImage();
       
   579         String type = deployParams.getTargetFormat();
       
   580         String bundleType = (appImage ?  "IMAGE" : "INSTALLER");
   583 
   581 
   584         for (jdk.jpackage.internal.Bundler bundler :
   582         for (jdk.jpackage.internal.Bundler bundler :
   585                 Bundlers.createBundlersInstance().getBundlers(bundleType)) {
   583                 Bundlers.createBundlersInstance().getBundlers(bundleType)) {
   586             if ((packageType == null) ||
   584             if (type == null) {
   587                      packageType.equalsIgnoreCase(bundler.getID())) {
   585                  if (bundler.isDefault()
   588                  if (bundler.supported(runtimeInstaller)) {
   586                          && bundler.supported(runtimeInstaller)) {
       
   587                      return bundler;
       
   588                  }
       
   589             } else {
       
   590                  if ((appImage || type.equalsIgnoreCase(bundler.getID()))
       
   591                          && bundler.supported(runtimeInstaller)) {
   589                      return bundler;
   592                      return bundler;
   590                  }
   593                  }
   591             }
   594             }
   592         }
   595         }
   593         return null;
   596         return null;