1 /* 2 * Copyright (c) 2012, 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 7125442 27 * @summary ensures a jar path as well as a class located in a path containing 28 * unicode characters are launched. 29 * @compile -XDignore.symbol.file I18NJarTest.java 30 * @run main/othervm I18NJarTest 31 */ 32 import java.io.File; 33 import java.util.Locale; 34 35 /* 36 * Note 1: the system must have the correct Locale, in order for the test to 37 * work correctly, on those systems that do not comply, the test will succeed. 38 * Here are some guidelines to set the locale correctly. 39 * On Windows: ControlPanel->Regional Settings, 40 * ensure that "Japanese" is selected and checked, and in 41 * "Code page conversion tables", the following must be checked, 42 * 932 (ANSI/OEM - Japanese Shift-JIS). 43 * On Unix: use "locale -a" verify one of these exist ja_JP.UTF-8 or 44 * ja_JP.utf8 or ja_JP.ujis, and export one of them with LC_ALL. 45 * 46 * 47 * Note 2: since we need to set the locale, it is safest to execute this test 48 * in its own VM (othervm mode), such that the ensuing tests can run unperturbed, 49 * regardless of the outcome. 50 */ 51 public class I18NJarTest extends TestHelper { 52 private static final File cwd = new File("."); 53 private static final File dir = new File("\uFF66\uFF67\uFF68\uFF69"); 54 private static final String encoding = System.getProperty("sun.jnu.encoding", ""); 55 56 public static void main(String... args) throws Exception { 57 boolean localeAvailable = false; 58 for (Locale l : Locale.getAvailableLocales()) { 59 if (l.toLanguageTag().equals(Locale.JAPAN.toLanguageTag())) { 60 localeAvailable = true; 61 break; 62 } 63 } 64 if (!localeAvailable) { 65 System.out.println("Warning: locale: " + Locale.JAPAN 66 + " not found, test passes vacuosly"); 67 return; 68 } 69 if (encoding.equals("MS932") || encoding.equals("UTF-8")) { 70 Locale.setDefault(Locale.JAPAN); 71 System.out.println("using locale " + Locale.JAPAN + 72 ", encoding " + encoding); 73 } else { 74 System.out.println("Warning: current encoding is " + encoding + 75 "this test requires MS932 <Ja> or UTF-8," + 76 " test passes vacuosly"); 77 return; 78 } 79 dir.mkdir(); 80 File dirfile = new File(dir, "foo.jar"); 81 createJar(dirfile, 82 "public static void main(String... args) {", 83 "System.out.println(\"Hello World\");", 84 "System.exit(0);", 85 "}"); 86 87 // remove the class files, to ensure that the class is indeed picked up 88 // from the jar file and not from ambient classpath. 89 File[] classFiles = cwd.listFiles(createFilter(CLASS_FILE_EXT)); 90 for (File f : classFiles) { 91 f.delete(); 92 } 93 94 // test with a jar file 95 TestResult tr = doExec(javaCmd, "-jar", dirfile.getAbsolutePath()); 96 System.out.println(tr); 97 if (!tr.isOK()) { 98 throw new RuntimeException("TEST FAILED"); 99 } 100 101 // test the same class but by specifying it as a classpath 102 tr = doExec(javaCmd, "-cp", dirfile.getAbsolutePath(), "Foo"); 103 System.out.println(tr); 104 if (!tr.isOK()) { 105 throw new RuntimeException("TEST FAILED"); 106 } 107 } 108 }