< prev index next >
src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
Print this page
@@ -72,29 +72,25 @@
private static final String FA_DESCRIPTION = "description";
private static final String FA_ICON = "icon";
public static final BundlerParamInfo<Boolean> CREATE_IMAGE =
new StandardBundlerParam<>(
- I18N.getString("param.create-image.name"),
- I18N.getString("param.create-image.description"),
IMAGE_MODE,
Boolean.class,
p -> Boolean.FALSE,
(s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
true : Boolean.valueOf(s));
public static final BundlerParamInfo<Boolean> CREATE_INSTALLER =
new StandardBundlerParam<>(
- I18N.getString("param.create-installer.name"),
- I18N.getString("param.create-installer.description"),
INSTALLER_MODE,
Boolean.class,
p -> Boolean.FALSE,
(s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
true : Boolean.valueOf(s));
- // regexp for parsing args (for example, for secondary launchers)
+ // regexp for parsing args (for example, for additional launchers)
private static Pattern pattern = Pattern.compile(
"(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
private DeployParams deployParams = null;
private BundlerType bundleType = null;
@@ -121,11 +117,11 @@
private static boolean runtimeInstaller = false;
private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
- private List<SecondaryLauncherArguments> secondaryLaunchers = null;
+ private List<AddLauncherArguments> addLaunchers = null;
private static Map<String, CLIOptions> argIds = new HashMap<>();
private static Map<String, CLIOptions> argShortIds = new HashMap<>();
{
@@ -157,16 +153,10 @@
context().bundleType = BundlerType.INSTALLER;
String format = "installer";
context().deployParams.setTargetFormat(format);
}),
- RUNTIME_INSTALLER("runtime-installer",
- OptionCategories.PROPERTY, () -> {
- runtimeInstaller = true;
- setOptionValue("runtime-installer", true);
- }),
-
INSTALLER_TYPE("installer-type", OptionCategories.PROPERTY, () -> {
String type = popArg();
if (BundlerType.INSTALLER.equals(context().bundleType)) {
context().deployParams.setTargetFormat(type);
context().hasTargetFormat = true;
@@ -186,11 +176,11 @@
DESCRIPTION ("description", "d", OptionCategories.PROPERTY),
VENDOR ("vendor", OptionCategories.PROPERTY),
- APPCLASS ("main-class", "c", OptionCategories.PROPERTY, () -> {
+ APPCLASS ("main-class", OptionCategories.PROPERTY, () -> {
context().hasMainClass = true;
setOptionValue("main-class", popArg());
}),
NAME ("name", "n", OptionCategories.PROPERTY),
@@ -200,14 +190,10 @@
VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
setOptionValue("verbose", true);
Log.setVerbose(true);
}),
- OVERWRITE ("overwrite", OptionCategories.PROPERTY, () -> {
- setOptionValue("overwrite", true);
- }),
-
RESOURCE_DIR("resource-dir",
OptionCategories.PROPERTY, () -> {
String resourceDir = popArg();
setOptionValue("resource-dir", resourceDir);
}),
@@ -217,20 +203,15 @@
String files = popArg();
context().files.addAll(
Arrays.asList(files.split(File.pathSeparator)));
}),
- ARGUMENTS ("arguments", "a", OptionCategories.PROPERTY, () -> {
+ ARGUMENTS ("arguments", OptionCategories.PROPERTY, () -> {
List<String> arguments = getArgumentList(popArg());
setOptionValue("arguments", arguments);
}),
- STRIP_NATIVE_COMMANDS ("strip-native-commands",
- OptionCategories.PROPERTY, () -> {
- setOptionValue("strip-native-commands", true);
- }),
-
ICON ("icon", OptionCategories.PROPERTY),
CATEGORY ("category", OptionCategories.PROPERTY),
COPYRIGHT ("copyright", OptionCategories.PROPERTY),
LICENSE_FILE ("license-file", OptionCategories.PROPERTY),
@@ -277,20 +258,20 @@
// check that we really add _another_ value to the list
setOptionValue("file-associations", associationList);
}),
- SECONDARY_LAUNCHER ("secondary-launcher",
+ ADD_LAUNCHER ("add-launcher",
OptionCategories.PROPERTY, () -> {
- context().secondaryLaunchers.add(
- new SecondaryLauncherArguments(popArg()));
+ context().addLaunchers.add(
+ new AddLauncherArguments(popArg()));
}),
- BUILD_ROOT ("build-root", OptionCategories.PROPERTY, () -> {
+ TEMP_ROOT ("temp-root", OptionCategories.PROPERTY, () -> {
context().buildRoot = popArg();
context().userProvidedBuildRoot = true;
- setOptionValue("build-root", context().buildRoot);
+ setOptionValue("temp-root", context().buildRoot);
}),
INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
@@ -298,11 +279,11 @@
context().hasAppImage = true;
}),
PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
- MAIN_JAR ("main-jar", "j", OptionCategories.PROPERTY, () -> {
+ MAIN_JAR ("main-jar", OptionCategories.PROPERTY, () -> {
context().mainJarPath = popArg();
context().hasMainJar = true;
setOptionValue("main-jar", context().mainJarPath);
}),
@@ -502,11 +483,11 @@
deployParams = new DeployParams();
bundleType = BundlerType.NONE;
allOptions = new ArrayList<>();
- secondaryLaunchers = new ArrayList<>();
+ addLaunchers = new ArrayList<>();
}
public boolean processArguments() throws Exception {
try {
@@ -551,16 +532,16 @@
deployParams.setBundleType(bundleType);
List<Map<String, ? super Object>> launchersAsMap =
new ArrayList<>();
- for (SecondaryLauncherArguments sl : secondaryLaunchers) {
+ for (AddLauncherArguments sl : addLaunchers) {
launchersAsMap.add(sl.getLauncherMap());
}
deployParams.addBundleArgument(
- StandardBundlerParam.SECONDARY_LAUNCHERS.getID(),
+ StandardBundlerParam.ADD_LAUNCHERS.getID(),
launchersAsMap);
// at this point deployParams should be already configured
deployParams.validate();
@@ -569,18 +550,18 @@
// validate name(s)
ArrayList<String> usedNames = new ArrayList<String>();
usedNames.add(bp.getName()); // add main app name
- for (SecondaryLauncherArguments sl : secondaryLaunchers) {
+ for (AddLauncherArguments sl : addLaunchers) {
Map<String, ? super Object> slMap = sl.getLauncherMap();
String slName =
(String) slMap.get(Arguments.CLIOptions.NAME.getId());
if (slName == null) {
- throw new PackagerException("ERR_NoSecondaryLauncherName");
+ throw new PackagerException("ERR_NoAddLauncherName");
}
- // same rules apply to secondary launcher names as app name
+ // same rules apply to additional launcher names as app name
DeployParams.validateName(slName, false);
for (String usedName : usedNames) {
if (slName.equals(usedName)) {
throw new PackagerException("ERR_NoUniqueName");
}
@@ -603,21 +584,46 @@
return false;
}
}
}
- private void validateArguments() {
+ private void validateArguments() throws PackagerException {
CLIOptions mode = allOptions.get(0);
+ boolean imageOnly = (mode == CLIOptions.CREATE_IMAGE);
+ boolean hasModule = allOptions.contains(CLIOptions.MODULE);
+ boolean hasMainJar = allOptions.contains(CLIOptions.MAIN_JAR);
+ boolean hasAppImage = allOptions.contains(
+ CLIOptions.PREDEFINED_APP_IMAGE);
+ boolean hasRuntime = allOptions.contains(
+ CLIOptions.PREDEFINED_RUNTIME_IMAGE);
+ boolean installerOnly = !imageOnly && hasAppImage;
+ boolean runtimeInstall = !imageOnly && hasRuntime && !hasAppImage &&
+ !hasModule && !hasMainJar;
+
for (CLIOptions option : allOptions) {
- if(!ValidOptions.checkIfSupported(mode, option)) {
- String key = "warning.unsupported.option";
- if (ValidOptions.checkIfOtherSupported(mode, option)) {
- key = "warning.unsupported.mode.option";
+ if (!ValidOptions.checkIfSupported(option)) {
+ // includes option valid only on different platform
+ throw new PackagerException("ERR_UnsupportedOption",
+ option.getIdWithPrefix());
+ }
+ if (imageOnly) {
+ if (!ValidOptions.checkIfImageSupported(option)) {
+ throw new PackagerException("ERR_NotImageOption",
+ option.getIdWithPrefix());
+ }
+ } else if (installerOnly || runtimeInstall) {
+ if (!ValidOptions.checkIfInstallerSupported(option)) {
+ String key = runtimeInstaller ?
+ "ERR_NoEntryPoint" : "ERR_NotInstallerOption";
+ throw new PackagerException(key, option.getIdWithPrefix());
+ }
}
- Log.info(MessageFormat.format(I18N.getString(key),
- option.getId(), mode));
}
+ if (installerOnly && hasRuntime) {
+ // note --runtime-image is only for image or runtime installer.
+ throw new PackagerException("ERR_NotInstallerOption",
+ CLIOptions.PREDEFINED_RUNTIME_IMAGE.getIdWithPrefix());
}
}
private List<jdk.jpackage.internal.Bundler> getPlatformBundlers() {
@@ -645,17 +651,17 @@
private boolean generateBundle(Map<String,? super Object> params)
throws PackagerException {
boolean bundleCreated = false;
- // the build-root needs to be fetched from the params early,
+ // the temp-root needs to be fetched from the params early,
// to prevent each copy of the params (such as may be used for
- // secondary launchers) from generating a separate build-root when
+ // additional launchers) from generating a separate temp-root when
// the default is used (the default is a new temp directory)
// The bundler.cleanup() below would not otherwise be able to
// clean these extra (and unneeded) temp directories.
- StandardBundlerParam.BUILD_ROOT.fetchFrom(params);
+ StandardBundlerParam.TEMP_ROOT.fetchFrom(params);
for (jdk.jpackage.internal.Bundler bundler : getPlatformBundlers()) {
Map<String, ? super Object> localParams = new HashMap<>(params);
try {
if (bundler.validate(localParams)) {
< prev index next >