1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 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 }