--- a/jdk/test/tools/launcher/modules/patch/systemmodules/PatchSystemModules.java Mon Apr 24 13:43:34 2017 +0800
+++ b/jdk/test/tools/launcher/modules/patch/systemmodules/PatchSystemModules.java Thu May 04 07:26:55 2017 +0000
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,8 @@
/*
* @test
- * @bug 8157068
- * @summary Patch java.base and user module with Hashes attribute tied with
- * other module.
+ * @bug 8157068 8177844
+ * @summary Patch java.base and user module with ModuleHashes attribute
* @library /lib/testlibrary
* @modules jdk.compiler
* @build CompilerUtils
@@ -59,6 +58,7 @@
private static final Path JARS_DIR = Paths.get("jars");
private static final Path PATCH_DIR = Paths.get("patches");
private static final Path IMAGE = Paths.get("image");
+ private static final Path NEW_M1_JAR = JARS_DIR.resolve("new_m1.jar");
private static final String JAVA_BASE = "java.base";
private final String[] modules = new String[] { "m1", "m2" };
@@ -80,13 +80,23 @@
assertTrue(CompilerUtils.compile(PATCH_SRC_DIR.resolve("m2"),
PATCH_DIR.resolve("m2")));
+ createJars();
+
// create an image with only m1 and m2
if (Files.exists(JMODS)) {
// create an image with m1,m2
createImage();
}
+
+ // create new copy of m1.jar
+ jar("--create",
+ "--file=" + NEW_M1_JAR.toString(),
+ "-C", MODS_DIR.resolve("m1").toString(), ".");
}
+ /*
+ * Test patching system module and user module on module path
+ */
@Test
public void test() throws Throwable {
Path patchedJavaBase = PATCH_DIR.resolve(JAVA_BASE);
@@ -107,6 +117,9 @@
"-m", "m1/p1.Main", "2");
}
+ /*
+ * Test --patch-module on a custom image
+ */
@Test
public void testImage() throws Throwable {
if (Files.notExists(JMODS))
@@ -125,27 +138,49 @@
"-m", "m1/p1.Main", "2");
}
+ /*
+ * Test a module linked in a system hashed in ModuleHashes attribute
+ * cannot be upgraded
+ */
@Test
- public void upgradeTiedModule() throws Throwable {
+ public void upgradeHashedModule() throws Throwable {
if (Files.notExists(JMODS))
return;
- Path m1 = MODS_DIR.resolve("m1.jar");
-
- // create another m1.jar
- jar("--create",
- "--file=" + m1.toString(),
- "-C", MODS_DIR.resolve("m1").toString(), ".");
-
// Fail to upgrade m1.jar with mismatched hash
runTestWithExitCode(getJava(IMAGE),
- "--upgrade-module-path", m1.toString(),
- "-m", "m1/p1.Main");
+ "--upgrade-module-path", NEW_M1_JAR.toString(),
+ "-m", "m1/p1.Main", "ShouldNeverRun");
+ // test when SystemModules fast path is not enabled, i.e. exploded image
runTestWithExitCode(getJava(IMAGE),
"--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
- "--upgrade-module-path", m1.toString(),
- "-m", "m1/p1.Main", "1");
+ "--upgrade-module-path", NEW_M1_JAR.toString(),
+ "-m", "m1/p1.Main", "ShouldNeverRun");
+ }
+
+ /*
+ * Test a module linked in a system hashed in ModuleHashes attribute
+ * cannot be upgraded combining with --patch-module and --upgrade-module-path
+ */
+ @Test
+ public void patchHashedModule() throws Throwable {
+ if (Files.notExists(JMODS))
+ return;
+
+ // --patch-module does not disable hash check.
+ // Test that a hashed module cannot be upgraded.
+ runTestWithExitCode(getJava(IMAGE),
+ "--patch-module", "m1=.jar",
+ "--upgrade-module-path", NEW_M1_JAR.toString(),
+ "-m", "m1/p1.Main", "ShouldNeverRun");
+
+ // test when SystemModules fast path is not enabled, i.e. exploded image
+ runTestWithExitCode(getJava(IMAGE),
+ "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
+ "--patch-module", "m1=.jar",
+ "--upgrade-module-path", NEW_M1_JAR.toString(),
+ "-m", "m1/p1.Main", "ShouldNeverRun");
}
private void runTestWithExitCode(String... options) throws Throwable {
@@ -171,9 +206,8 @@
assertTrue(exitValue == 0);
}
- static void createImage() throws Throwable {
+ static void createJars() throws Throwable {
FileUtils.deleteFileTreeUnchecked(JARS_DIR);
- FileUtils.deleteFileTreeUnchecked(IMAGE);
Files.createDirectories(JARS_DIR);
Path m1 = JARS_DIR.resolve("m1.jar");
@@ -189,7 +223,10 @@
"--module-path", JARS_DIR.toString(),
"--hash-modules", "m1",
"-C", MODS_DIR.resolve("m2").toString(), ".");
+ }
+ static void createImage() throws Throwable {
+ FileUtils.deleteFileTreeUnchecked(IMAGE);
String mpath = JARS_DIR.toString() + File.pathSeparator + JMODS.toString();
execTool("jlink", "--module-path", mpath,