Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/modules/patch/automatic/PatchTest.java
41159 views
1
/*
2
* Copyright (c) 2021, 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
* @build PatchTest
29
* jdk.test.lib.compiler.CompilerUtils
30
* jdk.test.lib.util.JarUtils
31
* jdk.test.lib.process.ProcessTools
32
* @run testng PatchTest
33
* @bug 8259395
34
* @summary Tests patching an automatic module
35
*/
36
37
import java.io.File;
38
import java.util.List;
39
import java.nio.file.Files;
40
import java.nio.file.Path;
41
42
import jdk.test.lib.compiler.CompilerUtils;
43
import jdk.test.lib.util.JarUtils;
44
import static jdk.test.lib.process.ProcessTools.*;
45
46
import org.testng.annotations.Test;
47
import org.testng.annotations.BeforeClass;
48
import static org.testng.Assert.*;
49
50
public class PatchTest {
51
52
private static final String APP_NAME = "myapp";
53
54
private static final String MODULE_NAME = "somelib";
55
56
private static final String EXTEND_PATCH_NAME = "patch1";
57
private static final String AUGMENT_PATCH_NAME = "patch2";
58
59
private static final String APP_MAIN = "myapp.Main";
60
private static final String EXTEND_PATCH_MAIN = "somelib.test.TestMain";
61
private static final String AUGMENT_PATCH_MAIN = "somelib.Dummy";
62
63
private static final String TEST_SRC = System.getProperty("test.src");
64
65
private static final Path APP_SRC = Path.of(TEST_SRC, APP_NAME);
66
private static final Path APP_CLASSES = Path.of("classes", APP_NAME);
67
private static final Path SOMELIB_SRC = Path.of(TEST_SRC, MODULE_NAME);
68
private static final Path SOMELIB_EXTEND_PATCH_SRC = Path.of(TEST_SRC, EXTEND_PATCH_NAME);
69
private static final Path SOMELIB_AUGMENT_PATCH_SRC = Path.of(TEST_SRC, AUGMENT_PATCH_NAME);
70
private static final Path SOMELIB_CLASSES = Path.of("classes", MODULE_NAME);
71
private static final Path SOMELIB_EXTEND_PATCH_CLASSES = Path.of("classes", EXTEND_PATCH_NAME);
72
private static final Path SOMELIB_AUGMENT_PATCH_CLASSES = Path.of("classes", AUGMENT_PATCH_NAME);
73
private static final Path SOMELIB_JAR = Path.of("mods", MODULE_NAME + "-0.19.jar");
74
75
private static final String MODULE_PATH = String.join(File.pathSeparator, SOMELIB_JAR.toString(), APP_CLASSES.toString());
76
77
/**
78
* The test consists of 2 modules:
79
*
80
* somelib - dummy automatic module.
81
* myapp - explicit module, uses somelib
82
*
83
* And two patches:
84
*
85
* patch1 - adds an additional package. (extend)
86
* patch2 - only replaces existing classes. (augment)
87
*
88
*/
89
@BeforeClass
90
public void compile() throws Exception {
91
boolean compiled;
92
93
// create mods/somelib-0.19.jar
94
95
compiled = CompilerUtils.compile(SOMELIB_SRC, SOMELIB_CLASSES);
96
assertTrue(compiled);
97
98
JarUtils.createJarFile(SOMELIB_JAR, SOMELIB_CLASSES);
99
100
101
// compile patch 1
102
compiled = CompilerUtils.compile(SOMELIB_EXTEND_PATCH_SRC, SOMELIB_EXTEND_PATCH_CLASSES,
103
"--module-path", SOMELIB_JAR.toString(),
104
"--add-modules", MODULE_NAME,
105
"--patch-module", MODULE_NAME + "=" + SOMELIB_EXTEND_PATCH_SRC);
106
assertTrue(compiled);
107
108
// compile patch 2
109
compiled = CompilerUtils.compile(SOMELIB_AUGMENT_PATCH_SRC, SOMELIB_AUGMENT_PATCH_CLASSES,
110
"--module-path", SOMELIB_JAR.toString(),
111
"--add-modules", MODULE_NAME,
112
"--patch-module", MODULE_NAME + "=" + SOMELIB_AUGMENT_PATCH_SRC);
113
assertTrue(compiled);
114
115
// compile app
116
compiled = CompilerUtils.compile(APP_SRC, APP_CLASSES,
117
"--module-path", SOMELIB_JAR.toString());
118
assertTrue(compiled);
119
}
120
121
@Test
122
public void testExtendAutomaticModuleOnModulePath() throws Exception {
123
int exitValue
124
= executeTestJava("--module-path", MODULE_PATH,
125
"--patch-module", MODULE_NAME + "=" + SOMELIB_EXTEND_PATCH_CLASSES,
126
"-m", APP_NAME + "/" + APP_MAIN, "patch1")
127
.outputTo(System.out)
128
.errorTo(System.out)
129
.getExitValue();
130
131
assertTrue(exitValue == 0);
132
}
133
134
@Test
135
public void testAugmentAutomaticModuleOnModulePath() throws Exception {
136
int exitValue
137
= executeTestJava("--module-path", MODULE_PATH,
138
"--patch-module", MODULE_NAME + "=" + SOMELIB_AUGMENT_PATCH_CLASSES,
139
"-m", APP_NAME + "/" + APP_MAIN, "patch2")
140
.outputTo(System.out)
141
.errorTo(System.out)
142
.getExitValue();
143
144
assertTrue(exitValue == 0);
145
}
146
147
@Test
148
public void testExtendAutomaticModuleAsInitialModule() throws Exception {
149
int exitValue
150
= executeTestJava("--module-path", SOMELIB_JAR.toString(),
151
"--patch-module", MODULE_NAME + "=" + SOMELIB_EXTEND_PATCH_CLASSES,
152
"-m", MODULE_NAME + "/" + EXTEND_PATCH_MAIN)
153
.outputTo(System.out)
154
.errorTo(System.out)
155
.getExitValue();
156
157
assertTrue(exitValue == 0);
158
}
159
160
@Test
161
public void testAugmentAutomaticModuleAsInitialModule() throws Exception {
162
int exitValue
163
= executeTestJava("--module-path", SOMELIB_JAR.toString(),
164
"--patch-module", MODULE_NAME + "=" + SOMELIB_AUGMENT_PATCH_CLASSES,
165
"-m", MODULE_NAME + "/" + AUGMENT_PATCH_MAIN)
166
.outputTo(System.out)
167
.errorTo(System.out)
168
.getExitValue();
169
170
assertTrue(exitValue == 0);
171
}
172
173
}
174
175