8222406: Multiple arguments for the same option - aggragation broken JDK-8200758-branch
authorherrick
Sat, 13 Apr 2019 07:47:23 -0400
branchJDK-8200758-branch
changeset 57324 c1d3935fbb79
parent 57323 66c1dbc008c5
child 57325 e678ef92ef0b
8222406: Multiple arguments for the same option - aggragation broken Reviewed-by: almatvee
src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java
test/jdk/tools/jpackage/apps/com.other/com/other/Other.java
test/jdk/tools/jpackage/apps/com.other/module-info.java
test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageAddModulesTest.java
test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModulePathTest.java
test/jdk/tools/jpackage/helpers/JPackageHelper.java
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java	Fri Apr 12 10:54:10 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java	Sat Apr 13 07:47:23 2019 -0400
@@ -465,7 +465,14 @@
         if (multi_args.contains(key)) {
             Object existingValue = bundlerArguments.get(key);
             if (existingValue instanceof String && value instanceof String) {
-                bundlerArguments.put(key, existingValue + "\n\n" + value);
+                String delim = "\n\n";
+                if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
+                    delim = File.pathSeparator;
+                } else if (key.equals(
+                        StandardBundlerParam.ADD_MODULES.getID())) {
+                    delim = ",";
+                }
+                bundlerArguments.put(key, existingValue + delim + value);
             } else if (existingValue instanceof List && value instanceof List) {
                 ((List)existingValue).addAll((List)value);
             } else if (existingValue instanceof Map &&
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/apps/com.other/com/other/Other.java	Sat Apr 13 07:47:23 2019 -0400
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.other;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+public class Other {
+
+    private static final String MSG = "other jpackage test application";
+    private static final int EXPECTED_NUM_OF_PARAMS = 3; // Starts at 1
+
+    public static void main(String[] args) {
+        String outputFile = "appOutput.txt";
+        File file = new File(outputFile);
+
+        try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
+            System.out.println(MSG);
+            out.println(MSG);
+
+            System.out.println("args.length: " + args.length);
+            out.println("args.length: " + args.length);
+
+            for (String arg : args) {
+                System.out.println(arg);
+                out.println(arg);
+            }
+
+            for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) {
+                String value = System.getProperty("param" + index);
+                if (value != null) {
+                    System.out.println("-Dparam" + index + "=" + value);
+                    out.println("-Dparam" + index + "=" + value);
+                }
+            }
+        } catch (Exception ex) {
+            System.err.println(ex.toString());
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/apps/com.other/module-info.java	Sat Apr 13 07:47:23 2019 -0400
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+module com.other {
+    exports com.other;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageAddModulesTest.java	Sat Apr 13 07:47:23 2019 -0400
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /*
+ * @test
+ * @summary jpackage create image module test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageAddModulesTest
+ */
+public class JPackageCreateAppImageAddModulesTest {
+    private static final String OUTPUT = "output";
+
+    private static final String [] CMD1 = {
+        "create-app-image",
+        "--output", OUTPUT,
+        "--name", "test",
+        "--module", "com.hello/com.hello.Hello",
+        "--module-path", "input",
+        "--add-modules", "java.desktop",
+    };
+
+    private static final String [] CMD2 = {
+        "create-app-image",
+        "--output", OUTPUT,
+        "--name", "test",
+        "--module", "com.hello/com.hello.Hello",
+        "--module-path", "input",
+        "--add-modules", "java.desktop,java.xml",
+    };
+
+    private static final String [] CMD3 = {
+        "create-app-image",
+        "--output", OUTPUT,
+        "--name", "test",
+        "--module", "com.hello/com.hello.Hello",
+        "--module-path", "input",
+        "--add-modules", "java.desktop",
+        "--add-modules", "java.xml",
+    };
+
+    public static void main(String[] args) throws Exception {
+        JPackageHelper.createHelloModule();
+        JPackageCreateAppImageBase.testCreateAppImage(CMD1);
+        JPackageHelper.deleteOutputFolder(OUTPUT);
+        JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD1);
+        JPackageHelper.deleteOutputFolder(OUTPUT);
+        JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD2);
+        JPackageHelper.deleteOutputFolder(OUTPUT);
+        JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD3);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModulePathTest.java	Sat Apr 13 07:47:23 2019 -0400
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /*
+ * @test
+ * @summary jpackage create image module test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageModulePathTest
+ */
+public class JPackageCreateAppImageModulePathTest {
+    private static final String OUTPUT = "output";
+
+    private static final String [] CMD1 = {
+        "create-app-image",
+        "--output", OUTPUT,
+        "--name", "test",
+        "--module", "com.hello/com.hello.Hello",
+        "--module-path", "input",
+    };
+
+    private static final String [] CMD2 = {
+        "create-app-image",
+        "--output", OUTPUT,
+        "--name", "test",
+        "--module", "com.hello/com.hello.Hello",
+        "--module-path", "input;input-other",
+    };
+
+    private static final String [] CMD3 = {
+        "create-app-image",
+        "--output", OUTPUT,
+        "--name", "test",
+        "--module", "com.hello/com.hello.Hello",
+        "--module-path", "input",
+        "--module-path", "input-other",
+    };
+
+    public static void main(String[] args) throws Exception {
+        JPackageHelper.createHelloModule();
+        JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD1);
+        JPackageHelper.deleteOutputFolder(OUTPUT);
+        JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD2);
+        JPackageHelper.deleteOutputFolder(OUTPUT);
+        JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD3);
+    }
+
+}
--- a/test/jdk/tools/jpackage/helpers/JPackageHelper.java	Fri Apr 12 10:54:10 2019 -0400
+++ b/test/jdk/tools/jpackage/helpers/JPackageHelper.java	Sat Apr 13 07:47:23 2019 -0400
@@ -347,19 +347,23 @@
     }
 
     public static void createHelloModule() throws Exception {
-        createModule("Hello.java");
+        createModule("Hello.java", "input", "hello");
     }
 
