Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jlink/ModuleNamesOrderTest.java
41145 views
1
/*
2
* Copyright (c) 2016, 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
import java.io.File;
25
import java.io.FileReader;
26
import java.io.IOException;
27
import java.nio.file.Path;
28
import java.nio.file.Paths;
29
import java.util.List;
30
import java.util.Properties;
31
import java.util.spi.ToolProvider;
32
import java.util.stream.Collectors;
33
import java.util.stream.Stream;
34
35
import tests.Helper;
36
import tests.JImageGenerator;
37
import tests.JImageGenerator.JLinkTask;
38
39
/*
40
* @test
41
* @bug 8168925
42
* @summary MODULES property should be topologically ordered and space-separated list
43
* @library ../lib
44
* @modules java.base/jdk.internal.jimage
45
* jdk.jdeps/com.sun.tools.classfile
46
* jdk.jlink/jdk.tools.jlink.internal
47
* jdk.jlink/jdk.tools.jmod
48
* jdk.jlink/jdk.tools.jimage
49
* jdk.compiler
50
* jdk.jshell
51
*
52
* @build tests.*
53
* @run main ModuleNamesOrderTest
54
*/
55
public class ModuleNamesOrderTest {
56
static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
57
.orElseThrow(() ->
58
new RuntimeException("jlink tool not found")
59
);
60
61
public static void main(String[] args) throws Exception {
62
Helper helper = Helper.newHelper();
63
if (helper == null) {
64
System.err.println("Test not run");
65
return;
66
}
67
68
testDependences(helper);
69
testModulesOrder(helper);
70
}
71
72
private static List<String> modulesProperty(Path outputDir, String modulePath, String... roots)
73
throws IOException
74
{
75
JLinkTask jlinkTask = JImageGenerator.getJLinkTask()
76
.modulePath(modulePath)
77
.output(outputDir);
78
Stream.of(roots).forEach(jlinkTask::addMods);
79
jlinkTask.call().assertSuccess();
80
81
File release = new File(outputDir.toString(), "release");
82
if (!release.exists()) {
83
throw new AssertionError("release not generated");
84
}
85
86
Properties props = new Properties();
87
try (FileReader reader = new FileReader(release)) {
88
props.load(reader);
89
}
90
91
String modules = props.getProperty("MODULES");
92
if (!modules.startsWith("\"java.base ")) {
93
throw new AssertionError("MODULES should start with 'java.base'");
94
}
95
if (modules.charAt(0) != '"' || modules.charAt(modules.length()-1) != '"') {
96
throw new AssertionError("MODULES value should be double quoted");
97
}
98
99
return Stream.of(modules.substring(1, modules.length()-1).split("\\s+"))
100
.collect(Collectors.toList());
101
}
102
103
private static void testDependences(Helper helper) throws IOException {
104
Path outputDir = helper.createNewImageDir("test");
105
List<String> modules = modulesProperty(outputDir, helper.defaultModulePath(),
106
"jdk.jshell");
107
String last = modules.get(modules.size()-1);
108
if (!last.equals("jdk.jshell")) {
109
throw new AssertionError("Unexpected MODULES value: " + modules);
110
}
111
112
checkDependency(modules, "java.logging", "java.base");
113
checkDependency(modules, "jdk.compiler", "java.compiler");
114
checkDependency(modules, "jdk.jshell", "java.logging");
115
checkDependency(modules, "jdk.jshell", "jdk.compiler");
116
}
117
118
/*
119
* Verify the MODULES list must be the same for the same module graph
120
*/
121
private static void testModulesOrder(Helper helper) throws IOException {
122
Path image1 = helper.createNewImageDir("test1");
123
List<String> modules1 = modulesProperty(image1, helper.defaultModulePath(),
124
"jdk.jshell");
125
Path image2 = helper.createNewImageDir("test2");
126
List<String> modules2 = modulesProperty(image2, helper.defaultModulePath(),
127
"jdk.jshell");
128
if (!modules1.equals(modules2)) {
129
throw new AssertionError("MODULES should be a stable order: " +
130
modules1 + " vs " + modules2);
131
}
132
}
133
134
private static void checkDependency(List<String> modules, String fromMod, String toMod) {
135
int fromModIdx = modules.indexOf(fromMod);
136
if (fromModIdx == -1) {
137
throw new AssertionError(fromMod + " is missing in MODULES");
138
}
139
int toModIdx = modules.indexOf(toMod);
140
if (toModIdx == -1) {
141
throw new AssertionError(toMod + " is missing in MODULES");
142
}
143
144
if (toModIdx > fromModIdx) {
145
throw new AssertionError("in MODULES, " + fromMod + " should appear after " + toMod);
146
}
147
}
148
}
149
150