Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/jdeps/modules/DotFileTest.java
41152 views
1
/*
2
* Copyright (c) 2017, 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
* @bug 8173374
27
* @summary Tests module dot graph
28
* @modules java.desktop
29
* java.sql
30
* jdk.jdeps/com.sun.tools.jdeps
31
* jdk.unsupported
32
* @library ../lib
33
* @build CompilerUtils
34
* @run testng DotFileTest
35
*/
36
37
import java.nio.file.Files;
38
import java.nio.file.Path;
39
import java.nio.file.Paths;
40
import java.util.HashSet;
41
import java.util.Set;
42
43
import java.util.regex.Matcher;
44
import java.util.regex.Pattern;
45
import java.util.spi.ToolProvider;
46
import java.util.stream.Collectors;
47
48
import org.testng.annotations.BeforeTest;
49
import org.testng.annotations.DataProvider;
50
import org.testng.annotations.Test;
51
52
import static org.testng.Assert.assertTrue;
53
import static org.testng.Assert.assertEquals;
54
55
public class DotFileTest {
56
private static final ToolProvider JDEPS = ToolProvider.findFirst("jdeps")
57
.orElseThrow(() -> new RuntimeException("jdeps not found"));
58
private static final ToolProvider JAR = ToolProvider.findFirst("jar")
59
.orElseThrow(() -> new RuntimeException("jar not found"));
60
61
private static final String TEST_SRC = System.getProperty("test.src");
62
private static final Path DOTS_DIR = Paths.get("dots");
63
private static final Path SPEC_DIR = Paths.get("spec");
64
private static final Path MODS = Paths.get("mods");
65
66
67
@BeforeTest
68
public void setup() throws Exception {
69
assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "unsafe"), MODS));
70
}
71
72
@DataProvider(name = "modules")
73
public Object[][] modules() {
74
return new Object[][]{
75
{"java.desktop", Set.of("java.datatransfer -> java.base",
76
"java.desktop -> java.datatransfer",
77
"java.desktop -> java.prefs",
78
"java.prefs -> java.xml",
79
"java.xml -> java.base" )
80
},
81
{ "java.sql", Set.of("java.logging -> java.base",
82
"java.transaction.xa -> java.base",
83
"java.sql -> java.logging",
84
"java.sql -> java.transaction.xa",
85
"java.sql -> java.xml",
86
"java.xml -> java.base" )
87
}
88
};
89
}
90
@DataProvider(name = "specVersion")
91
public Object[][] specVersion() {
92
return new Object[][]{
93
{"java.desktop", Set.of("java.datatransfer -> java.base",
94
"java.desktop -> java.datatransfer",
95
"java.desktop -> java.xml",
96
"java.xml -> java.base")
97
},
98
{ "java.sql", Set.of("java.logging -> java.base",
99
"java.transaction.xa -> java.base",
100
"java.sql -> java.logging",
101
"java.sql -> java.transaction.xa",
102
"java.sql -> java.xml",
103
"java.xml -> java.base" )
104
}
105
};
106
}
107
108
@Test(dataProvider = "modules")
109
public void test(String name, Set<String> edges) throws Exception {
110
String[] options = new String[] {
111
"-dotoutput", DOTS_DIR.toString(),
112
"-s", "-m", name
113
};
114
assertTrue(JDEPS.run(System.out, System.out, options) == 0);
115
116
Path path = DOTS_DIR.resolve(name + ".dot");
117
assertTrue(Files.exists(path));
118
Set<String> lines = Files.readAllLines(path).stream()
119
.filter(l -> l.contains(" -> "))
120
.map(this::split)
121
.collect(Collectors.toSet());
122
assertEquals(lines, edges);
123
}
124
125
@Test(dataProvider = "specVersion")
126
public void testAPIOnly(String name, Set<String> edges) throws Exception {
127
String[] options = new String[]{
128
"-dotoutput", SPEC_DIR.toString(),
129
"-s", "-apionly",
130
"-m", name
131
};
132
assertTrue(JDEPS.run(System.out, System.out, options) == 0);
133
134
Path path = SPEC_DIR.resolve(name + ".dot");
135
assertTrue(Files.exists(path));
136
Set<String> lines = Files.readAllLines(path).stream()
137
.filter(l -> l.contains(" -> "))
138
.map(this::split)
139
.collect(Collectors.toSet());
140
assertEquals(lines, edges);
141
}
142
143
/*
144
* Test if the file name of the dot output file matches the input filename
145
*/
146
@Test
147
public void testModularJar() throws Exception {
148
String filename = "org.unsafe-v1.0.jar";
149
assertTrue(JAR.run(System.out, System.out, "cf", filename,
150
"-C", MODS.toString(), ".") == 0);
151
152
// assertTrue(JDEPS.run(System.out, System.out,
153
// "--dot-output", DOTS_DIR.toString(), filename) == 0);
154
assertTrue(JDEPS.run(System.out, System.out,
155
"--dot-output", DOTS_DIR.toString(),
156
"--module-path", filename,
157
"-m", "unsafe") == 0);
158
159
Path path = DOTS_DIR.resolve(filename + ".dot");
160
assertTrue(Files.exists(path));
161
162
// package dependences
163
Set<String> expected = Set.of(
164
"org.indirect -> java.lang",
165
"org.indirect -> org.unsafe",
166
"org.safe -> java.io",
167
"org.safe -> java.lang",
168
"org.unsafe -> java.lang",
169
"org.unsafe -> sun.misc"
170
);
171
172
Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)");
173
Set<String> lines = new HashSet<>();
174
for (String line : Files.readAllLines(path)) {
175
line = line.replace('"', ' ').replace(';', ' ');
176
Matcher pm = pattern.matcher(line);
177
if (pm.find()) {
178
String origin = pm.group(1).trim();
179
String target = pm.group(2).trim();
180
lines.add(origin + " -> " + target);
181
}
182
}
183
assertEquals(lines, expected);
184
}
185
186
/*
187
* Test module summary with -m option
188
*/
189
@Test
190
public void testModuleSummary() throws Exception {
191
String filename = "org.unsafe-v2.0.jar";
192
assertTrue(JAR.run(System.out, System.out, "cf", filename,
193
"-C", MODS.toString(), ".") == 0);
194
195
assertTrue(JDEPS.run(System.out, System.out, "-s",
196
"--dot-output", DOTS_DIR.toString(),
197
"--module-path", filename,
198
"-m", "unsafe") == 0);
199
200
Path path = DOTS_DIR.resolve(filename + ".dot");
201
assertTrue(Files.exists(path));
202
203
// module dependences
204
Set<String> expected = Set.of(
205
"unsafe -> jdk.unsupported",
206
"jdk.unsupported -> java.base"
207
);
208
209
Set<String> lines = Files.readAllLines(path).stream()
210
.filter(l -> l.contains(" -> "))
211
.map(this::split)
212
.collect(Collectors.toSet());
213
assertEquals(lines, expected);
214
}
215
216
static Pattern PATTERN = Pattern.compile(" *\"(\\S+)\" -> \"(\\S+)\" .*");
217
String split(String line) {
218
Matcher pm = PATTERN.matcher(line);
219
assertTrue(pm.find());
220
return String.format("%s -> %s", pm.group(1), pm.group(2));
221
}
222
}
223
224