8213333: Fix issues found in jpackager with automated tests JDK-8200758-branch
authorherrick
Thu, 08 Nov 2018 13:56:26 -0500
branchJDK-8200758-branch
changeset 57022 81021f910bc2
parent 57021 441c020bf626
child 57023 8bf89434f0a5
8213333: Fix issues found in jpackager with automated tests Submitten-by: almatvee Reviewed-by: herrick. kcr
src/jdk.jpackager/share/classes/jdk/jpackager/internal/Arguments.java
src/jdk.jpackager/share/classes/jdk/jpackager/internal/CLIHelp.java
src/jdk.jpackager/share/classes/jdk/jpackager/internal/DeployParams.java
src/jdk.jpackager/share/classes/jdk/jpackager/internal/JPackagerToolProvider.java
src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelp.properties
src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelpi_ja.properties
src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelpi_zh_CN.properties
src/jdk.jpackager/share/classes/jdk/jpackager/main/Main.java
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/Arguments.java	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/Arguments.java	Thu Nov 08 13:56:26 2018 -0500
@@ -616,11 +616,11 @@
             if (Log.isVerbose()) {
                 throw e;
             } else {
-                System.err.println(e.getMessage());
+                Log.error(e.getMessage());
                 if (e.getCause() != null && e.getCause() != e) {
-                    System.err.println(e.getCause().getMessage());
+                    Log.error(e.getCause().getMessage());
                 }
-                System.exit(-1);
+                return false;
             }
         }
         return true;
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/CLIHelp.java	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/CLIHelp.java	Thu Nov 08 13:56:26 2018 -0500
@@ -38,33 +38,25 @@
             "jdk.jpackager.internal.resources.CLIHelp");
 
     // generates --help for jpackager's CLI
-    public static void showHelp(boolean all) {
-        
+    public static void showHelp(boolean noArgs) {
+
         Platform platform = Platform.getPlatform();
-        Log.info(I18N.getString("MSG_Help_common"));
+        if (noArgs) {
+            Log.info(I18N.getString("MSG_Help_no_args"));
+        } else {
+            Log.info(I18N.getString("MSG_Help_common"));
 
-        switch (platform) {
-            case MAC:
-                Log.info(I18N.getString("MSG_Help_mac"));
-                if (all) {
-                    Log.info(I18N.getString("MSG_Help_win"));
-                    Log.info(I18N.getString("MSG_Help_linux"));
-                }
-                break;
-            case LINUX:
-                Log.info(I18N.getString("MSG_Help_linux"));
-                if (all) {
-                    Log.info(I18N.getString("MSG_Help_win"));
+            switch (platform) {
+                case MAC:
                     Log.info(I18N.getString("MSG_Help_mac"));
-                }
-                break;
-            case WINDOWS:
-                Log.info(I18N.getString("MSG_Help_win"));
-                if (all) {
-                    Log.info(I18N.getString("MSG_Help_linux"));
-                    Log.info(I18N.getString("MSG_Help_mac"));
-                }
-                break;
+                    break;
+                case LINUX:
+                     Log.info(I18N.getString("MSG_Help_linux"));
+                    break;
+                case WINDOWS:
+                     Log.info(I18N.getString("MSG_Help_win"));
+                    break;
+            }
         }
     }
 }
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/DeployParams.java	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/DeployParams.java	Thu Nov 08 13:56:26 2018 -0500
@@ -341,6 +341,22 @@
             throw new PackagerException("ERR_MissingArgument", "--output");
         }
 
