Path: blob/master/test/jdk/tools/jimage/JImageNonAsciiNameTest.java
66643 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.nio.file.Path;24import jdk.internal.jimage.BasicImageReader;25import jdk.internal.jimage.ImageLocation;26import jdk.test.lib.compiler.InMemoryJavaCompiler;27import jdk.test.lib.util.JarBuilder;2829import tests.Helper;30import tests.JImageGenerator;31import tests.Result;3233/*34* @test35* @bug 827818536* @summary Test non-ASCII path in custom JRE37* @library ../lib38* /test/lib39* @modules java.base/jdk.internal.jimage40* jdk.jdeps/com.sun.tools.classfile41* jdk.jlink/jdk.tools.jimage42* @build tests.*43* @run main/othervm JImageNonAsciiNameTest44*/4546public class JImageNonAsciiNameTest {47private final static String moduleName = "A_module";48private final static String packageName = "test.\u3042"; //non-ASCII49private final static String className = "A";50private final static String fullName = packageName + "." + className;51private static Helper helper;5253public static void main(String[] args) throws Exception {54helper = Helper.newHelper();55if (helper == null) {56System.err.println("Test not run");57return;58}5960String source =61"package "+packageName+";" +62"public class "+className+" {" +63" public static void main(String[] args) {}" +64"}";65String moduleInfo = "module " + moduleName + " {}";6667// Using InMemory features to avoid generating non-ASCII name file68byte[] byteA = InMemoryJavaCompiler.compile(fullName, source);69byte[] byteModule = InMemoryJavaCompiler.compile(70"module-info", moduleInfo);7172Path jarDir = helper.getJarDir();73JarBuilder jb = new JarBuilder(74jarDir.resolve(moduleName + ".jar").toString());75jb.addEntry(fullName.replace(".","/") + ".class", byteA);76jb.addEntry("module-info.class", byteModule);77jb.build();7879Path outDir = helper.createNewImageDir(moduleName);8081Result result = JImageGenerator.getJLinkTask()82.modulePath(helper.defaultModulePath())83.output(outDir)84.addMods(moduleName)85.call();86Path testImage = result.assertSuccess();8788BasicImageReader bir = BasicImageReader.open(89testImage.resolve("lib").resolve("modules"));90ImageLocation loc = bir.findLocation(moduleName,91fullName.replace(".","/") + ".class");92if (loc == null) {93throw new RuntimeException("Failed to find " +94fullName + " in module " +moduleName);95}96}97}9899100