jdk/test/tools/launcher/modules/patch/systemmodules/PatchSystemModules.java
changeset 45355 619076d3686a
parent 45004 ea3137042a61
child 45384 457aa401b59a
equal deleted inserted replaced
45354:47b01400f779 45355:619076d3686a
    49 
    49 
    50 public class PatchSystemModules {
    50 public class PatchSystemModules {
    51     private static final String JAVA_HOME = System.getProperty("java.home");
    51     private static final String JAVA_HOME = System.getProperty("java.home");
    52 
    52 
    53     private static final Path TEST_SRC = Paths.get(System.getProperty("test.src"));
    53     private static final Path TEST_SRC = Paths.get(System.getProperty("test.src"));
    54     private static final Path PATCH_SRC_DIR = TEST_SRC.resolve("src1");
       
    55 
    54 
    56     private static final Path JMODS = Paths.get(JAVA_HOME, "jmods");
    55     private static final Path JMODS = Paths.get(JAVA_HOME, "jmods");
    57     private static final Path MODS_DIR = Paths.get("mods");
    56     private static final Path MODS_DIR = Paths.get("mods");
    58     private static final Path JARS_DIR = Paths.get("jars");
    57     private static final Path JARS_DIR = Paths.get("jars");
    59     private static final Path PATCH_DIR = Paths.get("patches");
    58     private static final Path PATCH_DIR = Paths.get("patches");
    64     private final String[] modules = new String[] { "m1", "m2" };
    63     private final String[] modules = new String[] { "m1", "m2" };
    65 
    64 
    66     @BeforeTest
    65     @BeforeTest
    67     private void setup() throws Throwable {
    66     private void setup() throws Throwable {
    68         Path src = TEST_SRC.resolve("src");
    67         Path src = TEST_SRC.resolve("src");
       
    68         Path src1 = TEST_SRC.resolve("src1");
       
    69 
    69         for (String name : modules) {
    70         for (String name : modules) {
    70             assertTrue(CompilerUtils.compile(src.resolve(name),
    71             assertTrue(CompilerUtils.compile(src.resolve(name),
    71                                              MODS_DIR,
    72                                              MODS_DIR,
    72                                              "--module-source-path", src.toString()));
    73                                              "--module-source-path", src.toString()));
    73         }
    74         }
    74 
    75 
    75         // compile patched source
    76         // compile patched source
    76         String patchDir = PATCH_SRC_DIR.resolve(JAVA_BASE).toString();
    77         String patchDir = src1.resolve(JAVA_BASE).toString();
    77         assertTrue(CompilerUtils.compile(PATCH_SRC_DIR.resolve(JAVA_BASE),
    78         assertTrue(CompilerUtils.compile(src1.resolve(JAVA_BASE),
    78                                          PATCH_DIR.resolve(JAVA_BASE),
    79                                          PATCH_DIR.resolve(JAVA_BASE),
    79                                          "--patch-module", "java.base=" + patchDir));
    80                                          "--patch-module", "java.base=" + patchDir));
    80         assertTrue(CompilerUtils.compile(PATCH_SRC_DIR.resolve("m2"),
    81         assertTrue(CompilerUtils.compile(src1.resolve("m2"),
    81                                          PATCH_DIR.resolve("m2")));
    82                                          PATCH_DIR.resolve("m2")));
    82 
    83 
    83         createJars();
    84         createJars();
    84 
    85 
    85         // create an image with only m1 and m2
    86         // create an image with only m1 and m2
    86         if (Files.exists(JMODS)) {
    87         if (Files.exists(JMODS)) {
    87             // create an image with m1,m2
    88             // create an image with m1,m2
    88             createImage();
    89             createImage();
    89         }
    90         }
    90 
    91 
    91         // create new copy of m1.jar
    92         // compile a different version of m1
       
    93         Path tmp = Paths.get("tmp");
       
    94         assertTrue(CompilerUtils.compile(src1.resolve("m1"), tmp,
       
    95                                          "--module-path", MODS_DIR.toString(),
       
    96                                          "--module-source-path", src1.toString()));
       
    97 
       
    98         // package new_m1.jar
    92         jar("--create",
    99         jar("--create",
    93             "--file=" + NEW_M1_JAR.toString(),
   100             "--file=" + NEW_M1_JAR.toString(),
    94             "-C", MODS_DIR.resolve("m1").toString(), ".");
   101             "-C", tmp.resolve("m1").toString(), ".");
    95     }
   102     }
    96 
   103 
    97     /*
   104     /*
    98      * Test patching system module and user module on module path
   105      * Test patching system module and user module on module path
    99      */
   106      */
   148             return;
   155             return;
   149 
   156 
   150         // Fail to upgrade m1.jar with mismatched hash
   157         // Fail to upgrade m1.jar with mismatched hash
   151         runTestWithExitCode(getJava(IMAGE),
   158         runTestWithExitCode(getJava(IMAGE),
   152                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   159                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   153                 "-m", "m1/p1.Main", "ShouldNeverRun");
   160                 "-m", "m1/p1.Main");
   154 
   161 
   155         // test when SystemModules fast path is not enabled, i.e. exploded image
   162         // test when SystemModules fast path is not enabled, i.e. exploded image
   156         runTestWithExitCode(getJava(IMAGE),
   163         runTestWithExitCode(getJava(IMAGE),
   157                 "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
   164                 "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
   158                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   165                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   159                 "-m", "m1/p1.Main", "ShouldNeverRun");
   166                 "-m", "m1/p1.Main");
   160     }
   167     }
   161 
   168 
   162     /*
   169     /*
   163      * Test a module linked in a system hashed in ModuleHashes attribute
   170      * Test a module linked in a system hashed in ModuleHashes attribute
   164      * cannot be upgraded combining with --patch-module and --upgrade-module-path
   171      * cannot be upgraded combining with --patch-module and --upgrade-module-path
   171         // --patch-module does not disable hash check.
   178         // --patch-module does not disable hash check.
   172         // Test that a hashed module cannot be upgraded.
   179         // Test that a hashed module cannot be upgraded.
   173         runTestWithExitCode(getJava(IMAGE),
   180         runTestWithExitCode(getJava(IMAGE),
   174                 "--patch-module", "m1=.jar",
   181                 "--patch-module", "m1=.jar",
   175                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   182                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   176                 "-m", "m1/p1.Main", "ShouldNeverRun");
   183                 "-m", "m1/p1.Main");
   177 
   184 
   178         // test when SystemModules fast path is not enabled, i.e. exploded image
   185         // test when SystemModules fast path is not enabled, i.e. exploded image
   179         runTestWithExitCode(getJava(IMAGE),
   186         runTestWithExitCode(getJava(IMAGE),
   180                 "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
   187                 "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
   181                 "--patch-module", "m1=.jar",
   188                 "--patch-module", "m1=.jar",
   182                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   189                 "--upgrade-module-path", NEW_M1_JAR.toString(),
   183                 "-m", "m1/p1.Main", "ShouldNeverRun");
   190                 "-m", "m1/p1.Main");
   184     }
   191     }
   185 
   192 
   186     private void runTestWithExitCode(String... options) throws Throwable {
   193     private void runTestWithExitCode(String... options) throws Throwable {
   187         assertTrue(executeCommand(options)
   194         assertTrue(executeCommand(options)
   188                         .outputTo(System.out)
   195                         .outputTo(System.out)