1 /* 2 * Copyright (c) 2012, 2013, 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 private static final String LANG = System.getenv("LANG"); 56 private static final String LC_ALL = System.getenv("LC_ALL"); 57 main(String... args)58 public static void main(String... args) throws Exception { 59 boolean localeAvailable = false; 60 for (Locale l : Locale.getAvailableLocales()) { 61 if (l.toLanguageTag().equals(Locale.JAPAN.toLanguageTag())) { 62 localeAvailable = true; 63 break; 64 } 65 } 66 if (!localeAvailable) { 67 System.out.println("Warning: locale: " + Locale.JAPAN 68 + " not found, test passes vacuously"); 69 return; 70 } 71 if ("C".equals(LC_ALL) || "C".equals(LANG)) { 72 System.out.println("Warning: The LANG and/or LC_ALL env vars are " + 73 "set to \"C\":\n" + 74 " LANG=" + LANG + "\n" + 75 " LC_ALL=" + LC_ALL + "\n" + 76 "This test requires support for multi-byte filenames.\n" + 77 "Test passes vacuously."); 78 return; 79 } 80 if (encoding.equals("MS932") || encoding.equals("UTF-8")) { 81 Locale.setDefault(Locale.JAPAN); 82 System.out.println("using locale " + Locale.JAPAN + 83 ", encoding " + encoding); 84 } else { 85 System.out.println("Warning: current encoding is " + encoding + 86 "this test requires MS932 <Ja> or UTF-8," + 87 " test passes vacuously"); 88 return; 89 } 90 dir.mkdir(); 91 File dirfile = new File(dir, "foo.jar"); 92 createJar(dirfile, 93 "public static void main(String... args) {", 94 "System.out.println(\"Hello World\");", 95 "System.exit(0);", 96 "}"); 97 98 // remove the class files, to ensure that the class is indeed picked up 99 // from the jar file and not from ambient classpath. 100 File[] classFiles = cwd.listFiles(createFilter(CLASS_FILE_EXT)); 101 for (File f : classFiles) { 102 f.delete(); 103 } 104 105 // test with a jar file 106 TestResult tr = doExec(javaCmd, "-jar", dirfile.getAbsolutePath()); 107 System.out.println(tr); 108 if (!tr.isOK()) { 109 throw new RuntimeException("TEST FAILED"); 110 } 111 112 // test the same class but by specifying it as a classpath 113 tr = doExec(javaCmd, "-cp", dirfile.getAbsolutePath(), "Foo"); 114 System.out.println(tr); 115 if (!tr.isOK()) { 116 throw new RuntimeException("TEST FAILED"); 117 } 118 } 119 } 120