8208578: Need to improve error handling of mandatory arguments JDK-8200758-branch
authorherrick
Thu, 11 Oct 2018 20:53:02 -0400
branchJDK-8200758-branch
changeset 56958 8880b21d458d
parent 56957 2f01969ed7cb
child 56959 973e113ced9a
8208578: Need to improve error handling of mandatory arguments Reviewed-by: almatvee
src/jdk.packager/share/classes/jdk/packager/internal/Arguments.java
src/jdk.packager/share/classes/jdk/packager/internal/resources/Arguments.properties
src/jdk.packager/share/classes/jdk/packager/internal/resources/Bundle.properties
--- a/src/jdk.packager/share/classes/jdk/packager/internal/Arguments.java	Thu Oct 11 20:48:26 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/Arguments.java	Thu Oct 11 20:53:02 2018 -0400
@@ -578,6 +578,29 @@
 
             BundleParams bp = deployParams.getBundleParams();
 
+            // validate name(s)
+            ArrayList<String> usedNames = new ArrayList<String>();
+            usedNames.add(bp.getName()); // add main app name
+
+            for (SecondaryLauncherArguments sl : secondaryLaunchers) {
+                Map<String, ? super Object> slMap = sl.getLauncherMap();
+                String slName = 
+                        (String) slMap.get(Arguments.CLIOptions.NAME.getId());
+                if (slName == null) {
+                    throw new PackagerException("ERR_NoSecondaryLauncherName");
+                } else {
+                    for (String usedName : usedNames) {
+                        if (slName.equals(usedName)) {
+                            throw new PackagerException("ERR_NoUniqueName");
+                        }
+                    }
+                }
+                usedNames.add(slName);
+            }
+            if (jreInstaller && bp.getName() == null) {
+                throw new PackagerException("ERR_NoJreInstallerName");
+            }
+
             generateBundle(bp.getBundleParamsAsMap());
         } catch (Exception e) {
             if (verbose) {
--- a/src/jdk.packager/share/classes/jdk/packager/internal/resources/Arguments.properties	Thu Oct 11 20:48:26 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/resources/Arguments.properties	Thu Oct 11 20:53:02 2018 -0400
@@ -1,29 +1,3 @@
-ERR_UnknownArgument=Error: Unknown argument: {0}
-ERR_UnknownCommand=Error: Unknown command: {0}
-ERR_UnknownReason=Unknown reason
-ERR_MissingArgument=Error: Missing argument: {0}
-ERR_EmbedingLauncher=Error: Missing embedded resource [{0}]
-ERR_ContradictorySetting=Error: Ant script manifest argument ''{0}'' contradicts Ant script data type settings.
-ERR_CreatingDirFailed=Error: Failed to create directory {0}
-ERR_CreatingFileFailed=Error: Failed to create file {0}
-ERR_CreatingTempFileFailed=Error: Failed to create temporary file
-ERR_CreatingJarFailed=Error: Failed to create jar file {0}
-ERR_FileCopyFailed=Error: Failed copy file to directory {0}
-ERR_FileReadFailed=Error: Failed reading file {0}
-ERR_CantDeleteFile=Error: File {0} could not be deleted.
-ERR_MissingDirectory=Missing directory {0}
-ERR_InvalidDirectory=Invalid directory {0}
-ERR_EmptySourceDirectory=Empty source directory {0}
-ERR_MissingJavaHome=Error: Java home directory is not known.
-ERR_MissingJavaFxHome=Error: JavaFx home directory is not known.
-ERR_JavacFailed=Error: javac execution failed, exit code: {0}
-ERR_MakeAllJavacFailed=Error: compilation of java sources failed
-ERR_DeployFailed=Error: deploy failed
-ERR_InvalidStoreFile=Error: Invalid keystore file: {0}
-ERR_SignFailed=Error: Signing failed
-ERR_MissingAppResources=Error: No application jars found
-ERR_NoEmbeddedDT=Error: -includedt requires the java deployment toolkit, which is not included in this distribution
-
 param.create-image.name=Create Image
 param.create-image.description=Creates platform-specific application image.
 
@@ -33,18 +7,9 @@
 param.create-jre-installer.name=Create JRE Installer
 param.create-jre-installer.description=Creates platform-specific JRE installer.
 
-MSG_UpdatingJar=Updating jar file\: {0}
-MSG_DeprecatedArg=Warning: {0} has been deprecated and will be removed in a future release.
-MSG_DeprecatedMode=Warning: Mode {0} has been deprecated and will be removed in a future release.
-MSG_NoJREPackaged=Package is configured to ship without a JRE.
-MSG_UserProvidedJRE=Using base JDK at\: {0}
-MSG_UseSystemJRE=No base JDK. Package will use system JRE.
 MSG_BundlerFailed=Error: Bundler "{1}" ({0}) failed to produce a bundle.
 MSG_BundlerPlatformException=Bundler {0} skipped because the bundler does not support bundling on this platform.
 MSG_BundlerConfigException=Bundler {0} skipped because of a configuration problem\: {1}  \n\
 Advice to fix\: {2}
 MSG_BundlerConfigExceptionNoAdvice=Bundler {0} skipped because of a configuration problem\: {1}
 MSG_BundlerRuntimeException=Bundler {0} failed because of {1}
-MSG_JarNoSelfCopy=Skip jar copy to itself\: {0}
-MSG_EnterKeystorePassword=Enter Passphrase for keystore:
-MSG_EnterKeyPassword=Enter key password for %s:
--- a/src/jdk.packager/share/classes/jdk/packager/internal/resources/Bundle.properties	Thu Oct 11 20:48:26 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/resources/Bundle.properties	Thu Oct 11 20:53:02 2018 -0400
@@ -26,6 +26,9 @@
 ERR_NoEmbeddedDT=Error: -includedt requires the java deployment toolkit, which is not included in this distribution
 ERR_AppImageNotExist=Error: App image directory "{0}" does not exist
 ERR_AppImageInvalid=Error: App image directory "{0}" is invalid and does not contain "app" and/or "runtime" sub-directories
+ERR_NoSecondaryLauncherName=Secondary Launchers require a name parameter.
+ERR_NoUniqueName=Secondary Launchers require a unique name parameter.
+ERR_NoJreInstallerName=Jre Installers require a name parameter.
 
 MSG_UpdatingJar=Updating jar file\: {0}
 MSG_NoJREPackaged=Package is configured to ship without a JRE.