src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
branchJDK-8200758-branch
changeset 57150 fa68c2ab636d
parent 57140 3dcb33ce7ced
child 57151 38d0b67617e3
equal deleted inserted replaced
57141:e7ba8c89abe7 57150:fa68c2ab636d
    64     private static final ResourceBundle I18N = ResourceBundle.getBundle(
    64     private static final ResourceBundle I18N = ResourceBundle.getBundle(
    65             "jdk.jpackage.internal.resources.MainResources");
    65             "jdk.jpackage.internal.resources.MainResources");
    66 
    66 
    67     private static final String IMAGE_MODE = "image";
    67     private static final String IMAGE_MODE = "image";
    68     private static final String INSTALLER_MODE = "installer";
    68     private static final String INSTALLER_MODE = "installer";
    69     private static final String JRE_INSTALLER_MODE = "jre-installer";
       
    70 
    69 
    71     private static final String FA_EXTENSIONS = "extension";
    70     private static final String FA_EXTENSIONS = "extension";
    72     private static final String FA_CONTENT_TYPE = "mime-type";
    71     private static final String FA_CONTENT_TYPE = "mime-type";
    73     private static final String FA_DESCRIPTION = "description";
    72     private static final String FA_DESCRIPTION = "description";
    74     private static final String FA_ICON = "icon";
    73     private static final String FA_ICON = "icon";
    91                     Boolean.class,
    90                     Boolean.class,
    92                     p -> Boolean.FALSE,
    91                     p -> Boolean.FALSE,
    93                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
    92                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
    94                             true : Boolean.valueOf(s));
    93                             true : Boolean.valueOf(s));
    95 
    94 
    96     public static final BundlerParamInfo<Boolean> CREATE_JRE_INSTALLER =
       
    97             new StandardBundlerParam<>(
       
    98                     I18N.getString("param.create-jre-installer.name"),
       
    99                     I18N.getString("param.create-jre-installer.description"),
       
   100                     JRE_INSTALLER_MODE,
       
   101                     Boolean.class,
       
   102                     p -> Boolean.FALSE,
       
   103                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
       
   104                             true : Boolean.valueOf(s));
       
   105 
       
   106     // regexp for parsing args (for example, for secondary launchers)
    95     // regexp for parsing args (for example, for secondary launchers)
   107     private static Pattern pattern = Pattern.compile(
    96     private static Pattern pattern = Pattern.compile(
   108           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
    97           "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
   109 
    98 
   110     private DeployParams deployParams = null;
    99     private DeployParams deployParams = null;
   128     private boolean retainBuildRoot = false;
   117     private boolean retainBuildRoot = false;
   129 
   118 
   130     private String buildRoot = null;
   119     private String buildRoot = null;
   131     private String mainJarPath = null;
   120     private String mainJarPath = null;
   132 
   121 
   133     private static boolean jreInstaller = false;
   122     private static boolean runtimeInstaller = false;
   134 
   123 
   135     private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
   124     private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
   136 
   125 
   137     private List<SecondaryLauncherArguments> secondaryLaunchers = null;
   126     private List<SecondaryLauncherArguments> secondaryLaunchers = null;
   138 
   127 
   165 
   154 
   166         CREATE_INSTALLER(INSTALLER_MODE, OptionCategories.MODE, () -> {
   155         CREATE_INSTALLER(INSTALLER_MODE, OptionCategories.MODE, () -> {
   167             setOptionValue(INSTALLER_MODE, true);
   156             setOptionValue(INSTALLER_MODE, true);
   168             context().bundleType = BundlerType.INSTALLER;
   157             context().bundleType = BundlerType.INSTALLER;
   169             String format = "installer";
   158             String format = "installer";
   170             if (hasNextArg()) {
       
   171                 String arg = popArg();
       
   172                 if (!arg.startsWith("-")) {
       
   173                     format = arg.toLowerCase();
       
   174                     context().hasTargetFormat = true;
       
   175                 } else {
       
   176                     prevArg();
       
   177                 }
       
   178             }
       
   179             context().deployParams.setTargetFormat(format);
   159             context().deployParams.setTargetFormat(format);
   180         }),
   160         }),
   181 
   161 
   182         CREATE_JRE_INSTALLER(JRE_INSTALLER_MODE, OptionCategories.MODE, () -> {
   162         RUNTIME_INSTALLER("runtime-installer",
   183             setOptionValue(JRE_INSTALLER_MODE, true);
   163                 OptionCategories.PROPERTY, () -> {
   184             context().bundleType = BundlerType.INSTALLER;
   164             runtimeInstaller = true;
   185             String format = "installer";
   165             setOptionValue("runtime-installer", true);
   186             if (hasNextArg()) {
   166         }),
   187                 String arg = popArg();
   167 
   188                 if (!arg.startsWith("-")) {
   168         INSTALLER_TYPE("installer-type", OptionCategories.PROPERTY, () -> {
   189                     format = arg.toLowerCase();
   169             String type = popArg();
   190                     context().hasTargetFormat = true;
   170             context().deployParams.setTargetFormat(type);
   191                 } else {
   171             context().hasTargetFormat = true;
   192                     prevArg();
   172             setOptionValue("installer-type", type);
   193                 }
       
   194             }
       
   195             jreInstaller = true;
       
   196             context().deployParams.setTargetFormat(format);
       
   197             context().deployParams.setJreInstaller(true);
       
   198         }),
   173         }),
   199 
   174 
   200         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
   175         INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
   201             context().input = popArg();
   176             context().input = popArg();
   202             setOptionValue("input", context().input);
   177             setOptionValue("input", context().input);
   209 
   184 
   210         DESCRIPTION ("description", "d", OptionCategories.PROPERTY),
   185         DESCRIPTION ("description", "d", OptionCategories.PROPERTY),
   211 
   186 
   212         VENDOR ("vendor", OptionCategories.PROPERTY),
   187         VENDOR ("vendor", OptionCategories.PROPERTY),
   213 
   188 
   214         APPCLASS ("class", "c", OptionCategories.PROPERTY, () -> {
   189         APPCLASS ("main-class", "c", OptionCategories.PROPERTY, () -> {
   215             context().hasMainClass = true;
   190             context().hasMainClass = true;
   216             setOptionValue("class", popArg());
   191             setOptionValue("main-class", popArg());
   217         }),
   192         }),
   218 
   193 
   219         NAME ("name", "n", OptionCategories.PROPERTY),
   194         NAME ("name", "n", OptionCategories.PROPERTY),
   220 
   195 
   221         IDENTIFIER ("identifier", OptionCategories.PROPERTY),
   196         IDENTIFIER ("identifier", OptionCategories.PROPERTY),
   223         VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
   198         VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
   224             setOptionValue("verbose", true);
   199             setOptionValue("verbose", true);
   225             Log.setVerbose(true);
   200             Log.setVerbose(true);
   226         }),
   201         }),
   227 
   202 
   228         FORCE ("force", OptionCategories.PROPERTY, () -> {
   203         OVERWRITE ("overwrite", OptionCategories.PROPERTY, () -> {
   229             setOptionValue("force", true);
   204             setOptionValue("overwrite", true);
   230         }),
   205         }),
   231 
   206 
   232         RESOURCE_DIR("resource-dir",
   207         RESOURCE_DIR("resource-dir",
   233                 OptionCategories.PROPERTY, () -> {
   208                 OptionCategories.PROPERTY, () -> {
   234             String resourceDir = popArg();
   209             String resourceDir = popArg();
   335         }),
   310         }),
   336 
   311 
   337         ADD_MODULES ("add-modules", OptionCategories.MODULAR),
   312         ADD_MODULES ("add-modules", OptionCategories.MODULAR),
   338 
   313 
   339         MODULE_PATH ("module-path", "p", OptionCategories.MODULAR),
   314         MODULE_PATH ("module-path", "p", OptionCategories.MODULAR),
   340 
       
   341         LIMIT_MODULES ("limit-modules", OptionCategories.MODULAR),
       
   342 
   315 
   343         MAC_SIGN ("mac-sign", "s", OptionCategories.PLATFORM_MAC, () -> {
   316         MAC_SIGN ("mac-sign", "s", OptionCategories.PLATFORM_MAC, () -> {
   344             setOptionValue("mac-sign", true);
   317             setOptionValue("mac-sign", true);
   345         }),
   318         }),
   346 
   319 
   569                             args.add(qsplit[i]);
   542                             args.add(qsplit[i]);
   570                         }
   543                         }
   571                     }
   544                     }
   572                 }
   545                 }
   573             } else {
   546             } else {
   574                Log.error("Can not find argument file: " + f);
   547                 Log.info(MessageFormat.format(I18N.getString(
       
   548                         "warning.missing.arg.file"), f));
   575             }
   549             }
   576         } catch (IOException ioe) {
   550         } catch (IOException ioe) {
   577             Log.verbose(ioe.getMessage());
   551             Log.verbose(ioe.getMessage());
   578             Log.verbose(ioe);
   552             Log.verbose(ioe);
   579         }
   553         }
   601                 }
   575                 }
   602             }
   576             }
   603 
   577 
   604             if (allOptions.isEmpty() || !allOptions.get(0).isMode()) {
   578             if (allOptions.isEmpty() || !allOptions.get(0).isMode()) {
   605                 // first argument should always be a mode.
   579                 // first argument should always be a mode.
   606                 Log.error("ERROR: Mode is not specified");
   580                 throw new PackagerException("ERR_MissingMode");
   607                 return false;
   581             }
   608             }
   582 
   609 
   583             if (hasMainJar && !hasMainClass) {
   610             if (!hasAppImage && !hasMainJar && !hasMainModule &&
       
   611                     !hasMainClass && !jreInstaller) {
       
   612                 Log.error("ERROR: Main jar, main class, main module, "
       
   613                         + "or app-image must be specified.");
       
   614             } else if (!hasMainModule && !hasMainClass) {
       
   615                 // try to get main-class from manifest
   584                 // try to get main-class from manifest
   616                 String mainClass = getMainClassFromManifest();
   585                 String mainClass = getMainClassFromManifest();
   617                 if (mainClass != null) {
   586                 if (mainClass != null) {
   618                     CLIOptions.setOptionValue(
   587                     CLIOptions.setOptionValue(
   619                             CLIOptions.APPCLASS.getId(), mainClass);
   588                             CLIOptions.APPCLASS.getId(), mainClass);
   664                         throw new PackagerException("ERR_NoUniqueName");
   633                         throw new PackagerException("ERR_NoUniqueName");
   665                     }
   634                     }
   666                 }
   635                 }
   667                 usedNames.add(slName);
   636                 usedNames.add(slName);
   668             }
   637             }
   669             if (jreInstaller && bp.getName() == null) {
   638             if (runtimeInstaller && bp.getName() == null) {
   670                 throw new PackagerException("ERR_NoJreInstallerName");
   639                 throw new PackagerException("ERR_NoJreInstallerName");
   671             }
   640             }
   672 
   641 
   673             return generateBundle(bp.getBundleParamsAsMap());
   642             return generateBundle(bp.getBundleParamsAsMap());
   674         } catch (Exception e) {
   643         } catch (Exception e) {
   707             if (hasTargetFormat && deployParams.getTargetFormat() != null &&
   676             if (hasTargetFormat && deployParams.getTargetFormat() != null &&
   708                     !deployParams.getTargetFormat().equalsIgnoreCase(
   677                     !deployParams.getTargetFormat().equalsIgnoreCase(
   709                     bundler.getID())) {
   678                     bundler.getID())) {
   710                 continue;
   679                 continue;
   711             }
   680             }
   712             if (bundler.supported()) {
   681             if (bundler.supported(runtimeInstaller)) {
   713                  platformBundlers.add(bundler);
   682                  platformBundlers.add(bundler);
   714             }
   683             }
   715         }
   684         }
   716 
   685 
   717         return platformBundlers;
   686         return platformBundlers;
   936             }
   905             }
   937         } catch (IOException ignore) {}
   906         } catch (IOException ignore) {}
   938         return null;
   907         return null;
   939     }
   908     }
   940 
   909 
   941     static boolean isJreInstaller() {
       
   942         return jreInstaller;
       
   943     }
       
   944 }
   910 }