Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/jdeps/modules/CheckModuleTest.java
41149 views
1
/*
2
* Copyright (c) 2016, 2020, 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
* @summary Tests split packages
27
* @library ../lib
28
* @build CompilerUtils JdepsUtil
29
* @modules jdk.jdeps/com.sun.tools.jdeps
30
* @run testng CheckModuleTest
31
*/
32
33
import java.lang.module.ModuleDescriptor;
34
import java.nio.file.Path;
35
import java.nio.file.Paths;
36
import java.util.Map;
37
import java.util.Set;
38
39
import com.sun.tools.jdeps.ModuleAnalyzer;
40
import org.testng.annotations.BeforeTest;
41
import org.testng.annotations.DataProvider;
42
import org.testng.annotations.Test;
43
44
import static org.testng.Assert.assertTrue;
45
import static org.testng.Assert.assertEquals;
46
47
48
public class CheckModuleTest {
49
private static final String TEST_SRC = System.getProperty("test.src");
50
private static final String TEST_CLASSES = System.getProperty("test.classes");
51
52
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
53
private static final Path MODS_DIR = Paths.get("mods");
54
55
// mIV and mV are analyzed. Others are compiled to make sure they are present
56
// on the module path for analysis
57
private static final Set<String> modules = Set.of("unsafe", "mIV", "mV", "mVI", "mVII", "mVIII");
58
59
private static final String JAVA_BASE = "java.base";
60
private static final String JAVA_COMPILER = "java.compiler";
61
62
/**
63
* Compiles classes used by the test
64
*/
65
@BeforeTest
66
public void compileAll() throws Exception {
67
CompilerUtils.cleanDir(MODS_DIR);
68
modules.forEach(mn ->
69
assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn)));
70
}
71
72
@DataProvider(name = "javaBase")
73
public Object[][] base() {
74
return new Object[][] {
75
{ JAVA_BASE, new ModuleMetaData(JAVA_BASE)
76
},
77
{ JAVA_COMPILER, new ModuleMetaData(JAVA_BASE)
78
},
79
};
80
};
81
82
@Test(dataProvider = "javaBase")
83
public void testJavaBase(String name, ModuleMetaData data) throws Exception {
84
String cmd = String.format("jdeps --check %s --module-path %s%n", name, MODS_DIR);
85
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
86
jdeps.appModulePath(MODS_DIR.toString());
87
88
ModuleAnalyzer analyzer = jdeps.getModuleAnalyzer(Set.of(name));
89
assertTrue(analyzer.run(false));
90
jdeps.dumpOutput(System.err);
91
92
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
93
for (int i = 0; i < 3; i++) {
94
descriptors[i].requires().stream()
95
/* jcov has a dependency on java.logging, just ignore it in case this test is being executed with jcov
96
* this dependency from jcov should be fixed once bug: CODETOOLS-7902642 gets fixed
97
*/
98
.filter(req -> !req.toString().equals("java.logging"))
99
.forEach(req -> data.checkRequires(req));
100
}
101
}
102
}
103
104
@DataProvider(name = "modules")
105
public Object[][] unnamed() {
106
return new Object[][]{
107
{ "mIV", new ModuleMetaData[] {
108
// original
109
new ModuleMetaData("mIV")
110
.requiresTransitive("java.compiler")
111
.requires("java.logging")
112
// unnused exports
113
.exports("p4.internal", Set.of("mVI", "mVII")),
114
// suggested version
115
new ModuleMetaData("mIV")
116
.requires("java.compiler"),
117
// reduced version
118
new ModuleMetaData("mIV")
119
.requires("java.compiler")
120
}
121
},
122
{ "mV", new ModuleMetaData[] {
123
// original
124
new ModuleMetaData("mV")
125
.requiresTransitive("java.compiler")
126
.requiresTransitive("java.logging")
127
.requires("java.sql")
128
.requiresTransitive("mIV"),
129
// suggested version
130
new ModuleMetaData("mV")
131
.requiresTransitive("java.compiler")
132
.requires("java.logging")
133
.requiresTransitive("java.sql")
134
.requiresTransitive("mIV"),
135
// reduced version
136
new ModuleMetaData("mV")
137
.requiresTransitive("java.compiler")
138
.requiresTransitive("java.sql")
139
.requiresTransitive("mIV"),
140
}
141
},
142
};
143
}
144
145
@Test(dataProvider = "modules")
146
public void modularTest(String name, ModuleMetaData[] data) throws Exception {
147
String cmd = String.format("jdeps --check %s --module-path %s%n", name, MODS_DIR);
148
149
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
150
jdeps.appModulePath(MODS_DIR.toString());
151
152
ModuleAnalyzer analyzer = jdeps.getModuleAnalyzer(Set.of(name));
153
assertTrue(analyzer.run(false));
154
jdeps.dumpOutput(System.err);
155
156
// compare the module descriptors and the suggested versions
157
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
158
for (int i = 0; i < 3; i++) {
159
ModuleMetaData metaData = data[i];
160
descriptors[i].requires().stream()
161
.forEach(req -> metaData.checkRequires(req));
162
}
163
164
Map<String, Set<String>> unused = analyzer.unusedQualifiedExports(name);
165
// verify unuused qualified exports
166
assertEquals(unused, data[0].exports);
167
}
168
}
169
170
}
171
172