-    private static void createModule(String javaFile)
-            throws Exception {
+    public static void createOtherModule() throws Exception {
+        createModule("Other.java", "input-other", "other");
+    }
+
+    private static void createModule(String javaFile, String inputDir,
+            String aName) throws Exception {
         int retVal;
 
-        File input = new File("input");
+        File input = new File(inputDir);
         if (!input.exists()) {
             input.mkdir();
         }
 
-        File module = new File("module" + File.separator + "com.hello");
+        File module = new File("module" + File.separator + "com." + aName);
         if (!module.exists()) {
             module.mkdirs();
         }
@@ -369,12 +373,12 @@
             List<String> args = new ArrayList<>();
             args.add(JAVAC.toString());
             args.add("-d");
-            args.add("module" + File.separator + "com.hello");
-            args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator + "com.hello"
-                    + File.separator + "module-info.java");
-            args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator + "com.hello"
-                    + File.separator + "com" + File.separator + "hello" + File.separator
-                    + javaFile);
+            args.add("module" + File.separator + "com." + aName);
+            args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator
+                    + "com." + aName + File.separator + "module-info.java");
+            args.add(TEST_SRC_ROOT + File.separator + "apps"
+                    + File.separator + "com." + aName + File.separator + "com"
+                    + File.separator + aName + File.separator + javaFile);
             retVal = execute(javacLog, args.stream().toArray(String[]::new));
         } catch (Exception ex) {
             if (javacLog.exists()) {
@@ -396,9 +400,9 @@
             args.add(JAR.toString());
             args.add("--create");
             args.add("--file");
-            args.add("input" + File.separator + "com.hello.jar");
+            args.add(inputDir + File.separator + "com." + aName + ".jar");
             args.add("-C");
-            args.add("module" + File.separator + "com.hello");
+            args.add("module" + File.separator + "com." + aName);
             args.add(".");
 
             retVal = execute(jarLog, args.stream().toArray(String[]::new));