Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/jdeps/modules/upgrademodulepath/UpgradeModulePathTest.java
41153 views
1
/*
2
* Copyright (c) 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
* @bug 8187449
27
* @summary Tests jdeps --upgrade-module-path
28
* @library ../../lib
29
* @build CompilerUtils
30
* @modules jdk.jartool
31
* jdk.jdeps/com.sun.tools.jdeps
32
* @run testng UpgradeModulePathTest
33
*/
34
35
import java.io.BufferedWriter;
36
import java.io.PrintWriter;
37
import java.nio.file.Files;
38
import java.nio.file.Path;
39
import java.nio.file.Paths;
40
import java.util.spi.ToolProvider;
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.assertFalse;
47
import static org.testng.Assert.assertTrue;
48
49
public class UpgradeModulePathTest {
50
private static final ToolProvider JAR = ToolProvider.findFirst("jar")
51
.orElseThrow(() -> new RuntimeException("jar not found"));
52
53
private static final String TEST_SRC = System.getProperty("test.src");
54
55
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
56
private static final Path MODS_DIR = Paths.get("mods");
57
58
private static final String JAVA_COMPILER = "java.compiler";
59
60
/**
61
* Compiles classes used by the test
62
*/
63
@BeforeTest
64
public void compileAll() throws Exception {
65
CompilerUtils.cleanDir(MODS_DIR);
66
assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, JAVA_COMPILER));
67
68
Path dir = MODS_DIR.resolve(JAVA_COMPILER);
69
70
// create a modular JAR file for java.compiler
71
JAR.run(System.out, System.err,
72
"cf", "java.compiler.jar", "-C", dir.toString(), ".");
73
74
// create a JAR file with AUTOMATIC-MODULE-NAME
75
try (BufferedWriter bw = Files.newBufferedWriter(Paths.get("manifest"));
76
PrintWriter writer = new PrintWriter(bw)) {
77
writer.println("AUTOMATIC-MODULE-NAME: java.compiler");
78
}
79
80
JAR.run(System.out, System.err,
81
"cfm", "auto.jar", "manifest", "-C", dir.toString(), "javax");
82
}
83
84
@Test
85
public void testSystemModule() throws Exception {
86
JdepsRunner jdepsRunner =
87
JdepsRunner.run(Stream.of("-m", "java.compiler").toArray(String[]::new));
88
89
assertTrue(jdepsRunner.outputContains("javax.tools"));
90
assertTrue(jdepsRunner.outputContains("javax.lang.model"));
91
assertTrue(jdepsRunner.outputContains("javax.annotation.processing"));
92
}
93
94
@Test
95
public void testUpgradedModule() throws Exception {
96
JdepsRunner jdepsRunner =
97
JdepsRunner.run(Stream.of("--upgrade-module-path", "java.compiler.jar",
98
"-m", "java.compiler").toArray(String[]::new));
99
100
assertTrue(jdepsRunner.outputContains("javax.tools"));
101
assertFalse(jdepsRunner.outputContains("javax.lang.model"));
102
assertFalse(jdepsRunner.outputContains("javax.annotation.processing"));
103
}
104
105
@Test
106
public void testAutomaticModule() throws Exception {
107
JdepsRunner jdepsRunner =
108
JdepsRunner.run(Stream.of("--upgrade-module-path", "auto.jar",
109
"-m", "java.compiler").toArray(String[]::new));
110
111
assertTrue(jdepsRunner.outputContains("javax.tools"));
112
assertFalse(jdepsRunner.outputContains("javax.lang.model"));
113
assertFalse(jdepsRunner.outputContains("javax.annotation.processing"));
114
}
115
}
116
117