jdk/test/tools/launcher/TestHelper.java
author ksrini
Wed, 05 Sep 2012 11:38:40 -0700
changeset 13675 c2999ee84468
parent 13416 9732a77088fe
child 14518 f4b1adde53b3
permissions -rw-r--r--
7194005: (launcher) needs to be enhanced for 64-bit jar file handling Reviewed-by: darcy, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     1
/*
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
     2
 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     4
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     8
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    13
 * accompanied this code).
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    14
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    21
 * questions.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    22
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    23
13675
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
    24
import java.io.OutputStream;
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
    25
import java.io.InputStream;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    26
import java.lang.annotation.ElementType;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    27
import java.lang.annotation.Retention;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    28
import java.lang.annotation.RetentionPolicy;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    29
import java.lang.annotation.Target;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    30
import java.lang.reflect.Method;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    31
import java.util.regex.Pattern;
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
    32
import java.io.StringWriter;
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
    33
import java.io.PrintWriter;
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
    34
import java.util.Set;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    35
import java.io.BufferedReader;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    36
import java.io.File;
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    37
import java.io.FileFilter;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    38
import java.io.FileNotFoundException;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    39
import java.io.FileOutputStream;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
    40
import java.io.IOException;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    41
import java.io.InputStreamReader;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    42
import java.io.PrintStream;
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    43
import java.nio.charset.Charset;
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    44
import java.nio.file.attribute.BasicFileAttributes;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
    45
import java.nio.file.Files;
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    46
import java.nio.file.FileVisitResult;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    47
import java.nio.file.SimpleFileVisitor;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
    48
import java.nio.file.Path;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    49
import java.util.ArrayList;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    50
import java.util.List;
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    51
import java.util.Locale;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    52
import java.util.Map;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    53
import javax.tools.JavaCompiler;
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    54
import javax.tools.ToolProvider;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    55
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
    56
import static java.nio.file.StandardCopyOption.*;
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    57
import static java.nio.file.StandardOpenOption.*;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
    58
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    59
/**
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
    60
 * This class provides some common utilities for the launcher tests.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    61
 */
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    62
public class TestHelper {
11679
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
    63
    // commonly used jtreg constants
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
    64
    static final File TEST_CLASSES_DIR;
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
    65
    static final File TEST_SOURCES_DIR;
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
    66
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    67
    static final String JAVAHOME = System.getProperty("java.home");
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 12047
diff changeset
    68
    static final String JAVA_BIN;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    69
    static final boolean isSDK = JAVAHOME.endsWith("jre");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    70
    static final String javaCmd;
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
    71
    static final String javawCmd;
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    72
    static final String java64Cmd;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    73
    static final String javacCmd;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    74
    static final String jarCmd;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
    75
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    76
    static final JavaCompiler compiler;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    77
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    78
    static final boolean debug = Boolean.getBoolean("TestHelper.Debug");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    79
    static final boolean isWindows =
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    80
            System.getProperty("os.name", "unknown").startsWith("Windows");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11687
diff changeset
    81
    static final boolean isMacOSX =
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12301
diff changeset
    82
            System.getProperty("os.name", "unknown").contains("OS X");
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    83
    static final boolean is64Bit =
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    84
            System.getProperty("sun.arch.data.model").equals("64");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    85
    static final boolean is32Bit =
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    86
            System.getProperty("sun.arch.data.model").equals("32");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    87
    static final boolean isSolaris =
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    88
            System.getProperty("os.name", "unknown").startsWith("SunOS");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    89
    static final boolean isLinux =
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    90
            System.getProperty("os.name", "unknown").startsWith("Linux");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    91
    static final boolean isDualMode = isSolaris;
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    92
    static final boolean isSparc = System.getProperty("os.arch").startsWith("sparc");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
    93
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    94
    // make a note of the golden default locale
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    95
    static final Locale DefaultLocale = Locale.getDefault();
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
    96
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    97
    static final String JAVA_FILE_EXT  = ".java";
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    98
    static final String CLASS_FILE_EXT = ".class";
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
    99
    static final String JAR_FILE_EXT   = ".jar";
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 12047
diff changeset
   100
    static final String EXE_FILE_EXT   = ".exe";
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   101
    static final String JLDEBUG_KEY     = "_JAVA_LAUNCHER_DEBUG";
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   102
    static final String EXPECTED_MARKER = "TRACER_MARKER:About to EXEC";
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   103
    static final String TEST_PREFIX     = "###TestError###: ";
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   104
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   105
    static int testExitValue = 0;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   106
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   107
    static {
11679
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   108
        String tmp = System.getProperty("test.classes", null);
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   109
        if (tmp == null) {
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   110
            throw new Error("property test.classes not defined ??");
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   111
        }
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   112
        TEST_CLASSES_DIR = new File(tmp).getAbsoluteFile();
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   113
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   114
        tmp = System.getProperty("test.src", null);
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   115
        if (tmp == null) {
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   116
            throw new Error("property test.src not defined ??");
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   117
        }
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   118
        TEST_SOURCES_DIR = new File(tmp).getAbsoluteFile();
84da476c4537 7132270: tools/launcher/DefaultLocaleTestRun.java failing (win)
ksrini
parents: 11520
diff changeset
   119
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   120
        if (is64Bit && is32Bit) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   121
            throw new RuntimeException("arch model cannot be both 32 and 64 bit");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   122
        }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   123
        if (!is64Bit && !is32Bit) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   124
            throw new RuntimeException("arch model is not 32 or 64 bit ?");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   125
        }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   126
        compiler = ToolProvider.getSystemJavaCompiler();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   127
        File binDir = (isSDK) ? new File((new File(JAVAHOME)).getParentFile(), "bin")
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   128
            : new File(JAVAHOME, "bin");
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 12047
diff changeset
   129
        JAVA_BIN = binDir.getAbsolutePath();
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   130
        File javaCmdFile = (isWindows)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   131
                ? new File(binDir, "java.exe")
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   132
                : new File(binDir, "java");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   133
        javaCmd = javaCmdFile.getAbsolutePath();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   134
        if (!javaCmdFile.canExecute()) {
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   135
            throw new RuntimeException("java <" + TestHelper.javaCmd +
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   136
                    "> must exist and should be executable");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   137
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   138
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   139
        File javacCmdFile = (isWindows)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   140
                ? new File(binDir, "javac.exe")
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   141
                : new File(binDir, "javac");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   142
        javacCmd = javacCmdFile.getAbsolutePath();
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   143
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   144
        File jarCmdFile = (isWindows)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   145
                ? new File(binDir, "jar.exe")
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   146
                : new File(binDir, "jar");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   147
        jarCmd = jarCmdFile.getAbsolutePath();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   148
        if (!jarCmdFile.canExecute()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   149
            throw new RuntimeException("java <" + TestHelper.jarCmd +
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   150
                    "> must exist and should be executable");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   151
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   152
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   153
        if (isWindows) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   154
            File javawCmdFile = new File(binDir, "javaw.exe");
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   155
            javawCmd = javawCmdFile.getAbsolutePath();
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   156
            if (!javawCmdFile.canExecute()) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   157
                throw new RuntimeException("java <" + javawCmd +
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   158
                        "> must exist and should be executable");
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   159
            }
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   160
        } else {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   161
            javawCmd = null;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   162
        }
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   163
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   164
        if (!javacCmdFile.canExecute()) {
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   165
            throw new RuntimeException("java <" + javacCmd +
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 10126
diff changeset
   166
                    "> must exist and should be executable");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   167
        }
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   168
        if (isSolaris) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   169
            File sparc64BinDir = new File(binDir,isSparc ? "sparcv9" : "amd64");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   170
            File java64CmdFile= new File(sparc64BinDir, "java");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   171
            if (java64CmdFile.exists() && java64CmdFile.canExecute()) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   172
                java64Cmd = java64CmdFile.getAbsolutePath();
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   173
            } else {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   174
                java64Cmd = null;
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   175
            }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   176
        } else {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   177
            java64Cmd = null;
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   178
        }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   179
    }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   180
    void run(String[] args) throws Exception {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   181
        int passed = 0, failed = 0;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   182
        final Pattern p = (args != null && args.length > 0)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   183
                ? Pattern.compile(args[0])
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   184
                : null;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   185
        for (Method m : this.getClass().getDeclaredMethods()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   186
            boolean selected = (p == null)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   187
                    ? m.isAnnotationPresent(Test.class)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   188
                    : p.matcher(m.getName()).matches();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   189
            if (selected) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   190
                try {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   191
                    m.invoke(this, (Object[]) null);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   192
                    System.out.println(m.getName() + ": OK");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   193
                    passed++;
13416
9732a77088fe 7189944: (launcher) test/tools/launcher/Arrrrghs.java needs a couple of minor fixes
ksrini
parents: 13411
diff changeset
   194
                    System.out.printf("Passed: %d, Failed: %d, ExitValue: %d%n",
9732a77088fe 7189944: (launcher) test/tools/launcher/Arrrrghs.java needs a couple of minor fixes
ksrini
parents: 13411
diff changeset
   195
                                      passed, failed, testExitValue);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   196
                } catch (Throwable ex) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   197
                    System.out.printf("Test %s failed: %s %n", m, ex.getCause());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   198
                    failed++;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   199
                }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   200
            }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   201
        }
