test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/AddModules.java
changeset 54927 1512d88b24c6
parent 53636 962ed57b29c9
equal deleted inserted replaced
54926:d4e7ccaf1445 54927:1512d88b24c6
    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  * @compile ../../test-classes/Hello.java
    32  * @run driver AddModules
    33  * @run driver AddModules
    33  * @summary sanity test the --add-modules option
    34  * @summary sanity test the --add-modules option
    34  */
    35  */
    35 
    36 
    36 import java.io.File;
    37 import java.io.File;
    61 
    62 
    62     private static Path moduleDir = null;
    63     private static Path moduleDir = null;
    63     private static Path subJar = null;
    64     private static Path subJar = null;
    64     private static Path mainJar1 = null;
    65     private static Path mainJar1 = null;
    65     private static Path mainJar2 = null;
    66     private static Path mainJar2 = null;
       
    67     private static String appJar;
    66 
    68 
    67     public static void buildTestModule() throws Exception {
    69     public static void buildTestModule() throws Exception {
    68 
    70 
    69         // javac -d mods/$TESTMODULE src/$TESTMODULE/**
    71         // javac -d mods/$TESTMODULE src/$TESTMODULE/**
    70         JarBuilder.compileModule(SRC_DIR.resolve(SUB_MODULE),
    72         JarBuilder.compileModule(SRC_DIR.resolve(SUB_MODULE),
    94         JarBuilder.createModularJar(mainJar2.toString(), classes, MAIN_CLASS2);
    96         JarBuilder.createModularJar(mainJar2.toString(), classes, MAIN_CLASS2);
    95 
    97 
    96     }
    98     }
    97 
    99 
    98     public static void main(String... args) throws Exception {
   100     public static void main(String... args) throws Exception {
       
   101         appJar = JarBuilder.getOrCreateHelloJar();
    99         // compile the modules and create the modular jar files
   102         // compile the modules and create the modular jar files
   100         buildTestModule();
   103         buildTestModule();
   101         String appClasses[] = {MAIN_CLASS1, MAIN_CLASS2, APP_CLASS};
   104         String appClasses[] = {MAIN_CLASS1, MAIN_CLASS2, APP_CLASS};
   102         // create an archive with the classes in the modules built in the
   105         // create an archive with the classes in the modules built in the
   103         // previous step
   106         // previous step
   104         OutputAnalyzer output = TestCommon.createArchive(
   107         OutputAnalyzer output = TestCommon.createArchive(
   105                                         null, appClasses,
   108                                         appJar, appClasses,
   106                                         "--module-path", moduleDir.toString(),
   109                                         "--module-path", moduleDir.toString(),
   107                                         "--add-modules",
   110                                         "--add-modules",
   108                                         MAIN_MODULE1 + "," + MAIN_MODULE2);
   111                                         MAIN_MODULE1 + "," + MAIN_MODULE2);
   109         TestCommon.checkDump(output);
   112         TestCommon.checkDump(output);
   110         String prefix[] = {"-Djava.class.path=", "-Xlog:class+load=trace"};
   113         String prefix[] = {"-Djava.class.path=" + appJar, "-Xlog:class+load=trace"};
   111 
   114 
   112         // run the com.greetings module with the archive with the --module-path
   115         // run the com.greetings module with the archive with the --module-path
   113         // the same as the one during dump time.
   116         // the same as the one during dump time.
   114         // The classes should be loaded from the archive.
   117         // The classes should be loaded from the archive.
   115         TestCommon.runWithModules(prefix,
   118         TestCommon.runWithModules(prefix,