8230927: Wrong arguments set for additional launchers JDK-8200758-branch
authorherrick
Wed, 25 Sep 2019 17:36:28 -0400
branchJDK-8200758-branch
changeset 58346 d5a3cd78e560
parent 58345 dc4ea94feb52
child 58359 e065fd274bc1
8230927: Wrong arguments set for additional launchers Reviewed-by: asemenyuk, almatvee
src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java
test/jdk/tools/jpackage/share/AddLauncherBase.java
test/jdk/tools/jpackage/share/AddLauncherTest.java
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java	Wed Sep 25 17:21:41 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java	Wed Sep 25 17:36:28 2019 -0400
@@ -57,6 +57,7 @@
  * arguments
  * java-options
  * win-console
+ * linux-app-category
  *
  */
 class AddLauncherArguments {
@@ -117,15 +118,18 @@
         putUnlessNull(bundleParams, CLIOptions.ICON.getId(),
                 (value == null) ? null : new File(value));
 
-        String argumentStr = getOptionValue(CLIOptions.ARGUMENTS);
-        putUnlessNullOrEmpty(bundleParams,
-                CLIOptions.ARGUMENTS.getId(),
-                Arguments.getArgumentList(argumentStr));
+        // "arguments" and "java-options" even if value is null:
+        if (allArgs.containsKey(CLIOptions.ARGUMENTS.getId())) {
+            String argumentStr = getOptionValue(CLIOptions.ARGUMENTS);
+            bundleParams.put(CLIOptions.ARGUMENTS.getId(),
+                    Arguments.getArgumentList(argumentStr));
+        }
 
-        String jvmargsStr = getOptionValue(CLIOptions.JAVA_OPTIONS);
-        putUnlessNullOrEmpty(bundleParams,
-                CLIOptions.JAVA_OPTIONS.getId(),
-                Arguments.getArgumentList(jvmargsStr));
+        if (allArgs.containsKey(CLIOptions.JAVA_OPTIONS.getId())) {
+            String jvmargsStr = getOptionValue(CLIOptions.JAVA_OPTIONS);
+            bundleParams.put(CLIOptions.JAVA_OPTIONS.getId(),
+                    Arguments.getArgumentList(jvmargsStr));
+        }
     }
 
     private String getOptionValue(CLIOptions option) {
@@ -154,22 +158,24 @@
         }
     }
 
-    private void putUnlessNullOrEmpty(Map<String, ? super Object> params,
-            String param, Collection<?> value) {
-        if (value != null && !value.isEmpty()) {
-            params.put(param, value);
-        }
-    }
-
     static Map<String, ? super Object> merge(
             Map<String, ? super Object> original,
             Map<String, ? super Object> additional) {
         Map<String, ? super Object> tmp = new HashMap<>(original);
-        if (additional.containsKey("module")) {
-            tmp.remove("main-jar");
-            tmp.remove("main-class");
-        } else if (additional.containsKey("main-jar")) {
-            tmp.remove("module");
+        if (additional.containsKey(CLIOptions.MODULE.getId())) {
+            tmp.remove(CLIOptions.MAIN_JAR.getId());
+            tmp.remove(CLIOptions.APPCLASS.getId());
+        } else if (additional.containsKey(CLIOptions.MAIN_JAR.getId())) {
+            tmp.remove(CLIOptions.MODULE.getId());
+        }
+        if (additional.containsKey(CLIOptions.ARGUMENTS.getId())) {
+            // if add launcher properties file contains "arguments", even with
+            // null value, disregard the "arguments" from command line
+            tmp.remove(CLIOptions.ARGUMENTS.getId());
+        }
+        if (additional.containsKey(CLIOptions.JAVA_OPTIONS.getId())) {
+            // same thing for java-options
+            tmp.remove(CLIOptions.JAVA_OPTIONS.getId());
         }
         tmp.putAll(additional);
         return tmp;
--- a/test/jdk/tools/jpackage/share/AddLauncherBase.java	Wed Sep 25 17:21:41 2019 -0400
+++ b/test/jdk/tools/jpackage/share/AddLauncherBase.java	Wed Sep 25 17:36:28 2019 -0400
@@ -133,6 +133,27 @@
         validate(includeArgs, name);
     }
 
+    public static void testCreateAppImage(String [] cmd,
+            ArrayList<String> argList, ArrayList <String> optionList) 
+            throws Exception {
+        JPackageHelper.executeCLI(true, cmd);
+        int retVal = JPackageHelper.execute(null, app);
+        if (retVal != 0) {
+            throw new AssertionError("Test application " + app
+                    + " exited with error: " + retVal);
+        }
+        validateResult(argList, optionList);
+        String name = "test4";
+
+        String app2 = JPackagePath.getAppSL(name);
+        retVal = JPackageHelper.execute(null, app2);
+        if (retVal != 0) {
+            throw new AssertionError("Test application " + app2
+                    +  " exited with error: " + retVal);
+        }
+        validateResult(arguments, vmArguments);
+    }
+
     public static void createSLProperties() throws Exception {
         arguments.add(ARGUMENT1);
         arguments.add(ARGUMENT2);
--- a/test/jdk/tools/jpackage/share/AddLauncherTest.java	Wed Sep 25 17:21:41 2019 -0400
+++ b/test/jdk/tools/jpackage/share/AddLauncherTest.java	Wed Sep 25 17:36:28 2019 -0400
@@ -21,7 +21,9 @@
  * questions.
  */
 
- /*
+import java.util.ArrayList;
+
+/*
  * @test
  * @summary jpackage create image with additional launcher test
  * @library ../helpers
@@ -42,10 +44,40 @@
         "--main-class", "Hello",
         "--add-launcher", "test2=sl.properties"};
 
+    private final static String OPT1 = "-Dparam1=xxx";
+    private final static String OPT2 = "-Dparam2=yyy";
+    private final static String OPT3 = "-Dparam3=zzz";
+    private final static String ARG1 = "original-argument";
+
+    private static final String [] CMD1 = {
+        "--package-type", "app-image",
+        "--input", "input",
+        "--dest", OUTPUT,
+        "--name", "test",
+        "--main-jar", "hello.jar",
+        "--main-class", "Hello",
+        "--java-options", OPT1,
+        "--java-options", OPT2,
+        "--java-options", OPT3,
+        "--arguments", ARG1,
+        "--add-launcher", "test4=sl.properties"};
+
+
     public static void main(String[] args) throws Exception {
         JPackageHelper.createHelloImageJar();
         AddLauncherBase.createSLProperties();
         AddLauncherBase.testCreateAppImage(CMD);
+
+        ArrayList <String> argList = new ArrayList <String> ();
+        argList.add(ARG1);
+
+        ArrayList <String> optList = new ArrayList <String> ();
+        optList.add(OPT1);
+        optList.add(OPT2);
+        optList.add(OPT3);
+
+        JPackageHelper.deleteOutputFolder(OUTPUT);
+        AddLauncherBase.testCreateAppImage(CMD1, argList, optList);
     }
 
 }