7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 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 /** 25 * @test 26 * @library ../../lib /lib/testlibrary 27 * @build OverlappingPackagesTest CompilerUtils 28 * @run testng OverlappingPackagesTest 29 * @summary Basic test to ensure that startup fails if two or more modules 30 * in the boot Layer have the same package 31 */ 32 33 import java.nio.file.Path; 34 import java.nio.file.Paths; 35 import java.util.Arrays; 36 import java.util.List; 37 38 import static jdk.testlibrary.ProcessTools.*; 39 40 import org.testng.annotations.BeforeTest; 41 import org.testng.annotations.Test; 42 import static org.testng.Assert.*; 43 44 @Test 45 public class OverlappingPackagesTest { 46 47 private static final String TEST_SRC = System.getProperty("test.src"); 48 49 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 50 private static final Path MODS_DIR = Paths.get("mods"); 51 52 // the names of the modules in this test 53 private static List<String> modules = Arrays.asList("m1", "m2", "misc", "test"); 54 55 56 /** 57 * Compiles all modules used by the test 58 */ 59 @BeforeTest 60 public void compileAll() throws Exception { 61 for (String mn : modules) { 62 Path src = SRC_DIR.resolve(mn); 63 Path mods = MODS_DIR.resolve(mn); 64 assertTrue(CompilerUtils.compile(src, mods)); 65 } 66 } 67 68 /** 69 * Sanity check that the test runs without error. 70 */ 71 public void testNoOverlappingPackages() throws Exception { 72 int exitValue 73 = executeTestJava("-mp", MODS_DIR.toString(), 74 "-m", "test/test.Main") 75 .outputTo(System.out) 76 .errorTo(System.err) 77 .getExitValue(); 78 79 assertTrue(exitValue == 0); 80 } 81 82 83 /** 84 * Run the test with "-addmods misc", the misc module has package 85 * sun.misc and so should overlap with the base module. 86 */ 87 public void testOverlapWithBaseModule() throws Exception { 88 int exitValue 89 = executeTestJava("-mp", MODS_DIR.toString(), 90 "-addmods", "misc", 91 "-m", "test/test.Main") 92 .outputTo(System.out) 93 .errorTo(System.err) 94 .getExitValue(); 95 96 assertTrue(exitValue != 0); 97 } 98 99 /** 100 * Run the test with "-addmods m1,m2". Both modules have package p. 101 */ 102 public void testOverlap() throws Exception { 103 int exitValue 104 = executeTestJava("-mp", MODS_DIR.toString(), 105 "-addmods", "m1,m2", 106 "-m", "test/test.Main") 107 .outputTo(System.out) 108 .errorTo(System.err) 109 .getExitValue(); 110 111 assertTrue(exitValue != 0); 112 } 113 114 115 } | 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 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 /** 25 * @test 26 * @library ../../lib /lib/testlibrary 27 * @build OverlappingPackagesTest CompilerUtils jdk.testlibrary.OutputAnalyzer 28 * @run testng OverlappingPackagesTest 29 * @summary Basic test to ensure that startup fails if two or more modules 30 * in the boot Layer have the same package. Startup is not supposed 31 * to fail if there is a package name duplication with/on the unnamed 32 * module. 33 */ 34 35 import java.io.File; 36 import java.nio.file.Path; 37 import java.nio.file.Paths; 38 import java.util.Arrays; 39 import java.util.List; 40 import java.util.regex.Pattern; 41 42 import static jdk.testlibrary.ProcessTools.*; 43 44 import org.testng.annotations.BeforeTest; 45 import org.testng.annotations.Test; 46 import static org.testng.Assert.*; 47 48 import jdk.testlibrary.OutputAnalyzer; 49 50 @Test 51 public class OverlappingPackagesTest { 52 53 private static final String TEST_SRC = System.getProperty("test.src"); 54 55 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 56 private static final Path MODS_DIR = Paths.get("mods"); 57 58 // the names of the modules in this test 59 private static final List<String> modules = Arrays.asList("m1", "m2", 60 "misc", "test"); 61 62 /** 63 * Compiles all modules used by the test 64 */ 65 @BeforeTest 66 public void compileAll() throws Exception { 67 for (String mn : modules) { 68 Path src = SRC_DIR.resolve(mn); 69 Path mods = MODS_DIR.resolve(mn); 70 assertTrue(CompilerUtils.compile(src, mods)); 71 } 72 } 73 74 /** 75 * Sanity check that the test runs without error. 76 */ 77 public void testNoOverlappingPackages() throws Exception { 78 int exitValue 79 = executeTestJava("-mp", MODS_DIR.toString(), 80 "-m", "test/test.Main") 81 .outputTo(System.out) 82 .errorTo(System.err) 83 .getExitValue(); 84 assertTrue(exitValue == 0); 85 } 86 87 88 /** 89 * Run the test with "-addmods misc", the misc module has package 90 * sun.misc and so should overlap with the base module. 91 */ 92 public void testOverlapWithBaseModule() throws Exception { 93 OutputAnalyzer output 94 = executeTestJava("-mp", MODS_DIR.toString(), 95 "-addmods", "misc", 96 "-m", "test/test.Main") 97 .outputTo(System.out) 98 .errorTo(System.err); 99 output.shouldContain("Module misc contains package sun.misc, " + 100 "module java.base exports package sun.misc to misc"); 101 assertTrue(output.getExitValue() != 0); 102 } 103 104 /** 105 * Run the test with "-addmods m1,m2". Both modules have package p. 106 */ 107 public void testOverlap() throws Exception { 108 OutputAnalyzer output 109 = executeTestJava("-mp", MODS_DIR.toString(), 110 "-addmods", "m1,m2", 111 "-m", "test/test.Main") 112 .outputTo(System.out) 113 .errorTo(System.err); 114 String errorText = "Package p in both module m. and module m."; 115 if(!Pattern.compile(errorText).matcher(output.getOutput()).find()) { 116 fail("Output does not contain expected error: \"" + 117 errorText + "\""); 118 } 119 assertTrue(output.getExitValue() != 0); 120 } 121 122 /** 123 * Run the test with m1 being on the modulepath. m1 module has package p. 124 * Package p is also present on the classpath. 125 */ 126 public void testOverlapWithClasspath() throws Exception { 127 int exitValue 128 = executeTestJava("-mp", MODS_DIR.toString(), 129 "-classpath", MODS_DIR.resolve("m1").toString(), 130 "-addmods", "m2", 131 "-m", "test/test.Main") 132 .outputTo(System.out) 133 .errorTo(System.err) 134 .getExitValue(); 135 assertTrue(exitValue == 0); 136 } 137 138 /** 139 * Run with package p present two times on the classpath. 140 */ 141 public void testOverlapWithDupsOnClasspath() throws Exception { 142 String cp = MODS_DIR.resolve("m1").toString() + File.pathSeparator + 143 MODS_DIR.resolve("m2"); 144 int exitValue 145 = executeTestJava("-mp", MODS_DIR.toString(), 146 "-classpath", cp, 147 "-m", "test/test.Main") 148 .outputTo(System.out) 149 .errorTo(System.err) 150 .getExitValue(); 151 assertTrue(exitValue == 0); 152 } 153 } |