+        if (getBundleType() == BundlerType.IMAGE) {
+            String input = (String)bundlerArguments.get(Arguments.CLIOptions.INPUT.getId());
+            if (input == null) {
+                throw new PackagerException("ERR_MissingArgument", "--input");
+            }
+        } else if (getBundleType() == BundlerType.INSTALLER) {
+            if (!Arguments.isJreInstaller()) {
+                String input = (String)bundlerArguments.get(Arguments.CLIOptions.INPUT.getId());
+                String appImage = (String)bundlerArguments.get(
+                    Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
+                if (input == null && appImage == null) {
+                    throw new PackagerException("ERR_MissingArgument", "--input or --app-image");
+                }
+            }
+        }
+
         boolean hasModule = (bundlerArguments.get(
                 Arguments.CLIOptions.MODULE.getId()) != null);
         boolean hasImage = (bundlerArguments.get(
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/JPackagerToolProvider.java	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/JPackagerToolProvider.java	Thu Nov 08 13:56:26 2018 -0500
@@ -43,10 +43,9 @@
     public synchronized int run(
             PrintWriter out, PrintWriter err, String... args) {
         try {
-            jdk.jpackager.main.Main.run(out, err, args);
+            return jdk.jpackager.main.Main.run(out, err, args);
         } catch (Exception ignored) {
-            return 1;
+            return -1;
         }
-        return 0;
     }
 }
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelp.properties	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelp.properties	Thu Nov 08 13:56:26 2018 -0500
@@ -66,7 +66,7 @@
 \          Name of the base directory that contains the files to package.\n\
 \  --files -f <input files>\n\
 \          List of files in the base directory. If omitted, all files from "input"\n\
-\          directory (which is a mandatory argument in this case) will be packaged.\n\
+\          directory will be packaged.\n\
 \  --name -n <application name>\n\
 \          Name of the application.\n\
 \  --main-jar -j <main jar name>\n\
@@ -189,3 +189,6 @@
 \  --win-console\n\
 \          Creates a console launcher for the application. Should be specified for\n\
 \          application which requires console interactions.\n\
+
+MSG_Help_no_args=Usage: jpackager <mode> <options>\n\
+\Use --help for a list of possible options\
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelpi_ja.properties	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelpi_ja.properties	Thu Nov 08 13:56:26 2018 -0500
@@ -66,7 +66,7 @@
 \          Name of the base directory that contains the files to package.\n\
 \  --files -f <input files>\n\
 \          List of files in the base directory. If omitted, all files from "input"\n\
-\          directory (which is a mandatory argument in this case) will be packaged.\n\
+\          directory will be packaged.\n\
 \  --name -n <application name>\n\
 \          Name of the application.\n\
 \  --main-jar -j <main jar name>\n\
@@ -189,3 +189,6 @@
 \  --win-console\n\
 \          Creates a console launcher for the application. Should be specified for\n\
 \          application which requires console interactions.\n\
+
+MSG_Help_no_args=Usage: jpackager <mode> <options>\n\
+\Use --help for a list of possible options\
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelpi_zh_CN.properties	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/internal/resources/CLIHelpi_zh_CN.properties	Thu Nov 08 13:56:26 2018 -0500
@@ -66,7 +66,7 @@
 \          Name of the base directory that contains the files to package.\n\
 \  --files -f <input files>\n\
 \          List of files in the base directory. If omitted, all files from "input"\n\
-\          directory (which is a mandatory argument in this case) will be packaged.\n\
+\          directory will be packaged.\n\
 \  --name -n <application name>\n\
 \          Name of the application.\n\
 \  --main-jar -j <main jar name>\n\
@@ -189,3 +189,6 @@
 \  --win-console\n\
 \          Creates a console launcher for the application. Should be specified for\n\
 \          application which requires console interactions.\n\
+
+MSG_Help_no_args=Usage: jpackager <mode> <options>\n\
+\Use --help for a list of possible options\
--- a/src/jdk.jpackager/share/classes/jdk/jpackager/main/Main.java	Thu Nov 08 13:46:28 2018 -0500
+++ b/src/jdk.jpackager/share/classes/jdk/jpackager/main/Main.java	Thu Nov 08 13:56:26 2018 -0500
@@ -84,7 +84,10 @@
         } else {
             try {
                 Arguments arguments = new Arguments(args);
-                arguments.processArguments();
+                if (!arguments.processArguments()) { // processArguments() should log error message
+                                                     // if failed.
+                    return -1;
+                }
             } catch (Exception e) {
                 if (Log.isVerbose()) {
                     Log.verbose(e);