Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/langtools/tools/jdeps/multiVersion/MultiVersionError.java
64474 views
1
/*
2
* Copyright (c) 2021, 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 8277165
27
* @library ../lib
28
* @build CompilerUtils
29
* @run testng MultiVersionError
30
* @summary Tests multiple versions of the same class file
31
*/
32
33
import java.nio.file.Path;
34
import java.nio.file.Paths;
35
import java.util.Set;
36
import java.util.spi.ToolProvider;
37
38
import org.testng.annotations.BeforeTest;
39
import org.testng.annotations.Test;
40
41
import static org.testng.Assert.assertTrue;
42
43
public class MultiVersionError {
44
private static final String TEST_SRC = System.getProperty("test.src");
45
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
46
47
private static final Path MODS_DIR = Paths.get("mods");
48
49
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar").orElseThrow();
50
private static final Set<String> modules = Set.of("m1", "m2");
51
52
/**
53
* Compiles classes used by the test
54
*/
55
@BeforeTest
56
public void compileAll() throws Exception {
57
CompilerUtils.cleanDir(MODS_DIR);
58
modules.forEach(mn ->
59
assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn)));
60
61
// create a modular multi-release m1.jar
62
Path m1 = MODS_DIR.resolve("m1");
63
Path m2 = MODS_DIR.resolve("m2");
64
jar("cf", "m1.jar", "-C", m1.toString(), "p/Test.class",
65
"--release", "9", "-C", m1.toString(), "module-info.class",
66
"--release", "11", "-C", m1.toString(), "p/internal/P.class");
67
jar("cf", "m2.jar", "-C", m2.toString(), "q/Q.class",
68
"--release", "10", "-C", m2.toString(), "module-info.class");
69
70
// package private p/internal/P.class in m1 instead
71
jar("cf", "m3.jar", "-C", m2.toString(), "q/Q.class",
72
"--release", "12", "-C", m2.toString(), "module-info.class",
73
"-C", m1.toString(), "p/internal/P.class");
74
}
75
76
/*
77
* multiple module-info.class from different versions should be excluded
78
* from multiple version check.
79
*/
80
@Test
81
public void noMultiVersionClass() {
82
// skip parsing p.internal.P to workaround JDK-8277681
83
JdepsRunner jdepsRunner = new JdepsRunner("--print-module-deps", "--multi-release", "10",
84
"--ignore-missing-deps",
85
"--module-path", "m1.jar", "m2.jar");
86
int rc = jdepsRunner.run(true);
87
assertTrue(rc == 0);
88
assertTrue(jdepsRunner.outputContains("java.base,m1"));
89
}
90
91
/*
92
* Detect multiple versions of p.internal.P class
93
*/
94
@Test
95
public void classInMultiVersions() {
96
JdepsRunner jdepsRunner = new JdepsRunner("--print-module-deps", "--multi-release", "13",
97
"--module-path", "m1.jar", "m3.jar");
98
int rc = jdepsRunner.run(true);
99
assertTrue(rc != 0);
100
assertTrue(jdepsRunner.outputContains("class p.internal.P already associated with version"));
101
}
102
103
private static void jar(String... options) {
104
int rc = JAR_TOOL.run(System.out, System.err, options);
105
assertTrue(rc == 0);
106
}
107
}
108
109