Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/jdeps/modules/GenOpenModule.java
41149 views
1
/*
2
* Copyright (c) 2016, 2017, 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 --generate-open-module option
27
* @library ../lib
28
* @build CompilerUtils JdepsUtil JdepsRunner
29
* @modules jdk.jdeps/com.sun.tools.jdeps
30
* @run testng GenOpenModule
31
*/
32
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.lang.module.ModuleDescriptor;
36
37
import java.nio.file.Files;
38
import java.nio.file.Path;
39
import java.nio.file.Paths;
40
41
import java.util.stream.Stream;
42
43
import org.testng.annotations.BeforeTest;
44
import org.testng.annotations.Test;
45
46
import static org.testng.Assert.assertEquals;
47
import static org.testng.Assert.assertTrue;
48
49
public class GenOpenModule extends GenModuleInfo {
50
private static final String MODULE_INFO = "module-info.class";
51
52
private static final Path MODS_DIR = Paths.get("mods");
53
private static final Path LIBS_DIR = Paths.get("libs");
54
private static final Path DEST_DIR = Paths.get("moduleinfosrc");
55
private static final Path NEW_MODS_DIR = Paths.get("new_mods");
56
57
@BeforeTest
58
public void setup() throws Exception {
59
compileAndCreateJars();
60
}
61
62
@Test
63
public void test() throws IOException {
64
Path dest = DEST_DIR.resolve("open");
65
Path classes = NEW_MODS_DIR.resolve("open");
66
Files.createDirectories(dest);
67
Files.createDirectories(classes);
68
69
Stream<String> files = MODULES.stream()
70
.map(mn -> LIBS_DIR.resolve(mn + ".jar"))
71
.map(Path::toString);
72
73
Stream<String> options = Stream.concat(
74
Stream.of("--generate-open-module", dest.toString()), files);
75
JdepsRunner.run(options.toArray(String[]::new));
76
77
// check file exists
78
MODULES.stream()
79
.map(mn -> dest.resolve(mn).resolve("module-info.java"))
80
.forEach(f -> assertTrue(Files.exists(f)));
81
82
// copy classes to a temporary directory
83
// and then compile new module-info.java
84
copyClasses(MODS_DIR, classes);
85
compileNewGenModuleInfo(dest, classes);
86
87
for (String mn : MODULES) {
88
Path p1 = classes.resolve(mn).resolve(MODULE_INFO);
89
Path p2 = MODS_DIR.resolve(mn).resolve(MODULE_INFO);
90
try (InputStream in1 = Files.newInputStream(p1);
91
InputStream in2 = Files.newInputStream(p2)) {
92
verify(ModuleDescriptor.read(in1),
93
ModuleDescriptor.read(in2));
94
}
95
}
96
}
97
98
/*
99
* Verify the dependences
100
*/
101
private void verify(ModuleDescriptor openModule, ModuleDescriptor md) {
102
System.out.println("verifying: " + openModule.name());
103
assertTrue(openModule.isOpen());
104
assertTrue(!md.isOpen());
105
assertEquals(openModule.name(), md.name());
106
assertEquals(openModule.requires(), md.requires());
107
assertTrue(openModule.exports().isEmpty());
108
assertEquals(openModule.provides(), md.provides());
109
}
110
}
111
112