1 /* |
1 /* |
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
27 * @requires vm.cds |
27 * @requires vm.cds |
28 * @library /test/lib /test/hotspot/jtreg/runtime/appcds |
28 * @library /test/lib /test/hotspot/jtreg/runtime/appcds |
29 * @modules jdk.compiler |
29 * @modules jdk.compiler |
30 * jdk.jartool/sun.tools.jar |
30 * jdk.jartool/sun.tools.jar |
31 * jdk.jlink |
31 * jdk.jlink |
32 * @run driver MainModuleOnly |
32 * @run main/othervm MainModuleOnly |
33 * @summary Test some scenarios with a main modular jar specified in the --module-path and -cp options in the command line. |
33 * @summary Test some scenarios with a main modular jar specified in the --module-path and -cp options in the command line. |
34 */ |
34 */ |
35 |
35 |
36 import java.io.File; |
36 import java.io.File; |
37 import java.nio.file.Files; |
37 import java.nio.file.Files; |
38 import java.nio.file.Path; |
38 import java.nio.file.Path; |
39 import java.nio.file.Paths; |
39 import java.nio.file.Paths; |
40 import java.util.Arrays; |
40 import java.util.Arrays; |
41 |
41 |
|
42 import jdk.test.lib.cds.CDSTestUtils.Result; |
42 import jdk.test.lib.process.OutputAnalyzer; |
43 import jdk.test.lib.process.OutputAnalyzer; |
43 import jdk.test.lib.Platform; |
44 import jdk.test.lib.Platform; |
44 |
45 |
45 public class MainModuleOnly { |
46 public class MainModuleOnly { |
46 |
47 |
58 private static final String MAIN_CLASS = "com.simple.Main"; |
59 private static final String MAIN_CLASS = "com.simple.Main"; |
59 |
60 |
60 private static Path moduleDir = null; |
61 private static Path moduleDir = null; |
61 private static Path moduleDir2 = null; |
62 private static Path moduleDir2 = null; |
62 private static Path destJar = null; |
63 private static Path destJar = null; |
|
64 |
|
65 private static final String jarFileError = "A jar file is not the one used while building the shared archive file:"; |
63 |
66 |
64 public static void buildTestModule() throws Exception { |
67 public static void buildTestModule() throws Exception { |
65 |
68 |
66 // javac -d mods/$TESTMODULE --module-path MOD_DIR src/$TESTMODULE/** |
69 // javac -d mods/$TESTMODULE --module-path MOD_DIR src/$TESTMODULE/** |
67 JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE1), |
70 JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE1), |
165 // modify the timestamp of the jar file |
168 // modify the timestamp of the jar file |
166 (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000); |
169 (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000); |
167 // run with the archive and the jar with modified timestamp. |
170 // run with the archive and the jar with modified timestamp. |
168 // It should fail due to timestamp of the jar doesn't match the one |
171 // It should fail due to timestamp of the jar doesn't match the one |
169 // used during dump time. |
172 // used during dump time. |
170 TestCommon.run("-cp", destJar.toString(), |
173 Result res = TestCommon.run("-cp", destJar.toString(), |
171 "--module-path", moduleDir.toString(), |
174 "-Xlog:cds", |
172 "-m", TEST_MODULE1) |
175 "--module-path", moduleDir.toString(), |
173 .assertAbnormalExit( |
176 "-m", TEST_MODULE1); |
174 "A jar file is not the one used while building the shared archive file:"); |
177 res.assertAbnormalExit(jarFileError); |
175 // create an archive with a non-empty directory in the --module-path. |
178 // create an archive with a non-empty directory in the --module-path. |
176 // The dumping process will exit with an error due to non-empty directory |
179 // The dumping process will exit with an error due to non-empty directory |
177 // in the --module-path. |
180 // in the --module-path. |
|
181 String mainModule = TEST_MODULE1; |
|
182 if (TestCommon.isDynamicArchive()) { |
|
183 mainModule += "/" + MAIN_CLASS; |
|
184 } |
178 output = TestCommon.createArchive(destJar.toString(), appClasses, |
185 output = TestCommon.createArchive(destJar.toString(), appClasses, |
179 "--module-path", MODS_DIR.toString(), |
186 "--module-path", MODS_DIR.toString(), |
180 "-m", TEST_MODULE1); |
187 "-m", mainModule); |
181 output.shouldHaveExitValue(1) |
188 output.shouldHaveExitValue(1) |
182 .shouldMatch("Error: non-empty directory.*com.simple"); |
189 .shouldMatch("Error: non-empty directory.*com.simple"); |
183 |
190 |
184 // test module path with very long length |
191 // test module path with very long length |
185 // |
192 // |