Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/jdeps/missingDeps/MissingDepsTest.java
41149 views
1
/*
2
* Copyright (c) 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 jdeps option on a MR jar with missing dependences
27
* @library ../lib
28
* @build CompilerUtils JdepsUtil
29
* @modules jdk.jdeps/com.sun.tools.jdeps
30
* @run testng MissingDepsTest
31
*/
32
33
import java.nio.file.Files;
34
import java.nio.file.Path;
35
import java.nio.file.Paths;
36
import java.util.Arrays;
37
import java.util.List;
38
import java.util.Set;
39
import java.util.spi.ToolProvider;
40
import java.util.stream.Stream;
41
42
import org.testng.annotations.BeforeTest;
43
import org.testng.annotations.DataProvider;
44
import org.testng.annotations.Test;
45
46
import static org.testng.Assert.assertTrue;
47
import static org.testng.Assert.assertEquals;
48
49
50
public class MissingDepsTest {
51
private static final String TEST_SRC = System.getProperty("test.src");
52
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
53
54
private static final Path MODS_DIR = Paths.get("mods");
55
private static final Path CLASSES_DIR = Paths.get("classes");
56
57
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar").orElseThrow();
58
private static final String VERSION = "13";
59
60
private static final Set<String> modules = Set.of("m1", "m2");
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
// compile a versioned class file
72
Path versionedFile = Paths.get(TEST_SRC, "p/internal/X.java");
73
assertTrue(CompilerUtils.compile(versionedFile, CLASSES_DIR, "-cp", MODS_DIR.resolve("m2").toString()));
74
75
// create a modular multi-release m1.jar
76
JAR_TOOL.run(System.out, System.err, "cf", "m1.jar",
77
"-C", MODS_DIR.resolve("m1").toString(), ".");
78
JAR_TOOL.run(System.out, System.err, "uf", "m1.jar",
79
"--release", VERSION, "-C", CLASSES_DIR.toString(), "p/internal/X.class");
80
// create a non-modular multi-release mr.jar
81
JAR_TOOL.run(System.out, System.err, "cf", "mr.jar",
82
"-C", MODS_DIR.resolve("m1").toString(), "p/Foo.class",
83
"--release", VERSION, "-C", CLASSES_DIR.toString(), "p/internal/X.class");
84
}
85
86
@Test
87
public void checkModuleDeps() {
88
JdepsTest test = new JdepsTest();
89
test.options(List.of("--module-path", "m1.jar", "--multi-release", VERSION, "--check", "m1"));
90
test.checkMissingDeps();
91
test.ignoreMissingDeps("requires java.management");
92
}
93
94
@Test
95
public void genModuleInfo() {
96
JdepsTest test = new JdepsTest();
97
test.options(List.of("--generate-module-info", ".", "--multi-release", VERSION, "mr.jar"));
98
test.checkMissingDeps();
99
Path file = Paths.get("mr", "versions", VERSION, "module-info.java");
100
test.ignoreMissingDeps(file.toString());
101
assertTrue(Files.exists(file));
102
}
103
104
@Test
105
public void listModuleDeps() {
106
JdepsTest test = new JdepsTest();
107
test.options(List.of("--list-deps", "--multi-release", VERSION, "mr.jar"));
108
test.checkMissingDeps();
109
test.ignoreMissingDeps("java.management");
110
}
111
112
class JdepsTest {
113
// set DEBUG to true to show the jdeps output
114
static final boolean DEBUG = false;
115
List<String> options;
116
JdepsTest options(List<String> options) {
117
this.options = options;
118
return this;
119
}
120
121
private void checkMissingDeps() {
122
JdepsRunner jdepsRunner = new JdepsRunner(options.toArray(new String[0]));
123
int rc = jdepsRunner.run(DEBUG);
124
assertTrue(rc != 0);
125
String regex = "\\s+13/p.internal.X\\s+->\\s+q.T\\s+not found";
126
assertTrue(Arrays.stream(jdepsRunner.output()).anyMatch(l -> l.matches(regex)));
127
}
128
129
public void ignoreMissingDeps(String expected) {
130
JdepsRunner jdepsRunner = new JdepsRunner(Stream.concat(Stream.of("--ignore-missing-deps"), options.stream())
131
.toArray(String[]::new));
132
int rc = jdepsRunner.run(DEBUG);
133
assertTrue(rc == 0);
134
System.out.println("Expected: " + expected);
135
assertTrue(Arrays.stream(jdepsRunner.output()).anyMatch(l -> l.contains(expected)));
136
}
137
}
138
}
139
140