jdk/test/tools/launcher/UnicodeTest.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 14856 92a1bcf46888
child 45944 882cea808912
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14856
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 11687
diff changeset
     2
 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    24
/*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    25
 * @test
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    26
 * @bug 5030265
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    27
 * @compile  -XDignore.symbol.file UnicodeTest.java
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    28
 * @run main/othervm UnicodeTest
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    29
 * @summary Verify that the J2RE can handle all legal Unicode characters
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    30
 *          in class names unless limited by the file system encoding
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    31
 *          or the encoding used for command line arguments.
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    32
 * @author Norbert Lindenberg, ksrini
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    33
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class creates Java source files using Unicode characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * that test the limits of what's possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * - in situations where the platform encoding imposes limits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   (command line arguments, non-Unicode file system)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * - in situations where full Unicode is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   (file system access in UTF-8 locales and on Windows 2000++,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *    jar file contents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    44
 * This test needs to be run in othervm as the locale is reset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    47
import java.io.File;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.io.OutputStreamWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    53
public class UnicodeTest extends TestHelper {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    54
    static final File UnicodeTestSrc        = new File("UnicodeTest-src");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    55
    static final File UnicodeTestClasses    = new File("UnicodeTest-classes");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    56
    static final String UnicodeTestJarName  = "UnicodeTest" + JAR_FILE_EXT;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    57
    static final File UnicodeTestJar        = new File(UnicodeTestJarName);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    58
    static final File SolarisUnicodeTestJar = new File(TEST_SOURCES_DIR,
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    59
                                                       UnicodeTestJarName);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    60
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    61
    /*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    62
     * the main method is a port of the shell based test to a java, this
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    63
     * eliminates the need for MKS on windows, thus we can rely on consistent
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    64
     * results regardless of the shell being used.
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    65
     */
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    66
    public static void main(String... args) throws Exception {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    67
        System.out.println("creating test source files");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    68
        UnicodeTestSrc.mkdirs();
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    69
        UnicodeTestClasses.mkdirs();
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    70
        String classname = generateSources();
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    71
        File javaFile = new File(UnicodeTestSrc, classname + JAVA_FILE_EXT);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    72
        System.out.println("building test apps");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    73
        compile("-encoding", "UTF-8",
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    74
                "-sourcepath", UnicodeTestSrc.getAbsolutePath(),
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    75
                "-d", UnicodeTestClasses.getAbsolutePath(),
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    76
                javaFile.getAbsolutePath());
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    77
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    78
        createJar("-cvfm", UnicodeTestJar.getAbsolutePath(),
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    79
                  new File(UnicodeTestSrc, "MANIFEST.MF").getAbsolutePath(),
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    80
                  "-C", UnicodeTestClasses.getAbsolutePath(), ".");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    81
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    82
        if (!UnicodeTestJar.exists()) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    83
            throw new Error("failed to create " + UnicodeTestJar.getAbsolutePath());
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    84
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    85
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    86
        System.out.println("running test app using class file");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    87
        TestResult tr = doExec(javaCmd,
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    88
                        "-cp", UnicodeTestClasses.getAbsolutePath(), classname);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    89
        if (!tr.isOK()) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    90
            System.out.println(tr);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    91
            throw new RuntimeException("test fails");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    92
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    93
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    94
        System.out.println("delete generated files with non-ASCII names");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    95
        recursiveDelete(UnicodeTestSrc);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    96
        recursiveDelete(UnicodeTestClasses);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    97
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    98
        /*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
    99
         * test in whatever the default locale is
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   100
         */
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   101
        runJarTests();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   103
        /*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   104
         * if the Japanese locale is available, test in that locale as well
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   105
         */
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   106
        if (setLocale(Locale.JAPANESE)) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   107
            runJarTests();
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   108
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   109
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   110
       /*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   111
        * if we can switch to a C locale, then test whether jar files with
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   112
        * non-ASCII characters in the manifest still work in this crippled
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   113
        * environment
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   114
        */
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   115
        if (setLocale(Locale.ENGLISH)) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   116
            runJarTests();
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   117
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   118
        // thats it we are outta here
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   119
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   120
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   121
    static void runJarTests() {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   122
        System.out.println("running test app using newly built jar file in " +
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   123
                Locale.getDefault());
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   124
        runTest(UnicodeTestJar);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   126
        System.out.println("running test app using jar file " +
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   127
                "(built with Solaris UTF-8 locale) in " + Locale.getDefault());
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   128
        runTest(SolarisUnicodeTestJar);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   129
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   130
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   131
    static void runTest(File testJar) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   132
        TestResult tr = doExec(javaCmd, "-jar", testJar.getAbsolutePath());
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   133
        if (!tr.isOK()) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   134
            System.out.println(tr);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   135
            throw new RuntimeException("test fails");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   136
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   137
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   138
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   139
    static boolean setLocale(Locale desired) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   140
        if (Locale.getDefault().equals(desired)) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   141
            return true;  // already set nothing more
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   142
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   143
        for (Locale l : Locale.getAvailableLocales()) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   144
            if (l == desired) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   145
                Locale.setDefault(l);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   146
                return true;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   147
            }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   148
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   149
        return false;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   150
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   151
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   152
    static String generateSources() throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        String commandLineClassNameSuffix = commandLineClassNameSuffix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        String commandLineClassName = "ClassA" + commandLineClassNameSuffix;
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   155
        String manifestClassName = "ClassB" +
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   156
                (hasUnicodeFileSystem() ? unicode : commandLineClassNameSuffix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        generateSource(commandLineClassName, manifestClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        generateSource(manifestClassName, commandLineClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        generateManifest(manifestClassName);
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   161
        return commandLineClassName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private static final String defaultEncoding = Charset.defaultCharset().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    // language names taken from java.util.Locale.getDisplayLanguage for the respective language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private static final String s_chinese = "\u4e2d\u6587";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private static final String t_chinese = "\u4e2d\u6587";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private static final String japanese = "\u65e5\u672c\u8a9e";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    private static final String korean = "\ud55c\uad6d\uc5b4";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static final String lithuanian = "Lietuvi\u0173";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final String czech = "\u010de\u0161tina";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final String turkish = "T\u00fcrk\u00e7e";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static final String spanish = "espa\u00f1ol";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static final String thai = "\u0e44\u0e17\u0e22";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final String unicode = arabic + s_chinese + t_chinese
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            + russian + hindi + greek + hebrew + japanese + korean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            + lithuanian + czech + turkish + spanish + thai;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private static String commandLineClassNameSuffix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // Mapping from main platform encodings to language names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // for Unix and Windows, respectively. Use empty suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // for Windows encodings where OEM encoding differs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // Use null if encoding isn't used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        String[][] names = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            { "UTF-8",          unicode,        ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            { "windows-1256",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            { "iso-8859-6",     arabic,         null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            { "GBK",            s_chinese,      s_chinese       },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            { "GB18030",        s_chinese,      s_chinese       },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            { "GB2312",         s_chinese,      null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            { "x-windows-950",  null,           t_chinese       },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            { "x-MS950-HKSCS",  null,           t_chinese       },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            { "x-euc-tw",       t_chinese,      null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            { "Big5",           t_chinese,      null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            { "Big5-HKSCS",     t_chinese,      null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            { "windows-1251",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            { "iso-8859-5",     russian,        null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            { "koi8-r",         russian,        null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            { "windows-1253",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            { "iso-8859-7",     greek,          null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            { "windows-1255",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            { "iso8859-8",      hebrew,         null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            { "windows-31j",    null,           japanese        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            { "x-eucJP-Open",   japanese,       null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            { "x-EUC-JP-LINUX", japanese,       null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            { "x-pck",          japanese,       null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            { "x-windows-949",  null,           korean          },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            { "euc-kr",         korean,         null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            { "windows-1257",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            { "iso-8859-13",    lithuanian,     null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            { "windows-1250",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            { "iso-8859-2",     czech,          null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            { "windows-1254",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            { "iso-8859-9",     turkish,        null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            { "windows-1252",   null,           ""              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            { "iso-8859-1",     spanish,        null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            { "iso-8859-15",    spanish,        null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            { "x-windows-874",  null,           thai            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            { "tis-620",        thai,           null            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   229
        int column = isWindows ? 2 : 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
             if (names[i][0].equalsIgnoreCase(defaultEncoding)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                 return names[i][column];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static boolean hasUnicodeFileSystem() {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   239
        return (isWindows) ? true : defaultEncoding.equalsIgnoreCase("UTF-8");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private static void generateSource(String thisClass, String otherClass) throws Exception {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   243
        File file = new File(UnicodeTestSrc, thisClass + JAVA_FILE_EXT);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   244
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        out.write("public class " + thisClass + " {\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        out.write("    public static void main(String[] args) {\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        out.write("        if (!" + otherClass + "." + otherClass.toLowerCase() + "().equals(\"" + otherClass + "\")) {\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        out.write("            throw new RuntimeException();\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        out.write("        }\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        out.write("    }\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        out.write("    public static String " + thisClass.toLowerCase() + "() {\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        out.write("        return \"" + thisClass + "\";\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        out.write("    }\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        out.write("}\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private static void generateManifest(String mainClass) throws Exception {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   259
        File file = new File(UnicodeTestSrc, "MANIFEST.MF");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 5506
diff changeset
   260
        FileOutputStream out = new FileOutputStream(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // Header lines are limited to 72 bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // The manifest spec doesn't say we have to break at character boundaries,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // so we rudely break at byte boundaries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        byte[] headerBytes = ("Main-Class: " + mainClass + "\n").getBytes("UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (headerBytes.length <= 72) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            out.write(headerBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            out.write(headerBytes, 0, 72);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            int start = 72;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            while (headerBytes.length > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                out.write((byte) '\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                out.write((byte) ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                int count = Math.min(71, headerBytes.length - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                out.write(headerBytes, start, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                start += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}