35 * @compile src/com/sun/tools/javac/MyMain.jasm 36 * @compile ../../../SharedArchiveFile/javax/annotation/processing/FilerException.jasm 37 * @run main ClassPathTests 38 * @summary AppCDS tests for testing classpath/package conflicts 39 */ 40 41 /* 42 * These tests will verify that AppCDS will correctly handle archived classes 43 * on the classpath that are in a package that is also exported by the jimage. 44 * These classes should fail to load unless --limit-modules is used to hide the 45 * package exported by the jimage. There are 8 variants of this test: 46 * - With a jimage app package and with a jimage ext package 47 * - With --limit-modules and without --limit-modules 48 * - With AppCDS and without AppCDS (to verify behaviour is the same for both). 49 * 50 * There is also a 9th test to verify that when --limit-modules is used, a jimage 51 * class in the archive can be replaced by a classpath class with the 52 * same name and package. 53 */ 54 55 import java.lang.reflect.Method; 56 import java.nio.file.Path; 57 import java.nio.file.Paths; 58 59 import jdk.test.lib.Asserts; 60 import jdk.test.lib.cds.CDSOptions; 61 import jdk.test.lib.cds.CDSTestUtils; 62 import jdk.test.lib.process.ProcessTools; 63 import jdk.test.lib.process.OutputAnalyzer; 64 65 66 public class ClassPathTests { 67 private static final String TEST_SRC = System.getProperty("test.src"); 68 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 69 private static final Path CLASSES_DIR = Paths.get("classes"); 70 71 // the test module 72 private static final String MAIN_CLASS = "jdk.test.Main"; 73 private static final String LIMITMODS_MAIN_CLASS = "jdk.test.LimitModsMain"; 74 75 // test classes to archive. These are both in UPGRADED_MODULES 76 private static final String JIMAGE_CLASS = "com/sun/tools/javac/Main"; 77 private static final String APP_ARCHIVE_CLASS = "com/sun/tools/javac/MyMain"; 78 private static final String PLATFORM_ARCHIVE_CLASS = "javax/annotation/processing/FilerException"; 79 private static final String[] ARCHIVE_CLASSES = {APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS, JIMAGE_CLASS}; 80 private static final int NUMBER_OF_TEST_CASES = 10; 81 82 private static String appJar; 83 private static String testArchiveName; 84 85 86 public static void main(String[] args) throws Exception { 87 ClassPathTests tests = new ClassPathTests(); 88 tests.dumpArchive(); 89 90 Method[] methods = tests.getClass().getDeclaredMethods(); 91 int numOfTestMethodsRun = 0; 92 for (Method m : methods) { 93 if (m.getName().startsWith("test")) { 94 System.out.println("About to run test method: " + m.getName()); 95 m.invoke(tests); 96 numOfTestMethodsRun++; 97 } 98 } 99 100 Asserts.assertTrue((numOfTestMethodsRun == NUMBER_OF_TEST_CASES), 101 "Expected " + NUMBER_OF_TEST_CASES + " test methods to run, actual number is " 102 + numOfTestMethodsRun); 103 } 104 105 private void dumpArchive() throws Exception { 106 // Create a jar file with all the classes related to this test. 107 JarBuilder.build( "classpathtests", 108 APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS, JIMAGE_CLASS, 109 "jdk/test/Main"); 110 appJar = TestCommon.getTestJar("classpathtests.jar"); 111 112 // dump the archive with altnernate jdk.comiler and jdk.activation classes in the class list 113 OutputAnalyzer output1 = TestCommon.dump(appJar, TestCommon.list(ARCHIVE_CLASSES)); 114 TestCommon.checkDump(output1); 115 // The PLATFORM_ARCHIVE_CLASS belongs to the java.compiler | 35 * @compile src/com/sun/tools/javac/MyMain.jasm 36 * @compile ../../../SharedArchiveFile/javax/annotation/processing/FilerException.jasm 37 * @run main ClassPathTests 38 * @summary AppCDS tests for testing classpath/package conflicts 39 */ 40 41 /* 42 * These tests will verify that AppCDS will correctly handle archived classes 43 * on the classpath that are in a package that is also exported by the jimage. 44 * These classes should fail to load unless --limit-modules is used to hide the 45 * package exported by the jimage. There are 8 variants of this test: 46 * - With a jimage app package and with a jimage ext package 47 * - With --limit-modules and without --limit-modules 48 * - With AppCDS and without AppCDS (to verify behaviour is the same for both). 49 * 50 * There is also a 9th test to verify that when --limit-modules is used, a jimage 51 * class in the archive can be replaced by a classpath class with the 52 * same name and package. 53 */ 54 55 import java.lang.reflect.InvocationTargetException; 56 import java.lang.reflect.Method; 57 import java.nio.file.Path; 58 import java.nio.file.Paths; 59 60 import jdk.test.lib.Asserts; 61 import jdk.test.lib.cds.CDSOptions; 62 import jdk.test.lib.cds.CDSTestUtils; 63 import jdk.test.lib.process.ProcessTools; 64 import jdk.test.lib.process.OutputAnalyzer; 65 66 import jtreg.SkippedException; 67 68 69 public class ClassPathTests { 70 private static final String TEST_SRC = System.getProperty("test.src"); 71 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 72 private static final Path CLASSES_DIR = Paths.get("classes"); 73 74 // the test module 75 private static final String MAIN_CLASS = "jdk.test.Main"; 76 private static final String LIMITMODS_MAIN_CLASS = "jdk.test.LimitModsMain"; 77 78 // test classes to archive. These are both in UPGRADED_MODULES 79 private static final String JIMAGE_CLASS = "com/sun/tools/javac/Main"; 80 private static final String APP_ARCHIVE_CLASS = "com/sun/tools/javac/MyMain"; 81 private static final String PLATFORM_ARCHIVE_CLASS = "javax/annotation/processing/FilerException"; 82 private static final String[] ARCHIVE_CLASSES = {APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS, JIMAGE_CLASS}; 83 private static final int NUMBER_OF_TEST_CASES = 10; 84 85 private static String appJar; 86 private static String testArchiveName; 87 88 89 public static void main(String[] args) throws Exception { 90 ClassPathTests tests = new ClassPathTests(); 91 tests.dumpArchive(); 92 93 Method[] methods = tests.getClass().getDeclaredMethods(); 94 int numOfTestMethodsRun = 0; 95 for (Method m : methods) { 96 if (m.getName().startsWith("test")) { 97 System.out.println("About to run test method: " + m.getName()); 98 try { 99 m.invoke(tests); 100 } catch (InvocationTargetException ite) { 101 if (ite.getCause() instanceof SkippedException) { 102 System.out.println("Test PASSED: " + ite.getCause().getMessage()); 103 } else { 104 throw ite; 105 } 106 } 107 numOfTestMethodsRun++; 108 } 109 } 110 111 Asserts.assertTrue((numOfTestMethodsRun == NUMBER_OF_TEST_CASES), 112 "Expected " + NUMBER_OF_TEST_CASES + " test methods to run, actual number is " 113 + numOfTestMethodsRun); 114 } 115 116 private void dumpArchive() throws Exception { 117 // Create a jar file with all the classes related to this test. 118 JarBuilder.build( "classpathtests", 119 APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS, JIMAGE_CLASS, 120 "jdk/test/Main"); 121 appJar = TestCommon.getTestJar("classpathtests.jar"); 122 123 // dump the archive with altnernate jdk.comiler and jdk.activation classes in the class list 124 OutputAnalyzer output1 = TestCommon.dump(appJar, TestCommon.list(ARCHIVE_CLASSES)); 125 TestCommon.checkDump(output1); 126 // The PLATFORM_ARCHIVE_CLASS belongs to the java.compiler |