8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher JDK-8200758-branch
authorherrick
Mon, 11 Mar 2019 21:04:21 -0400
branchJDK-8200758-branch
changeset 57259 a84c657c713d
parent 57258 ea75e8d7e34f
child 57261 13b6672477df
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher Reviewed-by: almatvee
src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java
src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java
src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java	Mon Mar 11 21:00:22 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java	Mon Mar 11 21:04:21 2019 -0400
@@ -193,9 +193,8 @@
         List<Map<String, ? super Object>> entryPoints
                 = StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params);
         for (Map<String, ? super Object> entryPoint : entryPoints) {
-            Map<String, ? super Object> tmp = new HashMap<>(originalParams);
-            tmp.putAll(entryPoint);
-            createLauncherForEntryPoint(tmp, root);
+            createLauncherForEntryPoint(
+                    AddLauncherArguments.merge(originalParams, entryPoint));
         }
 
         // Copy class path entries to Java folder
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Mon Mar 11 21:00:22 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java	Mon Mar 11 21:04:21 2019 -0400
@@ -323,8 +323,8 @@
         List<Map<String, ? super Object>> entryPoints =
                 StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params);
         for (Map<String, ? super Object> entryPoint : entryPoints) {
-            Map<String, ? super Object> tmp = new HashMap<>(originalParams);
-            tmp.putAll(entryPoint);
+            Map<String, ? super Object> tmp = 
+                    AddLauncherArguments.merge(originalParams, entryPoint);
 
             // add executable for add launcher
             Path addExecutable = macOSDir.resolve(getLauncherName(tmp));
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java	Mon Mar 11 21:00:22 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java	Mon Mar 11 21:04:21 2019 -0400
@@ -164,4 +164,22 @@
             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");
+            // should we only remove add-modules when it wasn't actually passed
+            // but was inferred or empty ?
+            tmp.remove("add-modules");
+        }
+        tmp.putAll(additional);
+        return tmp;
+    }
+
 }
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java	Mon Mar 11 21:00:22 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java	Mon Mar 11 21:04:21 2019 -0400
@@ -254,9 +254,8 @@
         List<Map<String, ? super Object>> entryPoints =
                 StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params);
         for (Map<String, ? super Object> entryPoint : entryPoints) {
-            Map<String, ? super Object> tmp = new HashMap<>(originalParams);
-            tmp.putAll(entryPoint);
-            createLauncherForEntryPoint(tmp);
+            createLauncherForEntryPoint(
+                    AddLauncherArguments.merge(originalParams, entryPoint));
         }
     }