13416
9732a77088fe 7189944: (launcher) test/tools/launcher/Arrrrghs.java needs a couple of minor fixes
ksrini
parents: 13411
diff changeset
   202
        System.out.printf("Total: Passed: %d, Failed %d%n", passed, failed);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   203
        if (failed > 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   204
            throw new RuntimeException("Tests failed: " + failed);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   205
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   206
        if (passed == 0 && failed == 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   207
            throw new AssertionError("No test(s) selected: passed = " +
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   208
                    passed + ", failed = " + failed + " ??????????");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   209
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   210
    }
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   211
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   212
    /*
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   213
     * is a dual mode available in the test jdk
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   214
     */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   215
    static boolean dualModePresent() {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   216
        return isDualMode && java64Cmd != null;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   217
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   218
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   219
    /*
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   220
     * usually the jre/lib/arch-name is the same as os.arch, except for x86.
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   221
     */
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   222
    static String getJreArch() {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   223
        String arch = System.getProperty("os.arch");
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   224
        return arch.equals("x86") ? "i386" : arch;
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   225
    }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   226
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   227
    /*
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   228
     * get the complementary jre arch ie. if sparc then return sparcv9 and
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   229
     * vice-versa.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   230
     */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   231
    static String getComplementaryJreArch() {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   232
        String arch = System.getProperty("os.arch");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   233
        if (arch != null) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   234
            switch (arch) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   235
                case "sparc":
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   236
                    return "sparcv9";
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   237
                case "sparcv9":
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   238
                    return "sparc";
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   239
                case "x86":
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   240
                    return "amd64";
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   241
                case "amd64":
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   242
                    return "i386";
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   243
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   244
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   245
        return null;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   246
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   247
13675
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   248
    static File getClassFile(File javaFile) {
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   249
        String s = javaFile.getAbsolutePath().replace(JAVA_FILE_EXT, CLASS_FILE_EXT);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   250
        return new File(s);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   251
    }
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   252
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   253
    static File getJavaFile(File classFile) {
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   254
        String s = classFile.getAbsolutePath().replace(CLASS_FILE_EXT, JAVA_FILE_EXT);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   255
        return new File(s);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   256
    }
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   257
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   258
    static String baseName(File f) {
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   259
        String s = f.getName();
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   260
        return s.substring(0, s.indexOf("."));
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   261
    }
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   262
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   263
    /*
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   264
     * A convenience method to create a jar with jar file name and defs
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   265
     */
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   266
    static void createJar(File jarName, String... mainDefs)
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   267
            throws FileNotFoundException{
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   268
        createJar(null, jarName, new File("Foo"), mainDefs);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   269
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   270
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   271
    /*
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   272
     * A convenience method to create a java file, compile and jar it up, using
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   273
     * the sole class file name in the jar, as the Main-Class attribute value.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   274
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   275
    static void createJar(File jarName, File mainClass, String... mainDefs)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   276
            throws FileNotFoundException {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   277
            createJar(null, jarName, mainClass, mainDefs);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   278
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   279
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   280
    /*
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   281
     * A convenience method to compile java files.
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   282
     */
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   283
    static void compile(String... compilerArgs) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   284
        if (compiler.run(null, null, null, compilerArgs) != 0) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   285
            String sarg = "";
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   286
            for (String x : compilerArgs) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   287
                sarg.concat(x + " ");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   288
            }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   289
            throw new Error("compilation failed: " + sarg);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   290
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   291
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   292
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   293
    /*
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   294
     * A generic jar file creator to create a java file, compile it
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   295
     * and jar it up, a specific Main-Class entry name in the
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   296
     * manifest can be specified or a null to use the sole class file name
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   297
     * as the Main-Class attribute value.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   298
     */
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   299
    static void createJar(String mEntry, File jarName, File mainClass,
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   300
            String... mainDefs) throws FileNotFoundException {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   301
        if (jarName.exists()) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   302
            jarName.delete();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   303
        }
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   304
        try (PrintStream ps = new PrintStream(new FileOutputStream(mainClass + ".java"))) {
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   305
            ps.println("public class Foo {");
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   306
            if (mainDefs != null) {
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   307
                for (String x : mainDefs) {
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   308
                    ps.println(x);
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   309
                }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   310
            }
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   311
            ps.println("}");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   312
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   313
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   314
        String compileArgs[] = {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   315
            mainClass + ".java"
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   316
        };
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   317
        if (compiler.run(null, null, null, compileArgs) != 0) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   318
            throw new RuntimeException("compilation failed " + mainClass + ".java");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   319
        }
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   320
        if (mEntry == null) {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   321
            mEntry = mainClass.getName();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   322
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   323
        String jarArgs[] = {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   324
            (debug) ? "cvfe" : "cfe",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   325
            jarName.getAbsolutePath(),
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   326
            mEntry,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   327
            mainClass.getName() + ".class"
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   328
        };
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   329
        createJar(jarArgs);
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   330
    }
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   331
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   332
   static void createJar(String... args) {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   333
        sun.tools.jar.Main jarTool =
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   334
                new sun.tools.jar.Main(System.out, System.err, "JarCreator");
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   335
        if (!jarTool.run(args)) {
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   336
            String message = "jar creation failed with command:";
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   337
            for (String x : args) {
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   338
                message = message.concat(" " + x);
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   339
            }
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   340
            throw new RuntimeException(message);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   341
        }
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9734
diff changeset
   342
   }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   343
13675
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   344
   static void copyStream(InputStream in, OutputStream out) throws IOException {
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   345
        byte[] buf = new byte[8192];
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   346
        int n = in.read(buf);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   347
        while (n > 0) {
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   348
            out.write(buf, 0, n);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   349
            n = in.read(buf);
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   350
        }
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   351
    }
c2999ee84468 7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents: 13416
diff changeset
   352
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   353
   static void copyFile(File src, File dst) throws IOException {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   354
        Path parent = dst.toPath().getParent();
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   355
        if (parent != null) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   356
            Files.createDirectories(parent);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   357
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   358
        Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   359
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   360
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   361
    static void createFile(File outFile, List<String> content) throws IOException {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   362
        Files.write(outFile.getAbsoluteFile().toPath(), content,
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   363
                Charset.defaultCharset(), CREATE_NEW);
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   364
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   365
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   366
    static void recursiveDelete(File target) throws IOException {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   367
        if (!target.exists()) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   368
            return;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   369
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   370
        Files.walkFileTree(target.toPath(), new SimpleFileVisitor<Path>() {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   371
            @Override
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   372
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   373
                try {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   374
                    Files.deleteIfExists(dir);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   375
                } catch (IOException ex) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   376
                    System.out.println("Error: could not delete: " + dir.toString());
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   377
                    System.out.println(ex.getMessage());
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   378
                    return FileVisitResult.TERMINATE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   379
                }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   380
                return FileVisitResult.CONTINUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   381
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   382
            @Override
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   383
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   384
                try {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   385
                    Files.deleteIfExists(file);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   386
                } catch (IOException ex) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   387
                    System.out.println("Error: could not delete: " + file.toString());
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   388
                    System.out.println(ex.getMessage());
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   389
                    return FileVisitResult.TERMINATE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   390
                }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   391
                return FileVisitResult.CONTINUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   392
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   393
        });
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   394
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   395
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   396
    static TestResult doExec(String...cmds) {
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   397
        return doExec(null, null, cmds);
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   398
    }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   399
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   400
    static TestResult doExec(Map<String, String> envToSet, String...cmds) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   401
        return doExec(envToSet, null, cmds);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   402
    }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   403
    /*
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   404
     * A method which executes a java cmd and returns the results in a container
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   405
     */
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   406
    static TestResult doExec(Map<String, String> envToSet,
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   407
                             Set<String> envToRemove, String...cmds) {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   408
        String cmdStr = "";
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   409
        for (String x : cmds) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   410
            cmdStr = cmdStr.concat(x + " ");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   411
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   412
        ProcessBuilder pb = new ProcessBuilder(cmds);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   413
        Map<String, String> env = pb.environment();
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   414
        if (envToRemove != null) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   415
            for (String key : envToRemove) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   416
                env.remove(key);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   417
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12301
diff changeset
   418
        }
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   419
        if (envToSet != null) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   420
            env.putAll(envToSet);
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   421
        }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   422
        BufferedReader rdr = null;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   423
        try {
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   424
            List<String> outputList = new ArrayList<>();
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   425
            pb.redirectErrorStream(true);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   426
            Process p = pb.start();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   427
            rdr = new BufferedReader(new InputStreamReader(p.getInputStream()));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   428
            String in = rdr.readLine();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   429
            while (in != null) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   430
                outputList.add(in);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   431
                in = rdr.readLine();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   432
            }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   433
            p.waitFor();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   434
            p.destroy();
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   435
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   436
            return new TestHelper.TestResult(cmdStr, p.exitValue(), outputList,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   437
                    env, new Throwable("current stack of the test"));
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   438
        } catch (Exception ex) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   439
            ex.printStackTrace();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   440
            throw new RuntimeException(ex.getMessage());
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   441
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   442
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   443
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   444
    static FileFilter createFilter(final String extension) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   445
        return new FileFilter() {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   446
            @Override
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   447
            public boolean accept(File pathname) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   448
                String name = pathname.getName();
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   449
                if (name.endsWith(extension)) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   450
                    return true;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   451
                }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   452
                return false;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   453
            }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   454
        };
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   455
    }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents: 11364
