author | iignatyev |
Tue, 06 Jun 2017 19:54:08 -0700 | |
changeset 45393 | de4e1efc8eec |
parent 43734 | 64b58fc82d90 |
child 45944 | 882cea808912 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
45393 | 2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
|
45393 | 26 |
* @library /lib/testlibrary /test/lib |
36511 | 27 |
* @modules jdk.compiler |
45393 | 28 |
* @build PatchTest JarUtils jdk.testlibrary.* |
29 |
* jdk.test.lib.compiler.CompilerUtils |
|
36511 | 30 |
* @run testng PatchTest |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
31 |
* @summary Basic test for --patch-module |
36511 | 32 |
*/ |
33 |
||
34 |
import java.io.File; |
|
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.nio.file.Paths; |
|
38 |
import java.util.stream.Collectors; |
|
39 |
import java.util.stream.Stream; |
|
40 |
||
45393 | 41 |
import jdk.test.lib.compiler.CompilerUtils; |
36511 | 42 |
import static jdk.testlibrary.ProcessTools.*; |
43 |
||
44 |
import org.testng.annotations.BeforeTest; |
|
45 |
import org.testng.annotations.Test; |
|
46 |
import static org.testng.Assert.*; |
|
47 |
||
48 |
/** |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
49 |
* Compiles and launches a test that uses --patch-module with two directories |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
50 |
* of classes to override existing classes and add new classes to modules in |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
51 |
* the boot layer. |
36511 | 52 |
* |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
53 |
* The classes overridden or added via --patch-module all define a public |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
54 |
* no-arg constructor and override toString to return "hi". This allows the |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
55 |
* launched test to check that the overridden classes are loaded. |
36511 | 56 |
*/ |
57 |
||
58 |
@Test |
|
59 |
public class PatchTest { |
|
60 |
||
61 |
// top-level source directory |
|
62 |
private static final String TEST_SRC = System.getProperty("test.src"); |
|
63 |
||
64 |
// source/destination tree for the test module |
|
65 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
66 |
private static final Path MODS_DIR = Paths.get("mods"); |
|
67 |
||
68 |
// source/destination tree for patch tree 1 |
|
69 |
private static final Path SRC1_DIR = Paths.get(TEST_SRC, "src1"); |
|
70 |
private static final Path PATCHES1_DIR = Paths.get("patches1"); |
|
71 |
||
72 |
// source/destination tree for patch tree 2 |
|
73 |
private static final Path SRC2_DIR = Paths.get(TEST_SRC, "src2"); |
|
74 |
private static final Path PATCHES2_DIR = Paths.get("patches2"); |
|
75 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
76 |
// destination directory for patches packaged as JAR files |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
77 |
private static final Path PATCHES_DIR = Paths.get("patches"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
78 |
|
36511 | 79 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
80 |
// the classes overridden or added with --patch-module |
36511 | 81 |
private static final String[] CLASSES = { |
82 |
||
83 |
// java.base = boot loader |
|
84 |
"java.base/java.text.Annotation", // override class |
|
85 |
"java.base/java.text.AnnotationBuddy", // add class to package |
|
86 |
"java.base/java.lang2.Object", // new package |
|
87 |
||
88 |
// jdk.naming.dns = platform class loader |
|
89 |
"jdk.naming.dns/com.sun.jndi.dns.DnsClient", |
|
90 |
"jdk.naming.dns/com.sun.jndi.dns.DnsClientBuddy", |
|
91 |
"jdk.naming.dns/com.sun.jndi.dns2.Zone", |
|
92 |
||
93 |
// jdk.compiler = application class loaded |
|
94 |
"jdk.compiler/com.sun.tools.javac.Main", |
|
95 |
"jdk.compiler/com.sun.tools.javac.MainBuddy", |
|
96 |
"jdk.compiler/com.sun.tools.javac2.Main", |
|
97 |
||
98 |
}; |
|
99 |
||
100 |
||
101 |
@BeforeTest |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
102 |
public void setup() throws Exception { |
36511 | 103 |
|
104 |
// javac -d mods/test src/test/** |
|
105 |
boolean compiled= CompilerUtils.compile(SRC_DIR.resolve("test"), |
|
106 |
MODS_DIR.resolve("test")); |
|
107 |
assertTrue(compiled, "classes did not compile"); |
|
108 |
||
43734
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
109 |
// javac --patch-module $MODULE=patches1/$MODULE -d patches1/$MODULE patches1/$MODULE/** |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
110 |
// jar cf patches/$MODULE-1.jar -C patches1/$MODULE . |
36511 | 111 |
for (Path src : Files.newDirectoryStream(SRC1_DIR)) { |
112 |
Path output = PATCHES1_DIR.resolve(src.getFileName()); |
|
113 |
String mn = src.getFileName().toString(); |
|
43734
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
114 |
compiled = CompilerUtils.compile(src, output, |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
115 |
"--patch-module", mn + "=" + src.toString()); |
36511 | 116 |
assertTrue(compiled, "classes did not compile"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
117 |
JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-1.jar"), output); |
36511 | 118 |
} |
119 |
||
43734
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
120 |
// javac --patch-module $MODULE=patches2/$MODULE -d patches2/$MODULE patches2/$MODULE/** |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
121 |
// jar cf patches/$MODULE-2.jar -C patches2/$MODULE . |
36511 | 122 |
for (Path src : Files.newDirectoryStream(SRC2_DIR)) { |
123 |
Path output = PATCHES2_DIR.resolve(src.getFileName()); |
|
124 |
String mn = src.getFileName().toString(); |
|
43734
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
125 |
compiled = CompilerUtils.compile(src, output, |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
126 |
"--patch-module", mn + "=" + src.toString()); |
36511 | 127 |
assertTrue(compiled, "classes did not compile"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
128 |
JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-2.jar"), output); |
36511 | 129 |
} |
130 |
||
131 |
} |
|
132 |
||
133 |
/** |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
134 |
* Run test with patches to java.base, jdk.naming.dns and jdk.compiler |
36511 | 135 |
*/ |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
136 |
void runTest(String basePatches, String dnsPatches, String compilerPatches) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
137 |
throws Exception |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
138 |
{ |
36511 | 139 |
// the argument to the test is the list of classes overridden or added |
140 |
String arg = Stream.of(CLASSES).collect(Collectors.joining(",")); |
|
141 |
||
142 |
int exitValue |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
143 |
= executeTestJava("--patch-module", "java.base=" + basePatches, |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
144 |
"--patch-module", "jdk.naming.dns=" + dnsPatches, |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
145 |
"--patch-module", "jdk.compiler=" + compilerPatches, |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
146 |
"--add-exports", "java.base/java.lang2=test", |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
147 |
"--add-exports", "jdk.naming.dns/com.sun.jndi.dns=test", |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
148 |
"--add-exports", "jdk.naming.dns/com.sun.jndi.dns2=test", |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
149 |
"--add-exports", "jdk.compiler/com.sun.tools.javac2=test", |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
150 |
"--add-modules", "jdk.naming.dns,jdk.compiler", |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
151 |
"--module-path", MODS_DIR.toString(), |
36511 | 152 |
"-m", "test/jdk.test.Main", arg) |
153 |
.outputTo(System.out) |
|
154 |
.errorTo(System.out) |
|
155 |
.getExitValue(); |
|
156 |
||
157 |
assertTrue(exitValue == 0); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
158 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
159 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
160 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
161 |
/** |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
162 |
* Run test with ---patch-module and exploded patches |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
163 |
*/ |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
164 |
public void testWithExplodedPatches() throws Exception { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
165 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
166 |
// patches1/java.base:patches2/java.base |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
167 |
String basePatches = PATCHES1_DIR.resolve("java.base") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
168 |
+ File.pathSeparator + PATCHES2_DIR.resolve("java.base"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
169 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
170 |
String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
171 |
+ File.pathSeparator + PATCHES2_DIR.resolve("jdk.naming.dns"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
172 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
173 |
String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
174 |
+ File.pathSeparator + PATCHES2_DIR.resolve("jdk.compiler"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
175 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
176 |
runTest(basePatches, dnsPatches, compilerPatches); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
177 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
178 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
179 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
180 |
/** |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
181 |
* Run test with ---patch-module and patches in JAR files |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
182 |
*/ |
38749
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
183 |
public void testWithJarPatches() throws Exception { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
184 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
185 |
// patches/java.base-1.jar:patches/java-base-2.jar |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
186 |
String basePatches = PATCHES_DIR.resolve("java.base-1.jar") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
187 |
+ File.pathSeparator + PATCHES_DIR.resolve("java.base-2.jar"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
188 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
189 |
String dnsPatches = PATCHES_DIR.resolve("jdk.naming.dns-1.jar") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
190 |
+ File.pathSeparator + PATCHES_DIR.resolve("jdk.naming.dns-2.jar"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
191 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
192 |
String compilerPatches = PATCHES_DIR.resolve("jdk.compiler-1.jar") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
193 |
+ File.pathSeparator + PATCHES_DIR.resolve("jdk.compiler-2.jar"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
194 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36928
diff
changeset
|
195 |
runTest(basePatches, dnsPatches, compilerPatches); |
36511 | 196 |
|
197 |
} |
|
198 |
||
38749
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
199 |
|
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
200 |
/** |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38749
diff
changeset
|
201 |
* Run test with ---patch-module and patches in JAR files and exploded patches |
38749
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
202 |
*/ |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
203 |
public void testWithJarAndExplodedPatches() throws Exception { |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
204 |
|
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
205 |
// patches/java.base-1.jar:patches2/java.base |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
206 |
String basePatches = PATCHES_DIR.resolve("java.base-1.jar") |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
207 |
+ File.pathSeparator + PATCHES2_DIR.resolve("java.base"); |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
208 |
|
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
209 |
// patches1/jdk.naming.dns:patches/jdk.naming.dns-2.jar |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
210 |
String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns") |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
211 |
+ File.pathSeparator + PATCHES_DIR.resolve("jdk.naming.dns-2.jar"); |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
212 |
|
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
213 |
String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler") |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
214 |
+ File.pathSeparator + PATCHES_DIR.resolve("jdk.compiler-2.jar"); |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
215 |
|
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
216 |
runTest(basePatches, dnsPatches, compilerPatches); |
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
217 |
|
90c9aeef923a
8158190: Add test that checks -Xpatch with both Jar and exploded patches
mli
parents:
38431
diff
changeset
|
218 |
} |
36511 | 219 |
} |