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 31 */ 32 33 import java.io.File; 34 import java.nio.file.Path; 35 import java.nio.file.Paths; 36 import java.nio.file.Files; 37 import java.util.Arrays; 38 import java.util.List; 39 40 import static jdk.testlibrary.ProcessTools.*; 41 42 import org.testng.annotations.BeforeTest; 43 import org.testng.annotations.Test; 44 import static org.testng.Assert.*; 45 46 import jdk.testlibrary.OutputAnalyzer; 47 48 @Test 49 public class OverlappingPackagesTest { 50 51 private static final String TEST_SRC = System.getProperty("test.src"); 52 53 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 54 private static final Path MODS_DIR = Paths.get("mods"); 55 56 // the names of the modules in this test 57 private static List<String> modules = Arrays.asList("m1", "m2", "misc", 58 "test"); 59 60 private static final String DUP_P_MSG = "Package p in both module m2 and " + 61 "module m1"; 62 63 64 /** 65 * Compiles all modules used by the test 66 */ 67 @BeforeTest 68 public void compileAll() throws Exception { 69 for (String mn : modules) { 70 Path src = SRC_DIR.resolve(mn); 71 Path mods = MODS_DIR.resolve(mn); 72 assertTrue(CompilerUtils.compile(src, mods)); 73 } 74 } 75 76 /** 77 * Sanity check that the test runs without error. 78 */ 79 public void testNoOverlappingPackages() throws Exception { 80 int exitValue 81 = executeTestJava("-mp", MODS_DIR.toString(), 82 "-m", "test/test.Main") 83 .outputTo(System.out) 84 .errorTo(System.err) 85 .getExitValue(); 86 87 assertTrue(exitValue == 0); 88 } 89 90 91 /** 92 * Run the test with "-addmods misc", the misc module has package 93 * sun.misc and so should overlap with the base module. 94 */ 95 public void testOverlapWithBaseModule() throws Exception { 96 OutputAnalyzer output 97 = executeTestJava("-mp", MODS_DIR.toString(), 98 "-addmods", "misc", 99 "-m", "test/test.Main") 100 .outputTo(System.out) 101 .errorTo(System.err); 102 output.shouldContain("Module misc contains package sun.misc, " + 103 "module java.base exports package sun.misc to misc"); 104 assertTrue(output.getExitValue() != 0); 105 } 106 107 /** 108 * Run the test with "-addmods m1,m2". Both modules have package p. 109 */ 110 public void testOverlap() throws Exception { 111 OutputAnalyzer output 112 = executeTestJava("-mp", MODS_DIR.toString(), 113 "-addmods", "m1,m2", 114 "-m", "test/test.Main") 115 .outputTo(System.out) 116 .errorTo(System.err); 117 output.shouldContain(DUP_P_MSG); 118 assertTrue(output.getExitValue() != 0); 119 } 120 121 /** 122 * Run the test with m1 being on the modulepath. m1 module has package p. 123 * Package p is also present on the classpath. 124 */ 125 public void testOverlapWithClasspath() throws Exception { 126 int exitValue 127 = executeTestJava("-mp", MODS_DIR.toString(), 128 "-classpath", MODS_DIR.resolve("m1").toString(), 129 "-addmods", "m2", 130 "-m", "test/test.Main") 131 .outputTo(System.out) 132 .errorTo(System.err) 133 .getExitValue(); 134 assertTrue(exitValue == 0); 135 } 136 137 /** 138 * Run with package p present two times on the classpath. 139 */ 140 public void testOverlapWithDupsOnClasspath() throws Exception { 141 String cp = MODS_DIR.resolve("m1").toString() + File.pathSeparator + 142 MODS_DIR.resolve("m2"); 143 int exitValue 144 = executeTestJava("-mp", MODS_DIR.toString(), 145 "-classpath", cp, 146 "-m", "test/test.Main") 147 .outputTo(System.out) 148 .errorTo(System.err) 149 .getExitValue(); 150 assertTrue(exitValue == 0); 151 } 152 153 /** 154 * Run the test with "-addmods m1,m2" with one of the modules being 155 * on the module path and the other one - on the upgrade module path. 156 * Both modules have package p. 157 */ 158 public void testOverlapUpgratePath() throws Exception { 159 Path upgradePath = Paths.get("up"); 160 Path dest = upgradePath.resolve("m1"); 161 Files.createDirectories(upgradePath); 162 Path src = MODS_DIR.resolve("m1"); 163 Files.move(src, dest); 164 try { 165 OutputAnalyzer output 166 = executeTestJava("-mp", MODS_DIR.toString(), 167 "-upgrademodulepath", upgradePath.toString(), 168 "-addmods", "m1,m2", 169 "-m", "test/test.Main") 170 .outputTo(System.out) 171 .errorTo(System.err); 172 output.shouldContain(DUP_P_MSG); 173 assertTrue(output.getExitValue() != 0); 174 } finally { 175 Files.move(dest, src); 176 } 177 } 178 } |