Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/tools/jimage/JImageNonAsciiNameTest.java
66643 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
import java.nio.file.Path;
25
import jdk.internal.jimage.BasicImageReader;
26
import jdk.internal.jimage.ImageLocation;
27
import jdk.test.lib.compiler.InMemoryJavaCompiler;
28
import jdk.test.lib.util.JarBuilder;
29
30
import tests.Helper;
31
import tests.JImageGenerator;
32
import tests.Result;
33
34
/*
35
* @test
36
* @bug 8278185
37
* @summary Test non-ASCII path in custom JRE
38
* @library ../lib
39
* /test/lib
40
* @modules java.base/jdk.internal.jimage
41
* jdk.jdeps/com.sun.tools.classfile
42
* jdk.jlink/jdk.tools.jimage
43
* @build tests.*
44
* @run main/othervm JImageNonAsciiNameTest
45
*/
46
47
public class JImageNonAsciiNameTest {
48
private final static String moduleName = "A_module";
49
private final static String packageName = "test.\u3042"; //non-ASCII
50
private final static String className = "A";
51
private final static String fullName = packageName + "." + className;
52
private static Helper helper;
53
54
public static void main(String[] args) throws Exception {
55
helper = Helper.newHelper();
56
if (helper == null) {
57
System.err.println("Test not run");
58
return;
59
}
60
61
String source =
62
"package "+packageName+";" +
63
"public class "+className+" {" +
64
" public static void main(String[] args) {}" +
65
"}";
66
String moduleInfo = "module " + moduleName + " {}";
67
68
// Using InMemory features to avoid generating non-ASCII name file
69
byte[] byteA = InMemoryJavaCompiler.compile(fullName, source);
70
byte[] byteModule = InMemoryJavaCompiler.compile(
71
"module-info", moduleInfo);
72
73
Path jarDir = helper.getJarDir();
74
JarBuilder jb = new JarBuilder(
75
jarDir.resolve(moduleName + ".jar").toString());
76
jb.addEntry(fullName.replace(".","/") + ".class", byteA);
77
jb.addEntry("module-info.class", byteModule);
78
jb.build();
79
80
Path outDir = helper.createNewImageDir(moduleName);
81
82
Result result = JImageGenerator.getJLinkTask()
83
.modulePath(helper.defaultModulePath())
84
.output(outDir)
85
.addMods(moduleName)
86
.call();
87
Path testImage = result.assertSuccess();
88
89
BasicImageReader bir = BasicImageReader.open(
90
testImage.resolve("lib").resolve("modules"));
91
ImageLocation loc = bir.findLocation(moduleName,
92
fullName.replace(".","/") + ".class");
93
if (loc == null) {
94
throw new RuntimeException("Failed to find " +
95
fullName + " in module " +moduleName);
96
}
97
}
98
}
99
100