15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.jpackage.tests; 25 26 import java.io.File; 27 import java.io.IOException; 28 import java.nio.file.Path; 29 import java.util.Collection; 30 import java.util.List; 31 import java.util.Objects; 32 import java.util.function.Function; 33 import java.util.stream.Collectors; 34 import java.util.stream.Stream; 35 import jdk.jpackage.test.Annotations.Parameters; 36 import jdk.jpackage.test.Annotations.Test; 37 import jdk.jpackage.test.JPackageCommand; 38 import jdk.jpackage.test.TKit; 39 40 41 /* 42 * @test 43 * @summary jpackage with --module-path testing 44 * @library ../../../../helpers 45 * @build jdk.jpackage.test.* 46 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 47 * @compile ModulePathTest.java 48 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 49 * --jpt-run=jdk.jpackage.tests.ModulePathTest 50 */ 51 52 public final class ModulePathTest { 53 54 @Parameters 55 public static Collection data() { 56 return List.of(new String[][]{ 57 {GOOD_PATH, EMPTY_DIR, NON_EXISTING_DIR}, 58 {EMPTY_DIR, NON_EXISTING_DIR, GOOD_PATH}, 59 {GOOD_PATH + "/a/b/c/d", GOOD_PATH}, 60 {String.join(File.pathSeparator, EMPTY_DIR, NON_EXISTING_DIR, 61 GOOD_PATH)}, 62 {String.join(File.pathSeparator, EMPTY_DIR, NON_EXISTING_DIR), 63 String.join(File.pathSeparator, EMPTY_DIR, NON_EXISTING_DIR, 64 GOOD_PATH)}, 65 {}, 66 {EMPTY_DIR} 67 }); 68 } 69 70 public ModulePathTest(String... modulePathArgs) { 71 this.modulePathArgs = List.of(modulePathArgs); 72 } 73 74 @Test 75 public void test() throws IOException { 76 final String moduleName = "com.foo"; 77 JPackageCommand cmd = JPackageCommand.helloAppImage( 78 "benvenuto.jar:" + moduleName + "/com.foo.Hello"); 79 // Build app jar file. 80 cmd.executePrerequisiteActions(); 81 82 // Ignore runtime that can be set for all tests. Usually if default 83 // runtime is set, it is fake one to save time on running jlink and 84 // copying megabytes of data from Java home to application image. 85 // We need proper runtime for this test. 86 cmd.ignoreDefaultRuntime(true); 87 88 // --module-path should be set in JPackageCommand.helloAppImage call 89 String goodModulePath = Objects.requireNonNull(cmd.getArgumentValue( 90 "--module-path")); 91 cmd.removeArgumentWithValue("--module-path"); 92 93 Path emptyDir = TKit.createTempDirectory("empty-dir"); 94 Path nonExistingDir = TKit.withTempDirectory("non-existing-dir", x -> {}); 95 96 Function<String, String> substitute = str -> { 97 String v = str; 98 v = v.replace(GOOD_PATH, goodModulePath); 99 v = v.replace(EMPTY_DIR, emptyDir.toString()); 100 v = v.replace(NON_EXISTING_DIR, nonExistingDir.toString()); 101 return v; 102 }; 103 104 boolean withGoodPath = modulePathArgs.stream().anyMatch( 105 s -> s.contains(GOOD_PATH)); 106 107 cmd.addArguments(modulePathArgs.stream().map(arg -> Stream.of( 108 "--module-path", substitute.apply(arg))).flatMap(s -> s).collect( 109 Collectors.toList())); 110 111 if (withGoodPath) { 112 cmd.executeAndAssertHelloAppImageCreated(); 113 } else { 114 final String expectedErrorMessage; 115 if (modulePathArgs.isEmpty()) { 116 expectedErrorMessage = "Error: Missing argument: --runtime-image or --module-path"; 117 } else { 118 expectedErrorMessage = String.format( 119 "Error: Module %s not found", moduleName); 120 } 121 122 List<String> output = cmd 123 .saveConsoleOutput(true) 124 .execute(1) 125 .getOutput(); 126 TKit.assertTextStream(expectedErrorMessage).apply(output.stream()); 127 } 128 } 129 130 private final List<String> modulePathArgs; 131 132 private final static String GOOD_PATH = "@GoodPath@"; 133 private final static String EMPTY_DIR = "@EmptyDir@"; 134 private final static String NON_EXISTING_DIR = "@NonExistingDir@"; 135 } | 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.jpackage.tests; 25 26 import java.io.File; 27 import java.io.IOException; 28 import java.nio.file.Path; 29 import java.util.Collection; 30 import java.util.List; 31 import java.util.Objects; 32 import java.util.function.Function; 33 import java.util.stream.Collectors; 34 import java.util.stream.Stream; 35 import jdk.jpackage.test.Annotations.*; 36 import jdk.jpackage.test.*; 37 38 39 /* 40 * @test 41 * @summary jpackage with --module-path testing 42 * @library ../../../../helpers 43 * @build jdk.jpackage.test.* 44 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 45 * @compile ModulePathTest.java 46 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 47 * --jpt-run=jdk.jpackage.tests.ModulePathTest 48 */ 49 50 public final class ModulePathTest { 51 52 @Parameters 53 public static Collection data() { 54 return List.of(new String[][]{ 55 {GOOD_PATH, EMPTY_DIR, NON_EXISTING_DIR}, 56 {EMPTY_DIR, NON_EXISTING_DIR, GOOD_PATH}, 57 {GOOD_PATH + "/a/b/c/d", GOOD_PATH}, 58 {String.join(File.pathSeparator, EMPTY_DIR, NON_EXISTING_DIR, 59 GOOD_PATH)}, 60 {String.join(File.pathSeparator, EMPTY_DIR, NON_EXISTING_DIR), 61 String.join(File.pathSeparator, EMPTY_DIR, NON_EXISTING_DIR, 62 GOOD_PATH)}, 63 {}, 64 {EMPTY_DIR} 65 }); 66 } 67 68 public ModulePathTest(String... modulePathArgs) { 69 this.modulePathArgs = List.of(modulePathArgs); 70 } 71 72 @Test 73 @Parameter("benvenuto.jar:com.jar.foo/com.jar.foo.Hello") 74 @Parameter("benvenuto.jmod:com.jmod.foo/com.jmod.foo.JModHello") 75 public void test(String javaAppDesc) throws IOException { 76 JavaAppDesc appDesc = JavaAppDesc.parse(javaAppDesc); 77 78 Path goodModulePath = TKit.createTempDirectory("modules"); 79 80 Path appBundle = HelloApp.createBundle(appDesc, goodModulePath); 81 82 JPackageCommand cmd = new JPackageCommand() 83 .setArgumentValue("--dest", TKit.workDir().resolve("output")) 84 .setDefaultAppName() 85 .setPackageType(PackageType.IMAGE); 86 87 if (TKit.isWindows()) { 88 cmd.addArguments("--win-console"); 89 } 90 91 cmd.addArguments("--module", String.join("/", appDesc.moduleName(), 92 appDesc.className())); 93 94 // Ignore runtime that can be set for all tests. Usually if default 95 // runtime is set, it is fake one to save time on running jlink and 96 // copying megabytes of data from Java home to application image. 97 // We need proper runtime for this test. 98 cmd.ignoreDefaultRuntime(true); 99 100 Path emptyDir = TKit.createTempDirectory("empty-dir"); 101 Path nonExistingDir = TKit.withTempDirectory("non-existing-dir", x -> {}); 102 103 Function<String, String> substitute = str -> { 104 String v = str; 105 v = v.replace(GOOD_PATH, goodModulePath.toString()); 106 v = v.replace(EMPTY_DIR, emptyDir.toString()); 107 v = v.replace(NON_EXISTING_DIR, nonExistingDir.toString()); 108 return v; 109 }; 110 111 boolean withGoodPath = modulePathArgs.stream().anyMatch( 112 s -> s.contains(GOOD_PATH)); 113 114 cmd.addArguments(modulePathArgs.stream().map(arg -> Stream.of( 115 "--module-path", substitute.apply(arg))).flatMap(s -> s).collect( 116 Collectors.toList())); 117 118 if (withGoodPath) { 119 cmd.executeAndAssertHelloAppImageCreated(); 120 } else { 121 final String expectedErrorMessage; 122 if (modulePathArgs.isEmpty()) { 123 expectedErrorMessage = "Error: Missing argument: --runtime-image or --module-path"; 124 } else { 125 expectedErrorMessage = String.format( 126 "Error: Module %s not found", appDesc.moduleName()); 127 } 128 129 List<String> output = cmd 130 .saveConsoleOutput(true) 131 .execute(1) 132 .getOutput(); 133 TKit.assertTextStream(expectedErrorMessage).apply(output.stream()); 134 } 135 } 136 137 private final List<String> modulePathArgs; 138 139 private final static String GOOD_PATH = "@GoodPath@"; 140 private final static String EMPTY_DIR = "@EmptyDir@"; 141 private final static String NON_EXISTING_DIR = "@NonExistingDir@"; 142 } |