8214021: Create additional automated tests for jpackager
Submitten-by: almatvee
Reviewed-by: herrick. kcr
--- a/test/jdk/tools/jpackager/Hello.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-
-public class Hello {
-
- private static final String MSG = "jpackager 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());
- }
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageArgumentsTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.File;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.List;
-
-/*
- * @test
- * @summary jpackager create image with --arguments test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageArgumentsTest
- */
-public class JPackagerCreateImageArgumentsTest {
-
- private static final String app;
- private static final String appOutput = "appOutput.txt";
- private static final String appOutputPath;
-
- private static final String[] CMD = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--files", "hello.jar",
- "--force",
- "--arguments", "TBD"};
-
- private static final String ARGUMENT1 = "argument";
- private static final String ARGUMENT2 = "Some Arguments";
- private static final String ARGUMENT3 = "Value \"with\" quotes";
-
- private static final String ARGUMENT_CMD1 = "test";
-
- private static final List<String> arguments = new ArrayList<>();
- private static final List<String> argumentsCmd = new ArrayList<>();
-
- static {
- if (JPackagerHelper.isWindows()) {
- app = "output" + File.separator + "test"
- + File.separator + "test.exe";
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- } else if (JPackagerHelper.isOSX()) {
- app = "output" + File.separator + "test.app"
- + File.separator + "Contents"
- + File.separator + "MacOS"
- + File.separator + "test";
- appOutputPath = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java";
- } else {
- app = "output" + File.separator + "test" + File.separator + "test";
- appOutputPath = "output"
- + File.separator + "test" + File.separator + "app";
- }
- }
-
- private static void initArguments(boolean toolProvider) {
- if (arguments.isEmpty()) {
- arguments.add(ARGUMENT1);
- arguments.add(ARGUMENT2);
- arguments.add(ARGUMENT3);
- }
-
- if (argumentsCmd.isEmpty()) {
- argumentsCmd.add(ARGUMENT_CMD1);
- }
-
- String argumentsMap =
- JPackagerHelper.listToArgumentsMap(arguments, toolProvider);
- CMD[CMD.length - 1] = argumentsMap;
- }
-
- private static void validateResult(String[] result, List<String> args)
- throws Exception {
- if (result.length != (args.size() + 2)) {
- throw new AssertionError(
- "Unexpected number of lines: " + result.length);
- }
-
- if (!result[0].trim().equals("jpackager test application")) {
- throw new AssertionError("Unexpected result[0]: " + result[0]);
- }
-
- if (!result[1].trim().equals("args.length: " + args.size())) {
- throw new AssertionError("Unexpected result[1]: " + result[1]);
- }
-
- int index = 2;
- for (String arg : args) {
- if (!result[index].trim().equals(arg)) {
- throw new AssertionError(
- "Unexpected result[" + index + "]: " + result[index]);
- }
- index++;
- }
- }
-
- private static void validate(String arg, List<String> expectedArgs)
- throws Exception {
- int retVal;
-
- if (arg == null) {
- retVal = JPackagerHelper.execute(null, app);
- } else {
- retVal = JPackagerHelper.execute(null, app, arg);
- }
- if (retVal != 0) {
- throw new AssertionError("Test application exited with error: "
- + retVal);
- }
-
- File outfile = new File(appOutputPath + File.separator + appOutput);
- if (!outfile.exists()) {
- throw new AssertionError(appOutput + " was not created");
- }
-
- String output = Files.readString(outfile.toPath());
- String[] result = output.split("\n");
- validateResult(result, expectedArgs);
- }
-
- private static void testCreateImage() throws Exception {
- initArguments(false);
- JPackagerHelper.executeCLI(true, CMD);
- validate(null, arguments);
- validate(ARGUMENT_CMD1, argumentsCmd);
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- initArguments(true);
- JPackagerHelper.executeToolProvider(true, CMD);
- validate(null, arguments);
- validate(ARGUMENT_CMD1, argumentsCmd);
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageInputFilesTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-
- /*
- * @test
- * @summary jpackager create image input/files test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageInputFilesTest
- */
-public class JPackagerCreateImageInputFilesTest {
- private static final String inputFile =
- "input" + File.separator + "input.txt";
- private static final String jarFile =
- "input" + File.separator + "input.txt";
- private static final String appOutputPath;
- private static final String appInputFilePath;
- private static final String appJarFilePath;
-
- static {
- if (JPackagerHelper.isOSX()) {
- appOutputPath = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java";
- appInputFilePath = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java"
- + File.separator + "input.txt";
- appJarFilePath = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java"
- + File.separator + "hello.jar";
- } else {
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- appInputFilePath = "output" + File.separator + "test"
- + File.separator + "app" + File.separator + "input.txt";
- appJarFilePath = "output" + File.separator + "test"
- + File.separator + "app" + File.separator + "hello.jar";
- }
- }
-
- private static final String [] CMD_1 = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--force",
- "--class", "Hello"};
-
- private static final String [] CMD_2 = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--force",
- "--files", "hello.jar"};
-
- private static void validate1() throws Exception {
- File input = new File(appInputFilePath);
- if (!input.exists()) {
- throw new AssertionError("Unexpected file does not exist: "
- + input.getAbsolutePath());
- }
-
- File jar = new File(appJarFilePath);
- if (!jar.exists()) {
- throw new AssertionError("Unexpected file does not exist: "
- + jar.getAbsolutePath());
- }
- }
-
- private static void validate2() throws Exception {
- File input = new File(appInputFilePath);
- if (input.exists()) {
- throw new AssertionError("Unexpected file exist: "
- + input.getAbsolutePath());
- }
-
- File jar = new File(appJarFilePath);
- if (!jar.exists()) {
- throw new AssertionError("Unexpected file does not exist: "
- + jar.getAbsolutePath());
- }
- }
-
- private static void testCreateImage() throws Exception {
- JPackagerHelper.executeCLI(true, CMD_1);
- validate1();
-
- JPackagerHelper.executeCLI(true, CMD_2);
- validate2();
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- JPackagerHelper.executeToolProvider(true, CMD_1);
- validate1();
-
- JPackagerHelper.executeToolProvider(true, CMD_2);
- validate2();
- }
-
- private static void createInputFile() throws Exception {
- try (PrintWriter out = new PrintWriter(
- new BufferedWriter(new FileWriter(inputFile)))) {
- out.println("jpackgaer resource file");
- }
- }
-
- private static void initCMD() {
- File input = new File(inputFile);
- File jar = new File(jarFile);
-
- String inputPath = input.getAbsolutePath();
- String jarPath = jar.getAbsolutePath();
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
-
- createInputFile();
- initCMD();
-
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageJVMArgsTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.File;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.List;
-
-/*
- * @test
- * @summary jpackager create image with --jvm-args test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageJVMArgsTest
- */
-public class JPackagerCreateImageJVMArgsTest {
-
- private static final String app;
- private static final String appOutput = "appOutput.txt";
- private static final String appOutputPath;
-
- private static final String[] CMD = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--files", "hello.jar",
- "--force",
- "--jvm-args", "TBD"};
-
- private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
- private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
- private static final String ARGUMENT3 =
- "-Dparam3=Some \"Param\" with \" 3";
-
- private static final List<String> arguments = new ArrayList<>();
-
- static {
- if (JPackagerHelper.isWindows()) {
- app = "output" + File.separator + "test"
- + File.separator + "test.exe";
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- } else if (JPackagerHelper.isOSX()) {
- app = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "MacOS"
- + File.separator + "test"; appOutputPath = "output"
- + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java";
- } else {
- app = "output" + File.separator + "test" + File.separator + "test";
- appOutputPath = "output"
- + File.separator + "test" + File.separator + "app";
- }
- }
-
- private static void initArguments(boolean toolProvider) {
- if (arguments.isEmpty()) {
- arguments.add(ARGUMENT1);
- arguments.add(ARGUMENT2);
- arguments.add(ARGUMENT3);
- }
-
- String argumentsMap = JPackagerHelper.listToArgumentsMap(arguments,
- toolProvider);
- CMD[CMD.length - 1] = argumentsMap;
- }
-
- private static void validateResult(String[] result, List<String> args)
- throws Exception {
- if (result.length != (args.size() + 2)) {
- for (String r : result) {
- System.err.println(r.trim());
- }
- throw new AssertionError("Unexpected number of lines: "
- + result.length);
- }
-
- if (!result[0].trim().equals("jpackager test application")) {
- throw new AssertionError("Unexpected result[0]: " + result[0]);
- }
-
- if (!result[1].trim().equals("args.length: 0")) {
- throw new AssertionError("Unexpected result[1]: " + result[1]);
- }
-
- int index = 2;
- for (String arg : args) {
- if (!result[index].trim().equals(arg)) {
- throw new AssertionError("Unexpected result[" + index + "]: "
- + result[index]);
- }
- index++;
- }
- }
-
- private static void validate(List<String> expectedArgs) throws Exception {
- int retVal = JPackagerHelper.execute(null, app);
- if (retVal != 0) {
- throw new AssertionError("Test application exited with error: "
- + retVal);
- }
-
- File outfile = new File(appOutputPath + File.separator + appOutput);
- if (!outfile.exists()) {
- throw new AssertionError(appOutput + " was not created");
- }
-
- String output = Files.readString(outfile.toPath());
- String[] result = output.split("\n");
- validateResult(result, expectedArgs);
- }
-
- private static void testCreateImage() throws Exception {
- initArguments(false);
- JPackagerHelper.executeCLI(true, CMD);
- validate(arguments);
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- initArguments(true);
- JPackagerHelper.executeToolProvider(true, CMD);
- validate(arguments);
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageMissingArgumentsTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2018, 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 jpackager create image missing arguments test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageMissingArgumentsTest
- */
-
-public class JPackagerCreateImageMissingArgumentsTest {
- private static final String [] RESULT_1 = {"--output" };
- private static final String [] CMD_1 = {
- "create-image",
- "--input", "input",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--force",
- "--files", "hello.jar"};
-
- private static final String [] RESULT_2 = {"--input"};
- private static final String [] CMD_2 = {
- "create-image",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--force",
- "--files", "hello.jar"};
-
- private static final String [] RESULT_3 = {"--input", "--app-image"};
- private static final String [] CMD_3 = {
- "create-installer",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--force",
- "--files", "hello.jar"};
-
- private static void validate(String output, String [] expected)
- throws Exception {
- String[] result = output.split("\n");
- if (result.length != 1) {
- System.err.println(output);
- throw new AssertionError("Invalid number of lines in output: "
- + result.length);
- }
-
- for (String s : expected) {
- if (!result[0].contains(s)) {
- System.err.println("Expected to contain: " + s);
- System.err.println("Actual: " + result[0]);
- throw new AssertionError("Unexpected error message");
- }
- }
- }
-
- private static void testMissingArg() throws Exception {
- String output = JPackagerHelper.executeCLI(false, CMD_1);
- validate(output, RESULT_1);
-
- output = JPackagerHelper.executeCLI(false, CMD_2);
- validate(output, RESULT_2);
-
- output = JPackagerHelper.executeCLI(false, CMD_3);
- validate(output, RESULT_3);
- }
-
- private static void testMissingArgToolProvider() throws Exception {
- String output = JPackagerHelper.executeToolProvider(false, CMD_1);
- validate(output, RESULT_1);
-
- output = JPackagerHelper.executeToolProvider(false, CMD_2);
- validate(output, RESULT_2);
-
- output = JPackagerHelper.executeToolProvider(false, CMD_3);
- validate(output, RESULT_3);
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- testMissingArg();
- testMissingArgToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageSecondaryLauncherTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.List;
-
- /*
- * @test
- * @summary jpackager create image with secondary launcher test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageSecondaryLauncherTest
- */
-public class JPackagerCreateImageSecondaryLauncherTest {
- private static final String app;
- private static final String app2;
- private static final String appOutput = "appOutput.txt";
- private static final String appOutputPath;
- private static final String MSG = "jpackager test application";
- private static final String [] CMD = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--files", "hello.jar",
- "--force",
- "--secondary-launcher", "sl.properties"};
-
- // Note: quotes in argument for secondary launcher is not support by test
- private static final String ARGUMENT1 = "argument 1";
- private static final String ARGUMENT2 = "argument 2";
- private static final String ARGUMENT3 = "argument 3";
-
- private static final List<String> arguments = new ArrayList<>();
-
- private static final String PARAM1 = "-Dparam1=Some Param 1";
- private static final String PARAM2 = "-Dparam2=Some Param 2";
- private static final String PARAM3 = "-Dparam3=Some Param 3";
-
- private static final List<String> vmArguments = new ArrayList<>();
-
- static {
- if (JPackagerHelper.isWindows()) {
- app = "output" + File.separator + "test"
- + File.separator + "test.exe";
- app2 = "output" + File.separator + "test"
- + File.separator + "test2.exe";
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- } else if (JPackagerHelper.isOSX()) {
- app = "output" + File.separator + "test.app"
- + File.separator + "Contents"
- + File.separator + "MacOS" + File.separator + "test";
- app2 = "output" + File.separator + "test.app"
- + File.separator + "Contents"
- + File.separator + "MacOS" + File.separator + "test2";
- appOutputPath = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java";
- } else {
- app = "output" + File.separator + "test" + File.separator + "test";
- app2 = "output" + File.separator + "test"
- + File.separator + "test2";
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- }
- }
-
- private static void validateResult(List<String> args, List<String> vmArgs)
- throws Exception {
- File outfile = new File(appOutputPath + File.separator + appOutput);
- if (!outfile.exists()) {
- throw new AssertionError(appOutput + " was not created");
- }
-
- String output = Files.readString(outfile.toPath());
- String[] result = output.split("\n");
-
- if (result.length != (args.size() + vmArgs.size() + 2)) {
- throw new AssertionError("Unexpected number of lines: "
- + result.length);
- }
-
- if (!result[0].trim().equals("jpackager test application")) {
- throw new AssertionError("Unexpected result[0]: " + result[0]);
- }
-
- if (!result[1].trim().equals("args.length: " + args.size())) {
- throw new AssertionError("Unexpected result[1]: " + result[1]);
- }
-
- int index = 2;
- for (String arg : args) {
- if (!result[index].trim().equals(arg)) {
- throw new AssertionError("Unexpected result[" + index + "]: "
- + result[index]);
- }
- index++;
- }
-
- for (String vmArg : vmArgs) {
- if (!result[index].trim().equals(vmArg)) {
- throw new AssertionError("Unexpected result[" + index + "]: "
- + result[index]);
- }
- index++;
- }
- }
-
- private static void validate() throws Exception {
- int retVal = JPackagerHelper.execute(null, app);
- if (retVal != 0) {
- throw new AssertionError("Test application exited with error: "
- + retVal);
- }
- validateResult(new ArrayList<>(), new ArrayList<>());
-
- retVal = JPackagerHelper.execute(null, app2);
- if (retVal != 0) {
- throw new AssertionError("Test application exited with error: "
- + retVal);
- }
- validateResult(arguments, vmArguments);
- }
-
- private static void testCreateImage() throws Exception {
- JPackagerHelper.executeCLI(true, CMD);
- validate();
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- JPackagerHelper.executeToolProvider(true, CMD);
- validate();
- }
-
- private static void createSLProperties() throws Exception {
- arguments.add(ARGUMENT1);
- arguments.add(ARGUMENT2);
- arguments.add(ARGUMENT3);
-
- String argumentsMap =
- JPackagerHelper.listToArgumentsMap(arguments, true);
-
- vmArguments.add(PARAM1);
- vmArguments.add(PARAM2);
- vmArguments.add(PARAM3);
-
- String vmArgumentsMap =
- JPackagerHelper.listToArgumentsMap(vmArguments, true);
-
- try (PrintWriter out = new PrintWriter(new BufferedWriter(
- new FileWriter("sl.properties")))) {
- out.println("name=test2");
- out.println("arguments=" + argumentsMap);
- out.println("jvm-args=" + vmArgumentsMap);
- }
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- createSLProperties();
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageStripNativeCommandsTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.stream.Collectors;
-
- /*
- * @test
- * @summary jpackager create image with --strip-native-commands test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageStripNativeCommandsTest
- */
-public class JPackagerCreateImageStripNativeCommandsTest {
- private static final String runtimeBinPath;
-
- private static final String [] CMD = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--files", "hello.jar",
- "--force",
- "--strip-native-commands"};
-
- static {
- if (JPackagerHelper.isWindows()) {
- runtimeBinPath = "output" + File.separator + "test"
- + File.separator + "runtime" + File.separator + "bin";
- } else if (JPackagerHelper.isOSX()) {
- runtimeBinPath = "output" + File.separator + "test.app"
- + File.separator + "Contents"
- + File.separator + "PlugIns" + File.separator
- + "Java.runtime" + File.separator
- + "Contents" + File.separator
- + "Home" + File.separator + "bin";
- } else {
- runtimeBinPath = "output" + File.separator + "test"
- + File.separator + "runtime" + File.separator + "bin";
- }
- }
-
- private static void validate() throws Exception {
- if (JPackagerHelper.isWindows()) {
- Path binPath = Paths.get(runtimeBinPath).toAbsolutePath();
- List<Path> files = Files.walk(binPath).collect(Collectors.toList());
- files.forEach((f) -> {
- if (f.toString().endsWith(".exe")) {
- throw new AssertionError(
- "Found executable file in runtime bin folder: "
- + f.toString());
- }
- });
- } else {
- File binFolder = new File(runtimeBinPath);
- if (binFolder.exists()) {
- throw new AssertionError("Found bin folder in runtime: "
- + binFolder.toString());
- }
- }
- }
-
- private static void testCreateImage() throws Exception {
- JPackagerHelper.executeCLI(true, CMD);
- validate();
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- JPackagerHelper.executeToolProvider(true, CMD);
- validate();
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.File;
-import java.nio.file.Files;
-
- /*
- * @test
- * @summary jpackager create image test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageTest
- */
-public class JPackagerCreateImageTest {
- private static final String app;
- private static final String appOutput = "appOutput.txt";
- private static final String appOutputPath;
- private static final String MSG = "jpackager test application";
- private static final String [] CMD = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--force",
- "--files", "hello.jar"};
-
- static {
- if (JPackagerHelper.isWindows()) {
- app = "output" + File.separator + "test"
- + File.separator + "test.exe";
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- } else if (JPackagerHelper.isOSX()) {
- app = "output" + File.separator + "test.app" + File.separator
- + "Contents" + File.separator
- + "MacOS" + File.separator + "test";
- appOutputPath = "output" + File.separator + "test.app"
- + File.separator + "Contents" + File.separator + "Java";
- } else {
- app = "output" + File.separator + "test" + File.separator + "test";
- appOutputPath = "output" + File.separator + "test"
- + File.separator + "app";
- }
- }
-
- private static void validateResult(String[] result) throws Exception {
- if (result.length != 2) {
- throw new AssertionError(
- "Unexpected number of lines: " + result.length);
- }
-
- if (!result[0].trim().equals("jpackager test application")) {
- throw new AssertionError("Unexpected result[0]: " + result[0]);
- }
-
- if (!result[1].trim().equals("args.length: 0")) {
- throw new AssertionError("Unexpected result[1]: " + result[1]);
- }
- }
-
- private static void validate() throws Exception {
- int retVal = JPackagerHelper.execute(null, app);
- if (retVal != 0) {
- throw new AssertionError(
- "Test application exited with error: " + retVal);
- }
-
- File outfile = new File(appOutputPath + File.separator + appOutput);
- if (!outfile.exists()) {
- throw new AssertionError(appOutput + " was not created");
- }
-
- String output = Files.readString(outfile.toPath());
- String[] result = output.split("\n");
- validateResult(result);
- }
-
- private static void testCreateImage() throws Exception {
- JPackagerHelper.executeCLI(true, CMD);
- validate();
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- JPackagerHelper.executeToolProvider(true, CMD);
- validate();
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerCreateImageVerboseTest.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2018, 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 jpackager create image verbose test
- * @build JPackagerHelper
- * @modules jdk.jpackager
- * @run main/othervm -Xmx512m JPackagerCreateImageVerboseTest
- */
-public class JPackagerCreateImageVerboseTest {
-
- private static final String[] CMD = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--force",
- "--files", "hello.jar"};
-
- private static final String[] CMD_VERBOSE = {
- "create-image",
- "--input", "input",
- "--output", "output",
- "--name", "test",
- "--main-jar", "hello.jar",
- "--class", "Hello",
- "--files", "hello.jar",
- "--force",
- "--verbose"};
-
- private static void validate(String result, String resultVerbose)
- throws Exception {
- String[] r = result.split("\n");
- String[] rv = resultVerbose.split("\n");
-
- if (r.length >= rv.length) {
- System.err.println("r.length: " + r.length);
- System.err.println(result);
- System.err.println("rv.length: " + rv.length);
- System.err.println(resultVerbose);
- throw new AssertionError(
- "non-verbose output is less or equal to verbose output");
- }
- }
-
- private static void testCreateImage() throws Exception {
- String result = JPackagerHelper.executeCLI(true, CMD);
- String resultVerbose = JPackagerHelper.executeCLI(true, CMD_VERBOSE);
- validate(result, resultVerbose);
- }
-
- private static void testCreateImageToolProvider() throws Exception {
- String result = JPackagerHelper.executeToolProvider(true, CMD);
- String resultVerbose =
- JPackagerHelper.executeToolProvider(true, CMD_VERBOSE);
- validate(result, resultVerbose);
- }
-
- public static void main(String[] args) throws Exception {
- JPackagerHelper.createHelloJar();
- testCreateImage();
- testCreateImageToolProvider();
- }
-
-}
--- a/test/jdk/tools/jpackager/JPackagerHelper.java Wed Nov 21 12:00:01 2018 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,363 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
-
-import java.util.spi.ToolProvider;
-
-public class JPackagerHelper {
-
- private static final boolean VERBOSE = false;
- private static final String OS =
- System.getProperty("os.name").toLowerCase();
- private static final String JAVA_HOME = System.getProperty("java.home");
- private static final String TEST_SRC = System.getProperty("test.src");
- private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
- private static final Path JPACKAGER;
- private static final Path JAVAC;
- private static final Path JAR;
-
- static {
- if (OS.startsWith("win")) {
- JPACKAGER = BIN_DIR.resolve("jpackager.exe");
- JAVAC = BIN_DIR.resolve("javac.exe");
- JAR = BIN_DIR.resolve("jar.exe");
- } else {
- JPACKAGER = BIN_DIR.resolve("jpackager");
- JAVAC = BIN_DIR.resolve("javac");
- JAR = BIN_DIR.resolve("jar");
- }
- }
-
- static final ToolProvider JPACKAGER_TOOL =
- ToolProvider.findFirst("jpackager").orElseThrow(
- () -> new RuntimeException("jpackager tool not found"));
-
- public static int execute(File out, String... command) throws Exception {
- if (VERBOSE) {
- System.out.print("Execute command: ");
- for (String c : command) {
- System.out.print(c);
- System.out.print(" ");
- }
- System.out.println();
- }
-
- ProcessBuilder builder = new ProcessBuilder(command);
- if (out != null) {
- builder.redirectErrorStream(true);
- builder.redirectOutput(out);
- }
-
- Process process = builder.start();
- return process.waitFor();
- }
-
- private static String[] getCommand(String... args) {
- String[] command;
- if (args == null) {
- command = new String[1];
- } else {
- command = new String[args.length + 1];
- }
-
- int index = 0;
- command[index] = JPACKAGER.toString();
-
- if (args != null) {
- for (String arg : args) {
- index++;
- command[index] = arg;
- }
- }
-
- return command;
- }
-
- public static String executeCLI(boolean retValZero, String... args)
- throws Exception {
- int retVal;
- File outfile = new File("output.log");
- try {
- String[] command = getCommand(args);
- retVal = execute(outfile, command);
- } catch (Exception ex) {
- if (outfile.exists()) {
- System.err.println(Files.readString(outfile.toPath()));
- }
- throw ex;
- }
-
- String output = Files.readString(outfile.toPath());
- if (retValZero) {
- if (retVal != 0) {
- System.err.println(output);
- throw new AssertionError("jpackager exited with error: "
- + retVal);
- }
- } else {
- if (retVal == 0) {
- System.err.println(output);
- throw new AssertionError("jpackager exited without error: "
- + retVal);
- }
- }
-
- if (VERBOSE) {
- System.out.println("output =");
- System.out.println(output);
- }
-
- return output;
- }
-
- public static String executeToolProvider(
- boolean retValZero, String... args) throws Exception {
- StringWriter writer = new StringWriter();
- PrintWriter pw = new PrintWriter(writer);
- int retVal = JPACKAGER_TOOL.run(pw, pw, args);
- String output = writer.toString();
-
- if (retValZero) {
- if (retVal != 0) {
- System.err.println(output);
- throw new AssertionError("jpackager exited with error: "
- + retVal);
- }
- } else {
- if (retVal == 0) {
- System.err.println(output);
- throw new AssertionError("jpackager exited without error");
- }
- }
-
- if (VERBOSE) {
- System.out.println("output =");
- System.out.println(output);
- }
-
- return output;
- }
-
- public static boolean isWindows() {
- return (OS.contains("win"));
- }
-
- public static boolean isOSX() {
- return (OS.contains("mac"));
- }
-
- public static boolean isLinux() {
- return ((OS.contains("nix") || OS.contains("nux")));
- }
-
- public static void createHelloJar() throws Exception {
- int retVal;
-
- File input = new File("input");
- if (!input.exists()) {
- input.mkdir();
- }
-
- Files.copy(Path.of(TEST_SRC + File.separator + "Hello.java"),
- Path.of("Hello.java"));
-
- File javacLog = new File("javac.log");
- try {
- retVal = execute(javacLog, JAVAC.toString(), "Hello.java");
- } catch (Exception ex) {
- if (javacLog.exists()) {
- System.err.println(Files.readString(javacLog.toPath()));
- }
- throw ex;
- }
-
- if (retVal != 0) {
- if (javacLog.exists()) {
- System.err.println(Files.readString(javacLog.toPath()));
- }
- throw new AssertionError("javac exited with error: " + retVal);
- }
-
- File jarLog = new File("jar.log");
- try {
- retVal = execute(null, JAR.toString(), "cvf",
- "input" + File.separator + "hello.jar", "Hello.class");
- } catch (Exception ex) {
- if (jarLog.exists()) {
- System.err.println(Files.readString(jarLog.toPath()));
- }
- throw ex;
- }
-
- if (retVal != 0) {
- if (jarLog.exists()) {
- System.err.println(Files.readString(jarLog.toPath()));
- }
- throw new AssertionError("jar exited with error: " + retVal);
- }
- }
-
- public static String listToArgumentsMap(List<String> arguments,
- boolean toolProvider) {
- if (arguments.isEmpty()) {
- return "";
- }
-
- String argsStr = "";
- for (int i = 0; i < arguments.size(); i++) {
- String arg = arguments.get(i);
- argsStr += quote(arg, toolProvider);
- if ((i + 1) != arguments.size()) {
- argsStr += " ";
- }
- }
-
- if (!toolProvider && isWindows()) {
- if (argsStr.contains(" ")) {
- if (argsStr.contains("\"")) {
- argsStr = escapeQuote(argsStr, toolProvider);
- }
- argsStr = "\"" + argsStr + "\"";
- }
- }
- return argsStr;
- }
-
- private static String quote(String in, boolean toolProvider) {
- if (in == null) {
- return null;
- }
-
- if (in.isEmpty()) {
- return "";
- }
-
- if (!in.contains("=")) {
- // Not a property
- if (in.contains(" ")) {
- in = escapeQuote(in, toolProvider);
- return "\"" + in + "\"";
- }
- return in;
- }
-
- if (!in.contains(" ")) {
- return in; // No need to quote
- }
-
- int paramIndex = in.indexOf("=");
- if (paramIndex <= 0) {
- return in; // Something wrong, just skip quoting
- }
-
- String param = in.substring(0, paramIndex);
- String value = in.substring(paramIndex + 1);
-
- if (value.length() == 0) {
- return in; // No need to quote
- }
-
- value = escapeQuote(value, toolProvider);
-
- return param + "=" + "\"" + value + "\"";
- }
-
- private static String escapeQuote(String in, boolean toolProvider) {
- if (in == null) {
- return null;
- }
-
- if (in.isEmpty()) {
- return "";
- }
-
- if (in.contains("\"")) {
- // Use code points to preserve non-ASCII chars
- StringBuilder sb = new StringBuilder();
- int codeLen = in.codePointCount(0, in.length());
- for (int i = 0; i < codeLen; i++) {
- int code = in.codePointAt(i);
- // Note: No need to escape '\' on Linux or OS X
- // jpackager expects us to pass arguments and properties with
- // quotes and spaces as a map
- // with quotes being escaped with additional \ for
- // internal quotes.
- // So if we want two properties below:
- // -Djnlp.Prop1=Some "Value" 1
- // -Djnlp.Prop2=Some Value 2
- // jpackager will need:
- // "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\""
- // but since we using ProcessBuilder to run jpackager we will need to escape
- // our escape symbols as well, so we will need to pass string below to ProcessBuilder:
- // "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\""
- switch (code) {
- case '"':
- // " -> \" -> \\\"
- if (i == 0 || in.codePointAt(i - 1) != '\\') {
- if (!toolProvider && isWindows()) {
- sb.appendCodePoint('\\');
- sb.appendCodePoint('\\');
- }
- sb.appendCodePoint('\\');
- sb.appendCodePoint(code);
- }
- break;
- case '\\':
- // We need to escape already escaped symbols as well
- if ((i + 1) < codeLen) {
- int nextCode = in.codePointAt(i + 1);
- if (nextCode == '"') {
- // \" -> \\\"
- sb.appendCodePoint('\\');
- sb.appendCodePoint('\\');
- sb.appendCodePoint('\\');
- sb.appendCodePoint(nextCode);
- } else {
- sb.appendCodePoint('\\');
- sb.appendCodePoint(code);
- }
- } else {
- if (isWindows()) {
- sb.appendCodePoint('\\');
- }
- sb.appendCodePoint(code);
- }
- break;
- default:
- sb.appendCodePoint(code);
- break;
- }
- }
- return sb.toString();
- }
-
- return in;
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/JPackagerMissingArgumentsTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image missing arguments test
+ * @library helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerMissingArgumentsTest
+ */
+
+public class JPackagerMissingArgumentsTest {
+ private static final String [] RESULT_1 = {"--output"};
+ private static final String [] CMD_1 = {
+ "create-image",
+ "--input", "input",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String [] RESULT_2 = {"--input"};
+ private static final String [] CMD_2 = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String [] RESULT_3 = {"--input", "--app-image"};
+ private static final String [] CMD_3 = {
+ "create-installer",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String [] RESULT_4 = {"--class"};
+ private static final String [] CMD_4 = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String [] RESULT_5 = {"--main-jar"};
+ private static final String [] CMD_5 = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String [] RESULT_6 = {"--module-path", "--runtime-image"};
+ private static final String [] CMD_6 = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--module", "com.hello/com.hello.Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String [] RESULT_7 = {"--module-path", "--runtime-image",
+ "--app-image"};
+ private static final String [] CMD_7 = {
+ "create-installer",
+ "--output", "output",
+ "--name", "test",
+ "--module", "com.hello/com.hello.Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static void validate(String output, String [] expected)
+ throws Exception {
+ String[] result = output.split("\n");
+ if (result.length != 1) {
+ System.err.println(output);
+ throw new AssertionError("Invalid number of lines in output: "
+ + result.length);
+ }
+
+ for (String s : expected) {
+ if (!result[0].contains(s)) {
+ System.err.println("Expected to contain: " + s);
+ System.err.println("Actual: " + result[0]);
+ throw new AssertionError("Unexpected error message");
+ }
+ }
+ }
+
+ private static void testMissingArg() throws Exception {
+ String output = JPackagerHelper.executeCLI(false, CMD_1);
+ validate(output, RESULT_1);
+
+ output = JPackagerHelper.executeCLI(false, CMD_2);
+ validate(output, RESULT_2);
+
+ output = JPackagerHelper.executeCLI(false, CMD_3);
+ validate(output, RESULT_3);
+
+ output = JPackagerHelper.executeCLI(false, CMD_4);
+ validate(output, RESULT_4);
+
+ output = JPackagerHelper.executeCLI(false, CMD_5);
+ validate(output, RESULT_5);
+
+ output = JPackagerHelper.executeCLI(false, CMD_6);
+ validate(output, RESULT_6);
+
+ output = JPackagerHelper.executeCLI(false, CMD_7);
+ validate(output, RESULT_7);
+ }
+
+ private static void testMissingArgToolProvider() throws Exception {
+ String output = JPackagerHelper.executeToolProvider(false, CMD_1);
+ validate(output, RESULT_1);
+
+ output = JPackagerHelper.executeToolProvider(false, CMD_2);
+ validate(output, RESULT_2);
+
+ output = JPackagerHelper.executeToolProvider(false, CMD_3);
+ validate(output, RESULT_3);
+
+ output = JPackagerHelper.executeToolProvider(false, CMD_4);
+ validate(output, RESULT_4);
+
+ output = JPackagerHelper.executeToolProvider(false, CMD_5);
+ validate(output, RESULT_5);
+
+ output = JPackagerHelper.executeToolProvider(false, CMD_6);
+ validate(output, RESULT_6);
+
+ output = JPackagerHelper.executeToolProvider(false, CMD_7);
+ validate(output, RESULT_7);
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testMissingArg();
+ testMissingArgToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/JPackagerVersionTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018, 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 jpackager version test
+ * @library helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerVersionTest
+ */
+public class JPackagerVersionTest {
+
+ private static final String ARG = "--version";
+ private static final String RESULT = "jpackager version"
+ + " " + System.getProperty("java.version");
+
+ private static void validate(String output) throws Exception {
+ String[] result = output.split("\n");
+ if (result.length != 1) {
+ System.err.println(output);
+ throw new AssertionError("Invalid number of lines in output: " + result.length);
+ }
+
+ if (!result[0].trim().equals(RESULT)) {
+ System.err.println("Expected: " + RESULT);
+ System.err.println("Actual: " + result[0]);
+ throw new AssertionError("Unexpected line 1");
+ }
+ }
+
+ private static void testVersion() throws Exception {
+ String output = JPackagerHelper.executeCLI(true, ARG);
+ validate(output);
+ }
+
+ private static void testVersionToolProvider() throws Exception {
+ String output = JPackagerHelper.executeToolProvider(true, ARG);
+ validate(output);
+ }
+
+ public static void main(String[] args) throws Exception {
+ testVersion();
+ testVersionToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/apps/Hello.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+public class Hello {
+
+ private static final String MSG = "jpackager 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/jpackager/apps/com.hello/com/hello/Hello.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2018, 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.hello;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+public class Hello {
+
+ private static final String MSG = "jpackager 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/jpackager/apps/com.hello/module-info.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018, 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.hello {
+ exports com.hello;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageArgumentsBase.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
+public class JPackagerCreateImageArgumentsBase {
+
+ private static final String app = JPackagerPath.getApp();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ private static final String ARGUMENT1 = "argument";
+ private static final String ARGUMENT2 = "Some Arguments";
+ private static final String ARGUMENT3 = "Value \"with\" quotes";
+
+ private static final String ARGUMENT_CMD1 = "test";
+
+ private static final List<String> arguments = new ArrayList<>();
+ private static final List<String> argumentsCmd = new ArrayList<>();
+
+ public static void initArguments(boolean toolProvider, String[] cmd) {
+ if (arguments.isEmpty()) {
+ arguments.add(ARGUMENT1);
+ arguments.add(ARGUMENT2);
+ arguments.add(ARGUMENT3);
+ }
+
+ if (argumentsCmd.isEmpty()) {
+ argumentsCmd.add(ARGUMENT_CMD1);
+ }
+
+ String argumentsMap
+ = JPackagerHelper.listToArgumentsMap(arguments, toolProvider);
+ cmd[cmd.length - 1] = argumentsMap;
+ }
+
+ private static void validateResult(String[] result, List<String> args)
+ throws Exception {
+ if (result.length != (args.size() + 2)) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: " + args.size())) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+
+ int index = 2;
+ for (String arg : args) {
+ if (!result[index].trim().equals(arg)) {
+ throw new AssertionError(
+ "Unexpected result[" + index + "]: " + result[index]);
+ }
+ index++;
+ }
+ }
+
+ private static void validate(String arg, List<String> expectedArgs)
+ throws Exception {
+ int retVal;
+
+ if (arg == null) {
+ retVal = JPackagerHelper.execute(null, app);
+ } else {
+ retVal = JPackagerHelper.execute(null, app, arg);
+ }
+ if (retVal != 0) {
+ throw new AssertionError("Test application exited with error: "
+ + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result, expectedArgs);
+ }
+
+ public static void testCreateImage(String[] cmd) throws Exception {
+ initArguments(false, cmd);
+ JPackagerHelper.executeCLI(true, cmd);
+ validate(null, arguments);
+ validate(ARGUMENT_CMD1, argumentsCmd);
+ }
+
+ public static void testCreateImageToolProvider(String[] cmd) throws Exception {
+ initArguments(true, cmd);
+ JPackagerHelper.executeToolProvider(true, cmd);
+ validate(null, arguments);
+ validate(ARGUMENT_CMD1, argumentsCmd);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageArgumentsModuleTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image with --arguments test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageArgumentsBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageArgumentsModuleTest
+ */
+public class JPackagerCreateImageArgumentsModuleTest {
+
+ private static final String[] CMD = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--force",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input",
+ "--arguments", "TBD"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloModule();
+ JPackagerCreateImageArgumentsBase.testCreateImage(CMD);
+ JPackagerCreateImageArgumentsBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageArgumentsTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image with --arguments test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageArgumentsBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageArgumentsTest
+ */
+public class JPackagerCreateImageArgumentsTest {
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--arguments", "TBD"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ JPackagerCreateImageArgumentsBase.testCreateImage(CMD);
+ JPackagerCreateImageArgumentsBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageBase.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+public abstract class JPackagerCreateImageBase {
+ private static final String app = JPackagerPath.getApp();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ private static void validateResult(String[] result) throws Exception {
+ if (result.length != 2) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+ }
+
+ private static void validate() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError(
+ "Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result);
+ }
+
+ public static void testCreateImage(String [] cmd) throws Exception {
+ JPackagerHelper.executeCLI(true, cmd);
+ validate();
+ }
+
+ public static void testCreateImageToolProvider(String [] cmd) throws Exception {
+ JPackagerHelper.executeToolProvider(true, cmd);
+ validate();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageBuildRootTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+
+ /*
+ * @test
+ * @summary jpackager create image to test --build-root
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageBuildRootTest
+ */
+public class JPackagerCreateImageBuildRootTest {
+ private static String buildRoot = null;
+ private static final String BUILD_ROOT = "buildRoot";
+ private static final String BUILD_ROOT_TB = "buildRootToolProvider";
+
+ private static final String [] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--build-root", "TBD"};
+
+ private static final String [] CMD_VERBOSE = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--verbose",
+ "--build-root", "TBD"};
+
+ private static void validate(boolean verbose) throws Exception {
+ File br = new File(buildRoot);
+ if (verbose) {
+ if (!br.exists()) {
+ throw new AssertionError(br.getAbsolutePath() + " does not exist");
+ }
+ } else {
+ if (br.exists()) {
+ throw new AssertionError(br.getAbsolutePath() + " exist");
+ }
+ }
+ }
+
+ private static void init(boolean toolProvider) {
+ if (toolProvider) {
+ buildRoot = BUILD_ROOT_TB;
+ } else {
+ buildRoot = BUILD_ROOT;
+ }
+
+ CMD[CMD.length - 1] = buildRoot;
+ CMD_VERBOSE[CMD_VERBOSE.length - 1] = buildRoot;
+ }
+
+ private static void testBuildRoot() throws Exception {
+ init(false);
+ JPackagerHelper.executeCLI(true, CMD);
+ validate(false);
+ JPackagerHelper.executeCLI(true, CMD_VERBOSE);
+ validate(true);
+ }
+
+ private static void testBuildRootToolProvider() throws Exception {
+ init(true);
+ JPackagerHelper.executeToolProvider(true, CMD);
+ validate(false);
+ JPackagerHelper.executeToolProvider(true, CMD_VERBOSE);
+ validate(true);
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testBuildRoot();
+ testBuildRootToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageForceTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * @test
+ * @summary jpackager create image to verify --force
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageForceTest
+ */
+public class JPackagerCreateImageForceTest {
+ private static final String app = JPackagerPath.getApp();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--output", "TBD"};
+
+ private static final String[] CMD_FORCE = {
+ "create-image",
+ "--input", "input",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar",
+ "--output", "TBD"};
+
+ private static void validateResult(String[] result) throws Exception {
+ if (result.length != 2) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+ }
+
+ private static void validate(String result) throws Exception {
+ if (!result.contains("java.io.IOException") &&
+ !result.contains("already exists") &&
+ !result.contains("--force is not specified")) {
+ System.err.println(result);
+ throw new AssertionError("Unexpected error message");
+ }
+ }
+
+ private static void validateForce() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError(
+ "Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result);
+ }
+
+ private static void testForce() throws Exception {
+ CMD[CMD.length - 1] = "output";
+ CMD_FORCE[CMD_FORCE.length - 1] = "output";
+
+ String appFolder = "test";
+ if (JPackagerHelper.isOSX()) {
+ appFolder = "test.app";
+ }
+
+ File output = new File("output" + File.separator + appFolder);
+ if (output.exists()) {
+ throw new AssertionError(
+ "Output folder already exist");
+ }
+ output.mkdirs();
+
+ String result = JPackagerHelper.executeCLI(false, CMD);
+ validate(result);
+
+ JPackagerHelper.executeCLI(true, CMD_FORCE);
+ validateForce();
+ }
+
+ private static void testForceToolProvider() throws Exception {
+ CMD[CMD.length - 1] = "outputToolProvider";
+ CMD_FORCE[CMD_FORCE.length - 1] = "outputToolProvider";
+
+ String appFolder = "test";
+ if (JPackagerHelper.isOSX()) {
+ appFolder = "test.app";
+ }
+
+ File output = new File("outputToolProvider" + File.separator + appFolder);
+ if (output.exists()) {
+ throw new AssertionError(
+ "Output folder already exist");
+ }
+ output.mkdirs();
+
+ String result = JPackagerHelper.executeToolProvider(false, CMD);
+ validate(result);
+
+ JPackagerHelper.executeToolProvider(true, CMD_FORCE);
+ validateForce();
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testForce();
+ testForceToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageIconTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * @test
+ * @summary jpackager create image to verify --icon
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageIconTest
+ */
+public class JPackagerCreateImageIconTest {
+ private static final String app = JPackagerPath.getApp();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar",
+ "--icon", getIconPath(),
+ "--output", "output"};
+
+ private static void validateResult(String[] result) throws Exception {
+ if (result.length != 2) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+ }
+
+ private static void validate() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError(
+ "Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result);
+ }
+
+ private static void validateIcon() throws Exception {
+ File origIcon = new File(getIconPath());
+ File icon = new File(JPackagerPath.getAppIcon());
+ if (origIcon.length() != icon.length()) {
+ System.err.println("origIcon.length(): " + origIcon.length());
+ System.err.println("icon.length(): " + icon.length());
+ throw new AssertionError("Icons size does not match");
+ }
+ }
+
+ private static void testIcon() throws Exception {
+ JPackagerHelper.executeCLI(true, CMD);
+ validate();
+ validateIcon();
+ }
+
+ private static void testIconToolProvider() throws Exception {
+ JPackagerHelper.executeToolProvider(true, CMD);
+ validate();
+ validateIcon();
+ }
+
+ private static String getIconPath() {
+ String ext = ".ico";
+ if (JPackagerHelper.isOSX()) {
+ ext = ".icns";
+ } else if (JPackagerHelper.isLinux()) {
+ ext = ".png";
+ }
+
+ String path = JPackagerPath.getTestSrc() + File.separator + "resources"
+ + File.separator + "icon" + ext;
+
+ return path;
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testIcon();
+ testIconToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageInputFilesTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+ /*
+ * @test
+ * @summary jpackager create image input/files test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageInputFilesTest
+ */
+public class JPackagerCreateImageInputFilesTest {
+ private static final String inputFile =
+ "input" + File.separator + "input.txt";
+ private static final String jarFile =
+ "input" + File.separator + "hello.jar";
+ private static final String appInputFilePath;
+ private static final String appJarFilePath;
+
+ static {
+ appInputFilePath = JPackagerPath.getAppWorkingDir() + File.separator + "input.txt";
+ appJarFilePath = JPackagerPath.getAppWorkingDir() + File.separator + "hello.jar";
+ }
+
+ private static final String [] CMD_1 = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--force",
+ "--class", "Hello"};
+
+ private static final String [] CMD_2 = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static void validate1() throws Exception {
+ File input = new File(appInputFilePath);
+ if (!input.exists()) {
+ throw new AssertionError("Unexpected file does not exist: "
+ + input.getAbsolutePath());
+ }
+
+ File jar = new File(appJarFilePath);
+ if (!jar.exists()) {
+ throw new AssertionError("Unexpected file does not exist: "
+ + jar.getAbsolutePath());
+ }
+ }
+
+ private static void validate2() throws Exception {
+ File input = new File(appInputFilePath);
+ if (input.exists()) {
+ throw new AssertionError("Unexpected file exist: "
+ + input.getAbsolutePath());
+ }
+
+ File jar = new File(appJarFilePath);
+ if (!jar.exists()) {
+ throw new AssertionError("Unexpected file does not exist: "
+ + jar.getAbsolutePath());
+ }
+ }
+
+ private static void testCreateImage() throws Exception {
+ JPackagerHelper.executeCLI(true, CMD_1);
+ validate1();
+
+ JPackagerHelper.executeCLI(true, CMD_2);
+ validate2();
+ }
+
+ private static void testCreateImageToolProvider() throws Exception {
+ JPackagerHelper.executeToolProvider(true, CMD_1);
+ validate1();
+
+ JPackagerHelper.executeToolProvider(true, CMD_2);
+ validate2();
+ }
+
+ private static void createInputFile() throws Exception {
+ try (PrintWriter out = new PrintWriter(
+ new BufferedWriter(new FileWriter(inputFile)))) {
+ out.println("jpackgaer resource file");
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+
+ createInputFile();
+
+ testCreateImage();
+ testCreateImageToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageJVMArgsBase.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
+public class JPackagerCreateImageJVMArgsBase {
+
+ private static final String app = JPackagerPath.getApp();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
+ private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
+ private static final String ARGUMENT3 =
+ "-Dparam3=Some \"Param\" with \" 3";
+
+ private static final List<String> arguments = new ArrayList<>();
+
+ private static void initArguments(boolean toolProvider, String [] cmd) {
+ if (arguments.isEmpty()) {
+ arguments.add(ARGUMENT1);
+ arguments.add(ARGUMENT2);
+ arguments.add(ARGUMENT3);
+ }
+
+ String argumentsMap = JPackagerHelper.listToArgumentsMap(arguments,
+ toolProvider);
+ cmd[cmd.length - 1] = argumentsMap;
+ }
+
+ private static void initArguments2(boolean toolProvider, String [] cmd) {
+ int index = cmd.length - 6;
+
+ cmd[index++] = "--jvm-args";
+ arguments.clear();
+ arguments.add(ARGUMENT1);
+ cmd[index++] = JPackagerHelper.listToArgumentsMap(arguments,
+ toolProvider);
+
+ cmd[index++] = "--jvm-args";
+ arguments.clear();
+ arguments.add(ARGUMENT2);
+ cmd[index++] = JPackagerHelper.listToArgumentsMap(arguments,
+ toolProvider);
+
+ cmd[index++] = "--jvm-args";
+ arguments.clear();
+ arguments.add(ARGUMENT3);
+ cmd[index++] = JPackagerHelper.listToArgumentsMap(arguments,
+ toolProvider);
+
+ arguments.clear();
+ arguments.add(ARGUMENT1);
+ arguments.add(ARGUMENT2);
+ arguments.add(ARGUMENT3);
+ }
+
+ private static void validateResult(String[] result, List<String> args)
+ throws Exception {
+ if (result.length != (args.size() + 2)) {
+ for (String r : result) {
+ System.err.println(r.trim());
+ }
+ throw new AssertionError("Unexpected number of lines: "
+ + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+
+ int index = 2;
+ for (String arg : args) {
+ if (!result[index].trim().equals(arg)) {
+ throw new AssertionError("Unexpected result[" + index + "]: "
+ + result[index]);
+ }
+ index++;
+ }
+ }
+
+ private static void validate(List<String> expectedArgs) throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError("Test application exited with error: "
+ + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result, expectedArgs);
+ }
+
+ public static void testCreateImageJVMArgs(String [] cmd) throws Exception {
+ initArguments(false, cmd);
+ JPackagerHelper.executeCLI(true, cmd);
+ validate(arguments);
+ }
+
+ public static void testCreateImageJVMArgsToolProvider(String [] cmd) throws Exception {
+ initArguments(true, cmd);
+ JPackagerHelper.executeToolProvider(true, cmd);
+ validate(arguments);
+ }
+
+ public static void testCreateImageJVMArgs2(String [] cmd) throws Exception {
+ initArguments2(false, cmd);
+ JPackagerHelper.executeCLI(true, cmd);
+ validate(arguments);
+ }
+
+ public static void testCreateImageJVMArgs2ToolProvider(String [] cmd) throws Exception {
+ initArguments2(true, cmd);
+ JPackagerHelper.executeToolProvider(true, cmd);
+ validate(arguments);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageJVMArgsModuleTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image with --jvm-args test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageJVMArgsBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageJVMArgsModuleTest
+ */
+public class JPackagerCreateImageJVMArgsModuleTest {
+
+ private static final String[] CMD = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--force",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input",
+ "--jvm-args", "TBD"};
+
+ private static final String[] CMD2 = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--force",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input",
+ "--jvm-args", "TBD",
+ "--jvm-args", "TBD",
+ "--jvm-args", "TBD"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloModule();
+
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgs(CMD);
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgsToolProvider(CMD);
+
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgs2(CMD2);
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgs2ToolProvider(CMD2);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageJVMArgsTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image with --jvm-args test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageJVMArgsBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageJVMArgsTest
+ */
+public class JPackagerCreateImageJVMArgsTest {
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--jvm-args", "TBD"};
+
+ private static final String[] CMD2 = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--jvm-args", "TBD",
+ "--jvm-args", "TBD",
+ "--jvm-args", "TBD"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgs(CMD);
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgsToolProvider(CMD);
+
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgs2(CMD2);
+ JPackagerCreateImageJVMArgsBase.testCreateImageJVMArgs2ToolProvider(CMD2);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageMainClassAttributeTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * @test
+ * @summary jpackager create image with no main class arguments and with main-class attribute
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageMainClassAttributeTest
+ */
+public class JPackagerCreateImageMainClassAttributeTest {
+ private static final String app = JPackagerPath.getApp();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static void validateResult(String[] result) throws Exception {
+ if (result.length != 2) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+ }
+
+ private static void validate() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError(
+ "Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result);
+ }
+
+ private static void testMainClassAttribute() throws Exception {
+ JPackagerHelper.executeCLI(true, CMD);
+ validate();
+ }
+
+ private static void testMainClassAttributeToolProvider() throws Exception {
+ JPackagerHelper.executeToolProvider(true, CMD);
+ validate();
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJarWithMainClass();
+ testMainClassAttribute();
+ testMainClassAttributeToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageModuleTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image module test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageModuleTest
+ */
+public class JPackagerCreateImageModuleTest {
+ private static final String [] CMD = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--force",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloModule();
+ JPackagerCreateImageBase.testCreateImage(CMD);
+ JPackagerCreateImageBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageNoNameTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * @test
+ * @summary jpackager create image with no --name
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageNoNameTest
+ */
+public class JPackagerCreateImageNoNameTest {
+ private static final String app = JPackagerPath.getAppNoName();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDirNoName();
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static void validateResult(String[] result) throws Exception {
+ if (result.length != 2) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+ }
+
+ private static void validate() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError(
+ "Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result);
+ }
+
+ private static void testMainClassAttribute() throws Exception {
+ JPackagerHelper.executeCLI(true, CMD);
+ validate();
+ }
+
+ private static void testMainClassAttributeToolProvider() throws Exception {
+ JPackagerHelper.executeToolProvider(true, CMD);
+ validate();
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testMainClassAttribute();
+ testMainClassAttributeToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageRuntimeBase.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+ public class JPackagerCreateImageRuntimeBase {
+ private static final String app = JPackagerPath.getApp();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+ private static final String runtimeJava = JPackagerPath.getRuntimeJava();
+ private static final String runtimeJavaOutput = "javaOutput.txt";
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+
+ private static void validateResult(String[] result) throws Exception {
+ if (result.length != 2) {
+ throw new AssertionError("Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+ }
+
+ private static void validate() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError("Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ validateResult(result);
+ }
+
+ private static void validateRuntime() throws Exception {
+ int retVal = JPackagerHelper.execute(new File(runtimeJavaOutput), runtimeJava, "--list-modules");
+ if (retVal != 0) {
+ throw new AssertionError("Test application exited with error: " + retVal);
+ }
+
+ File outfile = new File(runtimeJavaOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(runtimeJavaOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ if (result.length != 1) {
+ throw new AssertionError("Unexpected number of lines: " + result.length);
+ }
+
+ if (!result[0].startsWith("java.base")) {
+ throw new AssertionError("Unexpected result: " + result[0]);
+ }
+ }
+
+ public static void testCreateImage(String [] cmd) throws Exception {
+ JPackagerHelper.executeCLI(true, cmd);
+ validate();
+ validateRuntime();
+ }
+
+ public static void testCreateImageToolProvider(String [] cmd) throws Exception {
+ JPackagerHelper.executeToolProvider(true, cmd);
+ validate();
+ validateRuntime();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageRuntimeModuleTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image runtime test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageRuntimeBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageRuntimeModuleTest
+ */
+public class JPackagerCreateImageRuntimeModuleTest {
+ private static final String [] CMD = {
+ "create-image",
+ "--runtime-image", "runtime",
+ "--output", "output",
+ "--name", "test",
+ "--force",
+ "--win-console",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloModule();
+ JPackagerHelper.createRuntime();
+ JPackagerCreateImageRuntimeBase.testCreateImage(CMD);
+ JPackagerCreateImageRuntimeBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageRuntimeTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image runtime test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageRuntimeBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageRuntimeTest
+ */
+public class JPackagerCreateImageRuntimeTest {
+ private static final String [] CMD = {
+ "create-image",
+ "--runtime-image", "runtime",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ JPackagerHelper.createRuntime();
+ JPackagerCreateImageRuntimeBase.testCreateImage(CMD);
+ JPackagerCreateImageRuntimeBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageSecondaryLauncherBase.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
+public class JPackagerCreateImageSecondaryLauncherBase {
+ private static final String app = JPackagerPath.getApp();
+ private static final String app2 = JPackagerPath.getAppSL();
+ private static final String appOutput = JPackagerPath.getAppOutputFile();
+ private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
+
+ // Note: quotes in argument for secondary launcher is not support by test
+ private static final String ARGUMENT1 = "argument 1";
+ private static final String ARGUMENT2 = "argument 2";
+ private static final String ARGUMENT3 = "argument 3";
+
+ private static final List<String> arguments = new ArrayList<>();
+
+ private static final String PARAM1 = "-Dparam1=Some Param 1";
+ private static final String PARAM2 = "-Dparam2=Some Param 2";
+ private static final String PARAM3 = "-Dparam3=Some Param 3";
+
+ private static final List<String> vmArguments = new ArrayList<>();
+
+ private static void validateResult(List<String> args, List<String> vmArgs)
+ throws Exception {
+ File outfile = new File(appWorkingDir + File.separator + appOutput);
+ if (!outfile.exists()) {
+ throw new AssertionError(appOutput + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+
+ if (result.length != (args.size() + vmArgs.size() + 2)) {
+ throw new AssertionError("Unexpected number of lines: "
+ + result.length);
+ }
+
+ if (!result[0].trim().equals("jpackager test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (!result[1].trim().equals("args.length: " + args.size())) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+
+ int index = 2;
+ for (String arg : args) {
+ if (!result[index].trim().equals(arg)) {
+ throw new AssertionError("Unexpected result[" + index + "]: "
+ + result[index]);
+ }
+ index++;
+ }
+
+ for (String vmArg : vmArgs) {
+ if (!result[index].trim().equals(vmArg)) {
+ throw new AssertionError("Unexpected result[" + index + "]: "
+ + result[index]);
+ }
+ index++;
+ }
+ }
+
+ private static void validate() throws Exception {
+ int retVal = JPackagerHelper.execute(null, app);
+ if (retVal != 0) {
+ throw new AssertionError("Test application exited with error: "
+ + retVal);
+ }
+ validateResult(new ArrayList<>(), new ArrayList<>());
+
+ retVal = JPackagerHelper.execute(null, app2);
+ if (retVal != 0) {
+ throw new AssertionError("Test application exited with error: "
+ + retVal);
+ }
+ validateResult(arguments, vmArguments);
+ }
+
+ public static void testCreateImage(String [] cmd) throws Exception {
+ JPackagerHelper.executeCLI(true, cmd);
+ validate();
+ }
+
+ public static void testCreateImageToolProvider(String [] cmd) throws Exception {
+ JPackagerHelper.executeToolProvider(true, cmd);
+ validate();
+ }
+
+ public static void createSLProperties() throws Exception {
+ arguments.add(ARGUMENT1);
+ arguments.add(ARGUMENT2);
+ arguments.add(ARGUMENT3);
+
+ String argumentsMap =
+ JPackagerHelper.listToArgumentsMap(arguments, true);
+
+ vmArguments.add(PARAM1);
+ vmArguments.add(PARAM2);
+ vmArguments.add(PARAM3);
+
+ String vmArgumentsMap =
+ JPackagerHelper.listToArgumentsMap(vmArguments, true);
+
+ try (PrintWriter out = new PrintWriter(new BufferedWriter(
+ new FileWriter("sl.properties")))) {
+ out.println("name=test2");
+ out.println("arguments=" + argumentsMap);
+ out.println("jvm-args=" + vmArgumentsMap);
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageSecondaryLauncherModuleTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image with secondary launcher test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageSecondaryLauncherBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageSecondaryLauncherModuleTest
+ */
+public class JPackagerCreateImageSecondaryLauncherModuleTest {
+ private static final String [] CMD = {
+ "create-image",
+ "--output", "output",
+ "--name", "test",
+ "--force",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input",
+ "--secondary-launcher", "sl.properties"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloModule();
+ JPackagerCreateImageSecondaryLauncherBase.createSLProperties();
+ JPackagerCreateImageSecondaryLauncherBase.testCreateImage(CMD);
+ JPackagerCreateImageSecondaryLauncherBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageSecondaryLauncherTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image with secondary launcher test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageSecondaryLauncherBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageSecondaryLauncherTest
+ */
+public class JPackagerCreateImageSecondaryLauncherTest {
+ private static final String [] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--secondary-launcher", "sl.properties"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ JPackagerCreateImageSecondaryLauncherBase.createSLProperties();
+ JPackagerCreateImageSecondaryLauncherBase.testCreateImage(CMD);
+ JPackagerCreateImageSecondaryLauncherBase.testCreateImageToolProvider(CMD);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageStripNativeCommandsTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+
+ /*
+ * @test
+ * @summary jpackager create image with --strip-native-commands test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageStripNativeCommandsTest
+ */
+public class JPackagerCreateImageStripNativeCommandsTest {
+ private static final String runtimeBinPath = JPackagerPath.getRuntimeBin();
+
+ private static final String [] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--strip-native-commands"};
+
+ private static void validate() throws Exception {
+ if (JPackagerHelper.isWindows()) {
+ Path binPath = Paths.get(runtimeBinPath).toAbsolutePath();
+ List<Path> files = Files.walk(binPath).collect(Collectors.toList());
+ files.forEach((f) -> {
+ if (f.toString().endsWith(".exe")) {
+ throw new AssertionError(
+ "Found executable file in runtime bin folder: "
+ + f.toString());
+ }
+ });
+ } else {
+ File binFolder = new File(runtimeBinPath);
+ if (binFolder.exists()) {
+ throw new AssertionError("Found bin folder in runtime: "
+ + binFolder.toString());
+ }
+ }
+ }
+
+ private static void testCreateImage() throws Exception {
+ JPackagerHelper.executeCLI(true, CMD);
+ validate();
+ }
+
+ private static void testCreateImageToolProvider() throws Exception {
+ JPackagerHelper.executeToolProvider(true, CMD);
+ validate();
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testCreateImage();
+ testCreateImageToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @build JPackagerCreateImageBase
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageTest
+ */
+public class JPackagerCreateImageTest {
+ private static final String [] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ JPackagerCreateImageBase.testCreateImage(CMD);
+ JPackagerCreateImageBase.testCreateImageToolProvider(CMD);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageVerboseTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2018, 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 jpackager create image verbose test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageVerboseTest
+ */
+public class JPackagerCreateImageVerboseTest {
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String[] CMD_VERBOSE = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--verbose"};
+
+ private static void validate(String result, String resultVerbose)
+ throws Exception {
+ String[] r = result.split("\n");
+ String[] rv = resultVerbose.split("\n");
+
+ if (r.length >= rv.length) {
+ System.err.println("r.length: " + r.length);
+ System.err.println(result);
+ System.err.println("rv.length: " + rv.length);
+ System.err.println(resultVerbose);
+ throw new AssertionError(
+ "non-verbose output is less or equal to verbose output");
+ }
+ }
+
+ private static void testCreateImage() throws Exception {
+ String result = JPackagerHelper.executeCLI(true, CMD);
+ String resultVerbose = JPackagerHelper.executeCLI(true, CMD_VERBOSE);
+ validate(result, resultVerbose);
+ }
+
+ private static void testCreateImageToolProvider() throws Exception {
+ String result = JPackagerHelper.executeToolProvider(true, CMD);
+ String resultVerbose =
+ JPackagerHelper.executeToolProvider(true, CMD_VERBOSE);
+ validate(result, resultVerbose);
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testCreateImage();
+ testCreateImageToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/createimage/JPackagerCreateImageVersionTest.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,102 @@
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * Copyright (c) 2018, 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 jpackager create image --version test
+ * @library ../helpers
+ * @build JPackagerHelper
+ * @build JPackagerPath
+ * @modules jdk.jpackager
+ * @run main/othervm -Xmx512m JPackagerCreateImageVersionTest
+ */
+public class JPackagerCreateImageVersionTest {
+ private static final String appCfg = JPackagerPath.getAppCfg();
+ private static final String VERSION = "2.3";
+ private static final String VERSION_DEFAULT = "1.0";
+
+ private static final String[] CMD = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--force",
+ "--files", "hello.jar"};
+
+ private static final String[] CMD_VERSION = {
+ "create-image",
+ "--input", "input",
+ "--output", "output",
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--class", "Hello",
+ "--files", "hello.jar",
+ "--force",
+ "--version", VERSION};
+
+ private static void validate(String version)
+ throws Exception {
+ File outfile = new File(appCfg);
+ if (!outfile.exists()) {
+ throw new AssertionError(appCfg + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ if (version == null) {
+ version = VERSION_DEFAULT;
+ }
+
+ String expected = "app.version=" + version;
+ if (!output.contains(expected)) {
+ System.err.println("Expected: " + expected);
+ throw new AssertionError("Cannot find expected entry in config file");
+ }
+ }
+
+ private static void testVersion() throws Exception {
+ JPackagerHelper.executeCLI(true, CMD);
+ validate(null);
+ JPackagerHelper.executeCLI(true, CMD_VERSION);
+ validate(VERSION);
+ }
+
+ private static void testVersionToolProvider() throws Exception {
+ JPackagerHelper.executeToolProvider(true, CMD);
+ validate(null);
+ JPackagerHelper.executeToolProvider(true, CMD_VERSION);
+ validate(VERSION);
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackagerHelper.createHelloJar();
+ testVersion();
+ testVersionToolProvider();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/helpers/JPackagerHelper.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,511 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import java.util.spi.ToolProvider;
+
+public class JPackagerHelper {
+
+ private static final boolean VERBOSE = false;
+ private static final String OS = System.getProperty("os.name").toLowerCase();
+ private static final String JAVA_HOME = System.getProperty("java.home");
+ public static final String TEST_SRC;
+ private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
+ private static final Path JPACKAGER;
+ private static final Path JAVAC;
+ private static final Path JAR;
+ private static final Path JLINK;
+
+ static {
+ if (OS.startsWith("win")) {
+ JPACKAGER = BIN_DIR.resolve("jpackager.exe");
+ JAVAC = BIN_DIR.resolve("javac.exe");
+ JAR = BIN_DIR.resolve("jar.exe");
+ JLINK = BIN_DIR.resolve("jlink.exe");
+ } else {
+ JPACKAGER = BIN_DIR.resolve("jpackager");
+ JAVAC = BIN_DIR.resolve("javac");
+ JAR = BIN_DIR.resolve("jar");
+ JLINK = BIN_DIR.resolve("jlink");
+ }
+
+ // Figure out test src based on where we called
+ File testSrc = new File(System.getProperty("test.src") + File.separator + ".."
+ + File.separator + "apps");
+ if (testSrc.exists()) {
+ TEST_SRC = System.getProperty("test.src") + File.separator + "..";
+ } else {
+ testSrc = new File(System.getProperty("test.src") + File.separator
+ + ".." + File.separator + ".." + File.separator + "apps");
+ if (testSrc.exists()) {
+ TEST_SRC = System.getProperty("test.src") + File.separator + ".."
+ + File.separator + "..";
+ } else {
+ TEST_SRC = System.getProperty("test.src");
+ }
+ }
+ }
+
+ static final ToolProvider JPACKAGER_TOOL =
+ ToolProvider.findFirst("jpackager").orElseThrow(
+ () -> new RuntimeException("jpackager tool not found"));
+
+ public static int execute(File out, String... command) throws Exception {
+ if (VERBOSE) {
+ System.out.print("Execute command: ");
+ for (String c : command) {
+ System.out.print(c);
+ System.out.print(" ");
+ }
+ System.out.println();
+ }
+
+ ProcessBuilder builder = new ProcessBuilder(command);
+ if (out != null) {
+ builder.redirectErrorStream(true);
+ builder.redirectOutput(out);
+ }
+
+ Process process = builder.start();
+ return process.waitFor();
+ }
+
+ public static Process executeNoWait(File out, String... command) throws Exception {
+ if (VERBOSE) {
+ System.out.print("Execute command: ");
+ for (String c : command) {
+ System.out.print(c);
+ System.out.print(" ");
+ }
+ System.out.println();
+ }
+
+ ProcessBuilder builder = new ProcessBuilder(command);
+ if (out != null) {
+ builder.redirectErrorStream(true);
+ builder.redirectOutput(out);
+ }
+
+ return builder.start();
+ }
+
+ private static String[] getCommand(String... args) {
+ String[] command;
+ if (args == null) {
+ command = new String[1];
+ } else {
+ command = new String[args.length + 1];
+ }
+
+ int index = 0;
+ command[index] = JPACKAGER.toString();
+
+ if (args != null) {
+ for (String arg : args) {
+ index++;
+ command[index] = arg;
+ }
+ }
+
+ return command;
+ }
+
+ public static String executeCLI(boolean retValZero, String... args) throws Exception {
+ int retVal;
+ File outfile = new File("output.log");
+ try {
+ String[] command = getCommand(args);
+ retVal = execute(outfile, command);
+ } catch (Exception ex) {
+ if (outfile.exists()) {
+ System.err.println(Files.readString(outfile.toPath()));
+ }
+ throw ex;
+ }
+
+ String output = Files.readString(outfile.toPath());
+ if (retValZero) {
+ if (retVal != 0) {
+ System.err.println(output);
+ throw new AssertionError("jpackager exited with error: " + retVal);
+ }
+ } else {
+ if (retVal == 0) {
+ System.err.println(output);
+ throw new AssertionError("jpackager exited without error: " + retVal);
+ }
+ }
+
+ if (VERBOSE) {
+ System.out.println("output =");
+ System.out.println(output);
+ }
+
+ return output;
+ }
+
+ public static String executeToolProvider(boolean retValZero, String... args) throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ int retVal = JPACKAGER_TOOL.run(pw, pw, args);
+ String output = writer.toString();
+
+ if (retValZero) {
+ if (retVal != 0) {
+ System.err.println(output);
+ throw new AssertionError("jpackager exited with error: " + retVal);
+ }
+ } else {
+ if (retVal == 0) {
+ System.err.println(output);
+ throw new AssertionError("jpackager exited without error");
+ }
+ }
+
+ if (VERBOSE) {
+ System.out.println("output =");
+ System.out.println(output);
+ }
+
+ return output;
+ }
+
+ public static boolean isWindows() {
+ return (OS.contains("win"));
+ }
+
+ public static boolean isOSX() {
+ return (OS.contains("mac"));
+ }
+
+ public static boolean isLinux() {
+ return ((OS.contains("nix") || OS.contains("nux")));
+ }
+
+ public static void createHelloJar() throws Exception {
+ createJar(false);
+ }
+
+ public static void createHelloJarWithMainClass() throws Exception {
+ createJar(true);
+ }
+
+ private static void createJar(boolean mainClassAttribute) throws Exception {
+ int retVal;
+
+ File input = new File("input");
+ if (!input.exists()) {
+ input.mkdir();
+ }
+
+ Files.copy(Path.of(TEST_SRC + File.separator + "apps" + File.separator
+ + "Hello.java"), Path.of("Hello.java"));
+
+ File javacLog = new File("javac.log");
+ try {
+ retVal = execute(javacLog, JAVAC.toString(), "Hello.java");
+ } catch (Exception ex) {
+ if (javacLog.exists()) {
+ System.err.println(Files.readString(javacLog.toPath()));
+ }
+ throw ex;
+ }
+
+ if (retVal != 0) {
+ if (javacLog.exists()) {
+ System.err.println(Files.readString(javacLog.toPath()));
+ }
+ throw new AssertionError("javac exited with error: " + retVal);
+ }
+
+ File jarLog = new File("jar.log");
+ try {
+ List<String> args = new ArrayList<>();
+ args.add(JAR.toString());
+ args.add("-c");
+ args.add("-v");
+ args.add("-f");
+ args.add("input" + File.separator + "hello.jar");
+ if (mainClassAttribute) {
+ args.add("-e");
+ args.add("Hello");
+ }
+ args.add("Hello.class");
+ retVal = execute(jarLog, args.stream().toArray(String[]::new));
+ } catch (Exception ex) {
+ if (jarLog.exists()) {
+ System.err.println(Files.readString(jarLog.toPath()));
+ }
+ throw ex;
+ }
+
+ if (retVal != 0) {
+ if (jarLog.exists()) {
+ System.err.println(Files.readString(jarLog.toPath()));
+ }
+ throw new AssertionError("jar exited with error: " + retVal);
+ }
+ }
+
+ public static void createHelloModule() throws Exception {
+ createModule("Hello.java");
+ }
+
+ private static void createModule(String javaFile) throws Exception {
+ int retVal;
+
+ File input = new File("input");
+ if (!input.exists()) {
+ input.mkdir();
+ }
+
+ File module = new File("module" + File.separator + "com.hello");
+ if (!module.exists()) {
+ module.mkdirs();
+ }
+
+ File javacLog = new File("javac.log");
+ try {
+ List<String> args = new ArrayList<>();
+ args.add(JAVAC.toString());
+ args.add("-d");
+ args.add("module" + File.separator + "com.hello");
+ args.add(TEST_SRC + File.separator + "apps" + File.separator + "com.hello"
+ + File.separator + "module-info.java");
+ args.add(TEST_SRC + File.separator + "apps" + File.separator + "com.hello"
+ + File.separator + "com" + File.separator + "hello" + File.separator
+ + javaFile);
+ retVal = execute(javacLog, args.stream().toArray(String[]::new));
+ } catch (Exception ex) {
+ if (javacLog.exists()) {
+ System.err.println(Files.readString(javacLog.toPath()));
+ }
+ throw ex;
+ }
+
+ if (retVal != 0) {
+ if (javacLog.exists()) {
+ System.err.println(Files.readString(javacLog.toPath()));
+ }
+ throw new AssertionError("javac exited with error: " + retVal);
+ }
+
+ File jarLog = new File("jar.log");
+ try {
+ List<String> args = new ArrayList<>();
+ args.add(JAR.toString());
+ args.add("--create");
+ args.add("--file");
+ args.add("input" + File.separator + "com.hello.jar");
+ args.add("-C");
+ args.add("module" + File.separator + "com.hello");
+ args.add(".");
+
+ retVal = execute(jarLog, args.stream().toArray(String[]::new));
+ } catch (Exception ex) {
+ if (jarLog.exists()) {
+ System.err.println(Files.readString(jarLog.toPath()));
+ }
+ throw ex;
+ }
+
+ if (retVal != 0) {
+ if (jarLog.exists()) {
+ System.err.println(Files.readString(jarLog.toPath()));
+ }
+ throw new AssertionError("jar exited with error: " + retVal);
+ }
+ }
+
+ public static void createRuntime() throws Exception {
+ int retVal;
+
+ File jlinkLog = new File("jlink.log");
+ try {
+ List<String> args = new ArrayList<>();
+ args.add(JLINK.toString());
+ args.add("--output");
+ args.add("runtime");
+ args.add("--add-modules");
+ args.add("java.base");
+ retVal = execute(jlinkLog, args.stream().toArray(String[]::new));
+ } catch (Exception ex) {
+ if (jlinkLog.exists()) {
+ System.err.println(Files.readString(jlinkLog.toPath()));
+ }
+ throw ex;
+ }
+
+ if (retVal != 0) {
+ if (jlinkLog.exists()) {
+ System.err.println(Files.readString(jlinkLog.toPath()));
+ }
+ throw new AssertionError("jlink exited with error: " + retVal);
+ }
+ }
+
+ public static String listToArgumentsMap(List<String> arguments, boolean toolProvider) {
+ if (arguments.isEmpty()) {
+ return "";
+ }
+
+ String argsStr = "";
+ for (int i = 0; i < arguments.size(); i++) {
+ String arg = arguments.get(i);
+ argsStr += quote(arg, toolProvider);
+ if ((i + 1) != arguments.size()) {
+ argsStr += " ";
+ }
+ }
+
+ if (!toolProvider && isWindows()) {
+ if (argsStr.contains(" ")) {
+ if (argsStr.contains("\"")) {
+ argsStr = escapeQuote(argsStr, toolProvider);
+ }
+ argsStr = "\"" + argsStr + "\"";
+ }
+ }
+ return argsStr;
+ }
+
+ private static String quote(String in, boolean toolProvider) {
+ if (in == null) {
+ return null;
+ }
+
+ if (in.isEmpty()) {
+ return "";
+ }
+
+ if (!in.contains("=")) {
+ // Not a property
+ if (in.contains(" ")) {
+ in = escapeQuote(in, toolProvider);
+ return "\"" + in + "\"";
+ }
+ return in;
+ }
+
+ if (!in.contains(" ")) {
+ return in; // No need to quote
+ }
+
+ int paramIndex = in.indexOf("=");
+ if (paramIndex <= 0) {
+ return in; // Something wrong, just skip quoting
+ }
+
+ String param = in.substring(0, paramIndex);
+ String value = in.substring(paramIndex + 1);
+
+ if (value.length() == 0) {
+ return in; // No need to quote
+ }
+
+ value = escapeQuote(value, toolProvider);
+
+ return param + "=" + "\"" + value + "\"";
+ }
+
+ private static String escapeQuote(String in, boolean toolProvider) {
+ if (in == null) {
+ return null;
+ }
+
+ if (in.isEmpty()) {
+ return "";
+ }
+
+ if (in.contains("\"")) {
+ // Use code points to preserve non-ASCII chars
+ StringBuilder sb = new StringBuilder();
+ int codeLen = in.codePointCount(0, in.length());
+ for (int i = 0; i < codeLen; i++) {
+ int code = in.codePointAt(i);
+ // Note: No need to escape '\' on Linux or OS X
+ // jpackager expects us to pass arguments and properties with
+ // quotes and spaces as a map
+ // with quotes being escaped with additional \ for
+ // internal quotes.
+ // So if we want two properties below:
+ // -Djnlp.Prop1=Some "Value" 1
+ // -Djnlp.Prop2=Some Value 2
+ // jpackager will need:
+ // "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\""
+ // but since we using ProcessBuilder to run jpackager we will need to escape
+ // our escape symbols as well, so we will need to pass string below to ProcessBuilder:
+ // "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\""
+ switch (code) {
+ case '"':
+ // " -> \" -> \\\"
+ if (i == 0 || in.codePointAt(i - 1) != '\\') {
+ if (!toolProvider && isWindows()) {
+ sb.appendCodePoint('\\');
+ sb.appendCodePoint('\\');
+ }
+ sb.appendCodePoint('\\');
+ sb.appendCodePoint(code);
+ }
+ break;
+ case '\\':
+ // We need to escape already escaped symbols as well
+ if ((i + 1) < codeLen) {
+ int nextCode = in.codePointAt(i + 1);
+ if (nextCode == '"') {
+ // \" -> \\\"
+ sb.appendCodePoint('\\');
+ sb.appendCodePoint('\\');
+ sb.appendCodePoint('\\');
+ sb.appendCodePoint(nextCode);
+ } else {
+ sb.appendCodePoint('\\');
+ sb.appendCodePoint(code);
+ }
+ } else {
+ if (isWindows()) {
+ sb.appendCodePoint('\\');
+ }
+ sb.appendCodePoint(code);
+ }
+ break;
+ default:
+ sb.appendCodePoint(code);
+ break;
+ }
+ }
+ return sb.toString();
+ }
+
+ return in;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackager/helpers/JPackagerPath.java Wed Nov 21 13:20:52 2018 -0500
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.io.File;
+
+/**
+ * Helper class which contains functions to get different system dependent paths used by tests
+ */
+public class JPackagerPath {
+
+ // Return path to test src adjusted to location of caller
+ public static String getTestSrc() {
+ return JPackagerHelper.TEST_SRC;
+ }
+
+ // Returns path to generate test application
+ public static String getApp() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "test.exe";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator + "Contents"
+ + File.separator + "MacOS" + File.separator + "test";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator + "test";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path to generate test application icon
+ public static String getAppIcon() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "test.ico";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator + "Contents"
+ + File.separator + "Resources" + File.separator + "test.icns";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator
+ + File.separator + "resources"+ File.separator + "test.png";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path to generate test application without --name argument
+ public static String getAppNoName() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "Hello" + File.separator + "Hello.exe";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "Hello.app" + File.separator + "Contents"
+ + File.separator + "MacOS" + File.separator + "Hello";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "Hello" + File.separator + "Hello";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path to generate secondary launcher of test application
+ public static String getAppSL() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "test2.exe";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator + "Contents"
+ + File.separator + "MacOS" + File.separator + "test2";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator + "test2";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path to app working directory (where test application generates its output)
+ public static String getAppWorkingDir() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "app";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator + "Contents"
+ + File.separator + "Java";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator + "app";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path to test application cfg file
+ public static String getAppCfg() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "app" + File.separator
+ + "test.cfg";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator + "Contents"
+ + File.separator + "Java" + File.separator + "test.cfg";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator + "app" + File.separator
+ + "test.cfg";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path to app working directory without --name (where test application generates its output)
+ public static String getAppWorkingDirNoName() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "Hello" + File.separator + "app";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "Hello.app" + File.separator + "Contents"
+ + File.separator + "Java";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "Hello" + File.separator + "app";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns path including executable to java in image runtime folder
+ public static String getRuntimeJava() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "runtime" + File.separator
+ + "bin" + File.separator + "java.exe";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator
+ + "Contents" + File.separator + "PlugIns" + File.separator
+ + "Java.runtime" + File.separator + "Contents" + File.separator
+ + "Home" + File.separator + "bin" + File.separator + "java";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator + "runtime" + File.separator
+ + "bin" + File.separator + "java";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+
+ // Returns output file name generate by test application
+ public static String getAppOutputFile() {
+ return "appOutput.txt";
+ }
+
+ // Returns path to bin folder in image runtime
+ public static String getRuntimeBin() {
+ if (JPackagerHelper.isWindows()) {
+ return "output" + File.separator + "test" + File.separator + "runtime"
+ + File.separator + "bin";
+ } else if (JPackagerHelper.isOSX()) {
+ return "output" + File.separator + "test.app" + File.separator + "Contents"
+ + File.separator + "PlugIns" + File.separator + "Java.runtime"
+ + File.separator + "Contents" + File.separator + "Home" + File.separator
+ + "bin";
+ } else if (JPackagerHelper.isLinux()) {
+ return "output" + File.separator + "test" + File.separator + "runtime"
+ + File.separator + "bin";
+ } else {
+ throw new AssertionError("Cannot detect platform");
+ }
+ }
+}
Binary file test/jdk/tools/jpackager/resources/icon.icns has changed
Binary file test/jdk/tools/jpackager/resources/icon.ico has changed
Binary file test/jdk/tools/jpackager/resources/icon.png has changed