8224130: create additional automated tests for create-app-image
Reviewed-by: asemenyuk, almatvee
--- a/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageAddLauncherBase.java Thu Jun 06 19:28:40 2019 -0400
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageAddLauncherBase.java Thu Jun 06 19:31:11 2019 -0400
@@ -31,7 +31,6 @@
public class JPackageCreateAppImageAddLauncherBase {
private static final String app = JPackagePath.getApp();
- private static final String app2 = JPackagePath.getAppSL();
private static final String appOutput = JPackagePath.getAppOutputFile();
private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
@@ -47,6 +46,7 @@
private static final String PARAM3 = "-Dparam3=Some Param 3";
private static final List<String> vmArguments = new ArrayList<>();
+ private static final List<String> empty = new ArrayList<>();
private static void validateResult(List<String> args, List<String> vmArgs)
throws Exception {
@@ -58,12 +58,14 @@
String output = Files.readString(outfile.toPath());
String[] result = output.split("\n");
- if (result.length != (args.size() + vmArgs.size() + 2)) {
+ int expected = 2 + args.size() + vmArgs.size();
+
+ if (result.length != expected) {
throw new AssertionError("Unexpected number of lines: "
- + result.length);
+ + result.length + " expected: " + expected + " - results: " + output);
}
- if (!result[0].trim().equals("jpackage test application")) {
+ if (!result[0].trim().endsWith("jpackage test application")) {
throw new AssertionError("Unexpected result[0]: " + result[0]);
}
@@ -74,45 +76,62 @@
int index = 2;
for (String arg : args) {
if (!result[index].trim().equals(arg)) {
- throw new AssertionError("Unexpected result[" + index + "]: "
- + result[index]);
+ 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]);
+ throw new AssertionError("Unexpected result["
+ + index + "]: " + result[index]);
}
index++;
}
}
- private static void validate() throws Exception {
+ private static void validate(boolean includeArgs, String name)
+ throws Exception {
int retVal = JPackageHelper.execute(null, app);
if (retVal != 0) {
- throw new AssertionError("Test application exited with error: "
- + retVal);
+ throw new AssertionError("Test application " + app
+ + " exited with error: " + retVal);
}
validateResult(new ArrayList<>(), new ArrayList<>());
+ String app2 = JPackagePath.getAppSL(name);
retVal = JPackageHelper.execute(null, app2);
if (retVal != 0) {
- throw new AssertionError("Test application exited with error: "
- + retVal);
+ throw new AssertionError("Test application " + app2
+ + " exited with error: " + retVal);
}
- validateResult(arguments, vmArguments);
+ if (includeArgs) {
+ validateResult(arguments, vmArguments);
+ } else {
+ validateResult(empty, empty);
+ }
}
public static void testCreateAppImage(String [] cmd) throws Exception {
+ testCreateAppImage(cmd, true, "test2");
+ }
+
+ public static void testCreateAppImage(String [] cmd,
+ boolean includeArgs, String name) throws Exception {
JPackageHelper.executeCLI(true, cmd);
- validate();
+ validate(includeArgs, name);
}
- public static void testCreateAppImageToolProvider(String [] cmd) throws Exception {
+ public static void testCreateAppImageToolProvider(String [] cmd)
+ throws Exception {
+ testCreateAppImageToolProvider(cmd, true, "test2");
+ }
+
+ public static void testCreateAppImageToolProvider(String [] cmd,
+ boolean includeArgs, String name) throws Exception {
JPackageHelper.executeToolProvider(true, cmd);
- validate();
+ validate(includeArgs, name);
}
public static void createSLProperties() throws Exception {
@@ -135,6 +154,20 @@
out.println("arguments=" + argumentsMap);
out.println("java-options=" + vmArgumentsMap);
}
+
+ try (PrintWriter out = new PrintWriter(new BufferedWriter(
+ new FileWriter("m1.properties")))) {
+ out.println("module=com.hello/com.hello.Hello");
+ out.println("main-jar=");
+ }
+
+ try (PrintWriter out = new PrintWriter(new BufferedWriter(
+ new FileWriter("j1.properties")))) {
+ out.println("main-jar hello.jar");
+ out.println("main-class Hello");
+ }
+
+
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageAddLaunchersTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /*
+ * @test
+ * @summary jpackage create image with additional launcher test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageAddLauncherBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageAddLaunchersTest
+ */
+public class JPackageCreateAppImageAddLaunchersTest {
+ private static final String OUTPUT = "output";
+ private static final String [] CMD1 = {
+ "create-app-image",
+ "--description", "Test non modular app with multiple add-launchers where one is modular app and other is non modular app",
+ "--input", "input",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--main-class", "Hello",
+ "--module-path", "module",
+ "--add-modules", "com.hello",
+ "--add-launcher", "test3=j1.properties",
+ "--add-launcher", "test4=m1.properties"};
+
+ private static final String [] CMD2 = {
+ "create-app-image",
+ "--description", "Test modular app with multiple add-launchers where one is modular app and other is non modular app",
+ "--input", "input",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "module",
+ "--add-launcher", "test5=jl.properties",
+ "--add-launcher", "test6=m1.properties"};
+
+ public static void main(String[] args) throws Exception {
+ JPackageHelper.createHelloImageJar();
+ JPackageHelper.createHelloModule();
+ JPackageCreateAppImageAddLauncherBase.createSLProperties();
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageCreateAppImageAddLauncherBase.testCreateAppImageToolProvider(
+ CMD1, false, "test3");
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageCreateAppImageAddLauncherBase.testCreateAppImage(
+ CMD1, false, "test4");
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageCreateAppImageAddLauncherBase.testCreateAppImage(
+ CMD2, false, "test5");
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageCreateAppImageAddLauncherBase.testCreateAppImageToolProvider(
+ CMD2, false, "test6");
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageAtFilenameTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /*
+ * @test
+ * @summary jpackage create image test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageAtFilenameTest
+ */
+public class JPackageCreateAppImageAtFilenameTest {
+ private static final String OUTPUT = "output";
+
+ private static final String [] CMD = {
+ "create-app-image",
+ "--input", "input",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--main-class", "Hello",
+ };
+
+ public static void main(String[] args) throws Exception {
+ JPackageHelper.createHelloImageJar();
+
+ doTest(0, 1); // replace just the mode
+ doTest(0, 11); // replace everything
+ doTest(1, 10); // replace everything except mode
+ doTest(4, 2); // replace the name and --main-jar without jar name
+
+ }
+
+ private static void doTest(int index, int len) throws Exception {
+ String[] cmdWithAtFilename =
+ JPackageHelper.cmdWithAtFilename(CMD, index, len);
+
+ JPackageCreateAppImageBase.
+ testCreateAppImageToolProvider(cmdWithAtFilename);
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ }
+
+}
--- a/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageBase.java Thu Jun 06 19:28:40 2019 -0400
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageBase.java Thu Jun 06 19:31:11 2019 -0400
@@ -35,7 +35,7 @@
"Unexpected number of lines: " + result.length);
}
- if (!result[0].trim().equals("jpackage test application")) {
+ if (!result[0].trim().endsWith("jpackage test application")) {
throw new AssertionError("Unexpected result[0]: " + result[0]);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageJLinkModuleTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.ArrayList;
+
+ /*
+ * @test
+ * @summary jpackage create image modular jar test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageJLinkModuleTest
+ */
+public class JPackageCreateAppImageJLinkModuleTest {
+ private static final String OUTPUT = "output";
+ private static final String RUNTIME = "runtime";
+
+ private static final String [] CMD = {
+ "create-app-image",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--module", "com.other/com.other.Other",
+ "--runtime-image", RUNTIME,
+ };
+
+ public static void main(String[] args) throws Exception {
+ JPackageHelper.createOtherModule();
+
+ ArrayList<String> jlargs = new ArrayList<>();
+ jlargs.add("--add-modules");
+ jlargs.add("com.other");
+ jlargs.add("--module-path");
+ jlargs.add("module");
+ jlargs.add("--strip-debug");
+ jlargs.add("--no-header-files");
+ jlargs.add("--no-man-pages");
+ jlargs.add("--strip-native-commands");
+ JPackageHelper.createRuntime(jlargs);
+
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageCreateAppImageBase.testCreateAppImage(CMD);
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageJavaOptionsEqualsTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * @test
+ * @summary jpackage create image with --java-options test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageJavaOptionsBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageJavaOptionsEqualsTest
+ */
+public class JPackageCreateAppImageJavaOptionsEqualsTest {
+
+ private static final String app = JPackagePath.getApp();
+ private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
+
+ private static final String OUTPUT = "output";
+
+ private static final String[] CMD = {
+ "create-app-image",
+ "--input", "input",
+ "--description", "the two options below should cause two app execution "
+ + "Warnings with two lines output saying: "
+ + "WARNING: Unknown module: <module-name>",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--main-class", "Hello",
+ "--java-options",
+ "--add-exports=java.base/sun.util=me.mymodule.foo,ALL-UNNAMED",
+ "--java-options",
+ "--add-exports=java.base/sun.security.util=other.mod.bar,ALL-UNNAMED",
+ };
+
+ private static void validate() throws Exception {
+ File outfile = new File(appWorkingDir + File.separator + "app.out");
+
+ int retVal = JPackageHelper.execute(outfile, app);
+ if (retVal != 0) {
+ throw new AssertionError(
+ "Test application exited with error: " + retVal);
+ }
+
+ if (!outfile.exists()) {
+ throw new AssertionError(
+ "outfile: " + outfile + " was not created");
+ }
+
+ String output = Files.readString(outfile.toPath());
+ String[] result = output.split("\n");
+ if (result.length != 4) {
+ throw new AssertionError(
+ "Unexpected number of lines: " + result.length
+ + " - output: " + output);
+ }
+
+ if (!result[0].startsWith("WARNING: Unknown module: me.mymodule.foo")){
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
+ }
+
+ if (result[1].equals(result[0])) {
+ System.err.println("--- This is known bug JDK-8224486, remove this "
+ + "if/else block when JDK-8224486 is fixed");
+ } else
+
+ if (!result[1].startsWith("WARNING: Unknown module: other.mod.bar")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
+ }
+
+ if (!result[2].trim().endsWith("jpackage test application")) {
+ throw new AssertionError("Unexpected result[2]: " + result[2]);
+ }
+
+ if (!result[3].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[3]: " + result[3]);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackageHelper.createHelloImageJar();
+ String output = JPackageHelper.executeCLI(true, CMD);
+ validate();
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ output = JPackageHelper.executeToolProvider(true, CMD);
+ validate();
+ }
+
+}
--- a/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModuleTest.java Thu Jun 06 19:28:40 2019 -0400
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModuleTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
/*
* @test
- * @summary jpackage create image module test
+ * @summary jpackage create image modular jar test
* @library ../helpers
* @build JPackageHelper
* @build JPackagePath
@@ -34,18 +34,43 @@
public class JPackageCreateAppImageModuleTest {
private static final String OUTPUT = "output";
- private static final String [] CMD = {
+ private static final String [] CMD1 = {
"create-app-image",
+ "--module-path", "module",
+ "--module", "com.other/com.other.Other",
+ "--output", OUTPUT,
+ "--name", "test",
+ };
+
+ private static String [] commands = {
+ "create-app-image",
+ "--module-path", "module",
+ "--module", "com.other/com.other.Other",
"--output", OUTPUT,
"--name", "test",
- "--module", "com.hello/com.hello.Hello",
- "--module-path", "input"};
+ "--add-modules", "TBD",
+ };
+
+ private final static String [] paths = {
+ "ALL-MODULES",
+ "ALL_MODULE_PATH",
+ "ALL-SYSTEM",
+ "ALL-DEFAULT",
+ };
public static void main(String[] args) throws Exception {
- JPackageHelper.createHelloModule();
- JPackageCreateAppImageBase.testCreateAppImage(CMD);
+ JPackageHelper.createOtherModule();
+
JPackageHelper.deleteOutputFolder(OUTPUT);
- JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD);
+ JPackageCreateAppImageBase.testCreateAppImage(CMD1);
+
+ for (String path : paths) {
+ commands[commands.length - 1] = path;
+ System.out.println("using --add-modules " + path);
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageCreateAppImageBase.testCreateAppImageToolProvider(commands);
+ System.out.println("succeeded");
+ }
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageResourceTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.nio.file.Files;
+
+/*
+ * @test
+ * @summary jpackage create image to verify --icon
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @requires ((os.family == "windows") | (os.family == "mac"))
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageResourceTest
+ */
+public class JPackageCreateAppImageResourceTest {
+ private static final String OUTPUT = "output";
+ private static final String app = JPackagePath.getApp("icon");
+ private static final String appOutput = JPackagePath.getAppOutputFile();
+ private static final String appWorkingDir =
+ JPackagePath.getAppWorkingDir("icon");
+ private static final String resourceDir =
+ JPackagePath.getTestSrcRoot() + File.separator + "resources";
+
+ private static final String[] CMD = {
+ "create-app-image",
+ "--input", "input",
+ "--name", "icon",
+ "--main-jar", "hello.jar",
+ "--main-class", "Hello",
+ "--resource-dir", resourceDir,
+ "--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("jpackage 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 = JPackageHelper.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(JPackagePath.getAppIcon("icon"));
+ if (origIcon.length() != icon.length()) {
+ System.err.println("file: " + origIcon + " - origIcon.length(): "
+ + origIcon.length());
+ System.err.println("file: " + icon + " - icon.length(): "
+ + icon.length());
+ throw new AssertionError("Icons size does not match");
+ }
+ }
+
+ private static void testIcon() throws Exception {
+ JPackageHelper.executeCLI(true, CMD);
+ validate();
+ validateIcon();
+ }
+
+ private static void testIconToolProvider() throws Exception {
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageHelper.executeToolProvider(true, CMD);
+ validate();
+ validateIcon();
+ }
+
+ private static String getResourcenPath() {
+ return JPackagePath.getTestSrcRoot() + File.separator + "resources";
+ }
+
+ private static String getIconPath() {
+ String ext = ".ico";
+ if (JPackageHelper.isOSX()) {
+ ext = ".icns";
+ } else if (JPackageHelper.isLinux()) {
+ ext = ".png";
+ }
+ return resourceDir + File.separator + "icon" + ext;
+ }
+
+ public static void main(String[] args) throws Exception {
+ JPackageHelper.createHelloImageJar();
+ testIcon();
+ testIconToolProvider();
+ }
+}
--- a/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageVersionTest.java Thu Jun 06 19:28:40 2019 -0400
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageVersionTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -1,7 +1,3 @@
-
-import java.io.File;
-import java.nio.file.Files;
-
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -25,6 +21,9 @@
* questions.
*/
+import java.io.File;
+import java.nio.file.Files;
+
/*
* @test
* @summary jpackage create image --app-version test
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageWithSpaceTest.java Thu Jun 06 19:31:11 2019 -0400
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+
+ /*
+ * @test
+ * @summary jpackage create image test
+ * @library ../helpers
+ * @build JPackageHelper
+ * @build JPackagePath
+ * @build JPackageCreateAppImageBase
+ * @modules jdk.jpackage
+ * @run main/othervm -Xmx512m JPackageCreateAppImageWithSpaceTest
+ */
+public class JPackageCreateAppImageWithSpaceTest {
+ private static final String OUTPUT = "output";
+
+ private static final String [] CMD1 = {
+ "create-app-image",
+ "--input", "input dir",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--main-jar", "hello.jar",
+ "--main-class", "Hello",
+ };
+
+ private static final String [] CMD2 = {
+ "create-app-image",
+ "--input", "input dir2",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--main-jar", "sub dir/hello.jar",
+ "--main-class", "Hello",
+ };
+
+ public static void main(String[] args) throws Exception {
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageHelper.createHelloImageJar("input dir");
+ JPackageCreateAppImageBase.testCreateAppImage(CMD1);
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ JPackageHelper.createHelloImageJar(
+ "input dir2" + File.separator + "sub dir");
+
+ JPackageCreateAppImageBase.testCreateAppImageToolProvider(CMD2);
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ }
+}
--- a/test/jdk/tools/jpackage/helpers/JPackageHelper.java Thu Jun 06 19:28:40 2019 -0400
+++ b/test/jdk/tools/jpackage/helpers/JPackageHelper.java Thu Jun 06 19:31:11 2019 -0400
@@ -25,6 +25,8 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
@@ -164,7 +166,13 @@
public FileVisitResult visitFile(Path file,
BasicFileAttributes attr) throws IOException {
if (OS.startsWith("win")) {
- Files.setAttribute(file, "dos:readonly", false);
+ try {
+ Files.setAttribute(file, "dos:readonly", false);
+ } catch (Exception ioe) {
+ // just report and try to contune
+ System.err.println("IOException: " + ioe);
+ ioe.printStackTrace(System.err);
+ }
}
Files.delete(file);
return FileVisitResult.CONTINUE;
@@ -194,8 +202,8 @@
try {
deleteRecursive(outputFolder);
} catch (IOException ioe) {
- System.out.println("IOException: " + ioe);
- ioe.printStackTrace();
+ System.err.println("IOException: " + ioe);
+ ioe.printStackTrace(System.err);
deleteRecursive(outputFolder);
}
}
@@ -272,33 +280,44 @@
return ((OS.contains("nix") || OS.contains("nux")));
}
+ public static void createHelloImageJar(String inputDir) throws Exception {
+ createJar(false, "Hello", "image", inputDir);
+ }
+
public static void createHelloImageJar() throws Exception {
- createJar(false, "Hello", "image");
+ createJar(false, "Hello", "image", "input");
}
public static void createHelloImageJarWithMainClass() throws Exception {
- createJar(true, "Hello", "image");
+ createJar(true, "Hello", "image", "input");
}
public static void createHelloInstallerJar() throws Exception {
- createJar(false, "Hello", "installer");
+ createJar(false, "Hello", "installer", "input");
}
public static void createHelloInstallerJarWithMainClass() throws Exception {
- createJar(true, "Hello", "installer");
+ createJar(true, "Hello", "installer", "input");
}
private static void createJar(boolean mainClassAttribute, String name,
- String testType) throws Exception {
+ String testType, String inputDir) throws Exception {
int retVal;
- File input = new File("input");
+ File input = new File(inputDir);
if (!input.exists()) {
- input.mkdir();
+ input.mkdirs();
}
- Files.copy(Path.of(TEST_SRC_ROOT + File.separator + "apps" + File.separator
- + testType + File.separator + name + ".java"), Path.of(name + ".java"));
+ Path src = Path.of(TEST_SRC_ROOT + File.separator + "apps"
+ + File.separator + testType + File.separator + name + ".java");
+ Path dst = Path.of(name + ".java");
+
+ if (dst.toFile().exists()) {
+ Files.delete(dst);
+ }
+ Files.copy(src, dst);
+
File javacLog = new File("javac.log");
try {
@@ -324,7 +343,7 @@
args.add("-c");
args.add("-v");
args.add("-f");
- args.add("input" + File.separator + name.toLowerCase() + ".jar");
+ args.add(inputDir + File.separator + name.toLowerCase() + ".jar");
if (mainClassAttribute) {
args.add("-e");
args.add(name);
@@ -347,15 +366,15 @@
}
public static void createHelloModule() throws Exception {
- createModule("Hello.java", "input", "hello");
+ createModule("Hello.java", "input", "hello", true);
}
public static void createOtherModule() throws Exception {
- createModule("Other.java", "input-other", "other");
+ createModule("Other.java", "input-other", "other", false);
}
private static void createModule(String javaFile, String inputDir,
- String aName) throws Exception {
+ String aName, boolean createModularJar) throws Exception {
int retVal;
File input = new File(inputDir);
@@ -394,34 +413,41 @@
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(inputDir + File.separator + "com." + aName + ".jar");
- args.add("-C");
- args.add("module" + File.separator + "com." + aName);
- args.add(".");
+ if (createModularJar) {
+ File jarLog = new File("jar.log");
+ try {
+ List<String> args = new ArrayList<>();
+ args.add(JAR.toString());
+ args.add("--create");
+ args.add("--file");
+ args.add(inputDir + File.separator + "com." + aName + ".jar");
+ args.add("-C");
+ args.add("module" + File.separator + "com." + aName);
+ args.add(".");
- retVal = execute(jarLog, args.stream().toArray(String[]::new));
- } catch (Exception ex) {
- if (jarLog.exists()) {
- System.err.println(Files.readString(jarLog.toPath()));
+ retVal = execute(jarLog, args.stream().toArray(String[]::new));
+ } catch (Exception ex) {
+ if (jarLog.exists()) {
+ System.err.println(Files.readString(jarLog.toPath()));
+ }
+ throw ex;
}
- throw ex;
- }
- if (retVal != 0) {
- if (jarLog.exists()) {
- System.err.println(Files.readString(jarLog.toPath()));
+ if (retVal != 0) {
+ if (jarLog.exists()) {
+ System.err.println(Files.readString(jarLog.toPath()));
+ }
+ throw new AssertionError("jar exited with error: " + retVal);
}
- throw new AssertionError("jar exited with error: " + retVal);
}
}
public static void createRuntime() throws Exception {
+ List<String> moreArgs = new ArrayList<>();
+ createRuntime(moreArgs);
+ }
+
+ public static void createRuntime(List<String> moreArgs) throws Exception {
int retVal;
File jlinkLog = new File("jlink.log");
@@ -432,6 +458,8 @@
args.add("runtime");
args.add("--add-modules");
args.add("java.base");
+ args.addAll(moreArgs);
+
retVal = execute(jlinkLog, args.stream().toArray(String[]::new));
} catch (Exception ex) {
if (jlinkLog.exists()) {
@@ -473,6 +501,30 @@
return argsStr;
}
+ public static String[] cmdWithAtFilename(String [] cmd, int ndx, int len)
+ throws IOException {
+ ArrayList<String> newAList = new ArrayList<>();
+ String fileString = null;
+ for (int i=0; i<cmd.length; i++) {
+ if (i == ndx) {
+ newAList.add("@argfile.cmds");
+ fileString = cmd[i];
+ } else if (i > ndx && i < ndx + len) {
+ fileString += " " + cmd[i];
+ } else {
+ newAList.add(cmd[i]);
+ }
+ }
+ if (fileString != null) {
+ Path path = new File("argfile.cmds").toPath();
+ try (BufferedWriter bw = Files.newBufferedWriter(path);
+ PrintWriter out = new PrintWriter(bw)) {
+ out.println(fileString);
+ }
+ }
+ return newAList.toArray(new String[0]);
+ }
+
private static String quote(String in, boolean toolProvider) {
if (in == null) {
return null;
--- a/test/jdk/tools/jpackage/helpers/JPackagePath.java Thu Jun 06 19:28:40 2019 -0400
+++ b/test/jdk/tools/jpackage/helpers/JPackagePath.java Thu Jun 06 19:31:11 2019 -0400
@@ -50,13 +50,19 @@
// Returns path to generate test application
public static String getApp() {
+ return getApp("test");
+ }
+
+ public static String getApp(String name) {
if (JPackageHelper.isWindows()) {
- return "output" + File.separator + "test" + File.separator + "test.exe";
+ return "output" + File.separator + name
+ + File.separator + name + ".exe";
} else if (JPackageHelper.isOSX()) {
- return "output" + File.separator + "test.app" + File.separator + "Contents"
- + File.separator + "MacOS" + File.separator + "test";
+ return "output" + File.separator + name + ".app"
+ + File.separator + "Contents"
+ + File.separator + "MacOS" + File.separator + name;
} else if (JPackageHelper.isLinux()) {
- return "output" + File.separator + "test" + File.separator + "test";
+ return "output" + File.separator + name + File.separator + name;
} else {
throw new AssertionError("Cannot detect platform");
}
@@ -64,14 +70,20 @@
// Returns path to generate test application icon
public static String getAppIcon() {
+ return getAppIcon("test");
+ }
+
+ public static String getAppIcon(String name) {
if (JPackageHelper.isWindows()) {
- return "output" + File.separator + "test" + File.separator + "test.ico";
+ return "output" + File.separator + name + File.separator
+ + name + ".ico";
} else if (JPackageHelper.isOSX()) {
- return "output" + File.separator + "test.app" + File.separator + "Contents"
- + File.separator + "Resources" + File.separator + "test.icns";
+ return "output" + File.separator + name + ".app"
+ + File.separator + "Contents" + File.separator
+ + "Resources" + File.separator + name + ".icns";
} else if (JPackageHelper.isLinux()) {
- return "output" + File.separator + "test" + File.separator
- + File.separator + "resources"+ File.separator + "test.png";
+ return "output" + File.separator + name + File.separator
+ + "resources"+ File.separator + name + ".png";
} else {
throw new AssertionError("Cannot detect platform");
}
@@ -92,14 +104,16 @@
}
// Returns path to generate secondary launcher of test application
- public static String getAppSL() {
+ public static String getAppSL(String name) {
if (JPackageHelper.isWindows()) {
- return "output" + File.separator + "test" + File.separator + "test2.exe";
+ return "output" + File.separator + "test" + File.separator
+ + name + ".exe";
} else if (JPackageHelper.isOSX()) {
- return "output" + File.separator + "test.app" + File.separator + "Contents"
- + File.separator + "MacOS" + File.separator + "test2";
+ return "output" + File.separator + "test.app" + File.separator
+ + "Contents" + File.separator + "MacOS"
+ + File.separator + name;
} else if (JPackageHelper.isLinux()) {
- return "output" + File.separator + "test" + File.separator + "test2";
+ return "output" + File.separator + "test" + File.separator + name;
} else {
throw new AssertionError("Cannot detect platform");
}
@@ -107,13 +121,17 @@
// Returns path to app working directory (where test application generates its output)
public static String getAppWorkingDir() {
+ return getAppWorkingDir("test");
+ }
+
+ public static String getAppWorkingDir(String name) {
if (JPackageHelper.isWindows()) {
- return "output" + File.separator + "test" + File.separator + "app";
+ return "output" + File.separator + name + File.separator + "app";
} else if (JPackageHelper.isOSX()) {
- return "output" + File.separator + "test.app" + File.separator + "Contents"
- + File.separator + "Java";
+ return "output" + File.separator + name + ".app"
+ + File.separator + "Contents" + File.separator + "Java";
} else if (JPackageHelper.isLinux()) {
- return "output" + File.separator + "test" + File.separator + "app";
+ return "output" + File.separator + name + File.separator + "app";
} else {
throw new AssertionError("Cannot detect platform");
}