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