diff changeset
   456
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   457
    static boolean isEnglishLocale() {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   458
        return Locale.getDefault().getLanguage().equals("en");
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   459
    }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11679
diff changeset
   460
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   461
    /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   462
     * A class to encapsulate the test results and stuff, with some ease
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   463
     * of use methods to check the test results.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   464
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   465
    static class TestResult {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   466
        PrintWriter status;
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   467
        StringWriter sw;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   468
        int exitValue;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   469
        List<String> testOutput;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   470
        Map<String, String> env;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   471
        Throwable t;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   472
        boolean testStatus;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   473
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   474
        public TestResult(String str, int rv, List<String> oList,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   475
                Map<String, String> env, Throwable t) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   476
            sw = new StringWriter();
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   477
            status = new PrintWriter(sw);
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   478
            status.println("Executed command: " + str + "\n");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   479
            exitValue = rv;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   480
            testOutput = oList;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   481
            this.env = env;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   482
            this.t = t;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   483
            testStatus = true;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   484
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   485
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   486
        void appendError(String x) {
13416
9732a77088fe 7189944: (launcher) test/tools/launcher/Arrrrghs.java needs a couple of minor fixes
ksrini
parents: 13411
diff changeset
   487
            testStatus = false;
9732a77088fe 7189944: (launcher) test/tools/launcher/Arrrrghs.java needs a couple of minor fixes
ksrini
parents: 13411
diff changeset
   488
            testExitValue++;
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   489
            status.println(TEST_PREFIX + x);
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   490
        }
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   491
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   492
        void indentStatus(String x) {
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   493
            status.println("  " + x);
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   494
        }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   495
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   496
        void checkNegative() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   497
            if (exitValue == 0) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   498
                appendError("test must not return 0 exit value");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   499
            }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   500
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   501
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   502
        void checkPositive() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   503
            if (exitValue != 0) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   504
                appendError("test did not return 0 exit value");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   505
            }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   506
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   507
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   508
        boolean isOK() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   509
            return exitValue == 0;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   510
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   511
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   512
        boolean isZeroOutput() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   513
            if (!testOutput.isEmpty()) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   514
                appendError("No message from cmd please");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   515
                return false;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   516
            }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   517
            return true;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   518
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   519
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   520
        boolean isNotZeroOutput() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   521
            if (testOutput.isEmpty()) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   522
                appendError("Missing message");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   523
                return false;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   524
            }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   525
            return true;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   526
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   527
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   528
        @Override
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   529
        public String toString() {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   530
            status.println("++++Begin Test Info++++");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   531
            status.println("Test Status: " + (testStatus ? "PASS" : "FAIL"));
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   532
            status.println("++++Test Environment++++");
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   533
            for (String x : env.keySet()) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   534
                indentStatus(x + "=" + env.get(x));
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   535
            }
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   536
            status.println("++++Test Output++++");
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   537
            for (String x : testOutput) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   538
                indentStatus(x);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   539
            }
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   540
            status.println("++++Test Stack Trace++++");
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   541
            status.println(t.toString());
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   542
            for (StackTraceElement e : t.getStackTrace()) {
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   543
                indentStatus(e.toString());
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 5506
diff changeset
   544
            }
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   545
            status.println("++++End of Test Info++++");
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   546
            status.flush();
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   547
            String out = sw.toString();
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   548
            status.close();
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   549
            return out;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   550
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   551
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   552
        boolean contains(String str) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   553
            for (String x : testOutput) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   554
                if (x.contains(str)) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   555
                    return true;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   556
                }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   557
            }
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   558
            appendError("string <" + str + "> not found");
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   559
            return false;
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   560
        }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   561
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   562
        boolean matches(String stringToMatch) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   563
          for (String x : testOutput) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   564
                if (x.matches(stringToMatch)) {
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   565
                    return true;
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   566
                }
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1329
diff changeset
   567
            }
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 12538
diff changeset
   568
            appendError("string <" + stringToMatch + "> not found");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   569
            return false;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   570
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   571
    }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   572
    /**
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   573
    * Indicates that the annotated method is a test method.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   574
    */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   575
    @Retention(RetentionPolicy.RUNTIME)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   576
    @Target(ElementType.METHOD)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12561
diff changeset
   577
    public @interface Test {}
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   578
}