jdk/src/share/classes/sun/launcher/LauncherHelper.java
author alanb
Thu, 15 Aug 2013 11:54:05 +0100
changeset 19409 d7c7b9d56631
parent 15687 9f473a0b9e86
child 20179 fa41a3d5805e
permissions -rw-r--r--
8022921: Remove experimental Profile attribute Reviewed-by: mchung, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     1
/*
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
     2
 * Copyright (c) 2007, 2013, 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2168
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2168
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    10
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    11
 * 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
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    14
 * 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
    15
 * accompanied this code).
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    16
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    17
 * 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
    18
 * 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
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2168
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2168
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2168
diff changeset
    23
 * questions.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    24
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    25
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    26
package sun.launcher;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    27
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    28
/*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    29
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    30
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    31
 *  If you write code that depends on this, you do so at your own
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    32
 *  risk.  This code and its internal interfaces are subject to change
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    33
 *  or deletion without notice.</b>
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    34
 *
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    35
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    36
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    37
/**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    38
 * A utility package for the java(1), javaw(1) launchers.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    39
 * The following are helper methods that the native launcher uses
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    40
 * to perform checks etc. using JNI, see src/share/bin/java.c
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    41
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    42
import java.io.File;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    43
import java.io.IOException;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    44
import java.io.PrintStream;
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
    45
import java.io.UnsupportedEncodingException;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    46
import java.lang.reflect.Method;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    47
import java.lang.reflect.Modifier;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    48
import java.math.BigDecimal;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    49
import java.math.RoundingMode;
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
    50
import java.nio.charset.Charset;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
    51
import java.nio.file.DirectoryStream;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
    52
import java.nio.file.Files;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
    53
import java.nio.file.Path;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    54
import java.util.ResourceBundle;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    55
import java.text.MessageFormat;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    56
import java.util.ArrayList;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    57
import java.util.Collections;
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    58
import java.util.Iterator;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    59
import java.util.List;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    60
import java.util.Locale;
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    61
import java.util.Locale.Category;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    62
import java.util.Properties;
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    63
import java.util.Set;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
    64
import java.util.TreeSet;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    65
import java.util.jar.Attributes;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    66
import java.util.jar.JarFile;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    67
import java.util.jar.Manifest;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    68
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    69
public enum LauncherHelper {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    70
    INSTANCE;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    71
    private static final String MAIN_CLASS = "Main-Class";
15682
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 15003
diff changeset
    72
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    73
    private static StringBuilder outBuf = new StringBuilder();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
    74
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    75
    private static final String INDENT = "    ";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    76
    private static final String VM_SETTINGS     = "VM settings:";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    77
    private static final String PROP_SETTINGS   = "Property settings:";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    78
    private static final String LOCALE_SETTINGS = "Locale settings:";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    79
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    80
    // sync with java.c and sun.misc.VM
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    81
    private static final String diagprop = "sun.java.launcher.diag";
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
    82
    final static boolean trace = sun.misc.VM.getSavedProperty(diagprop) != null;
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    83
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    84
    private static final String defaultBundleName =
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    85
            "sun.launcher.resources.launcher";
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    86
    private static class ResourceBundleHolder {
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    87
        private static final ResourceBundle RB =
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
    88
                ResourceBundle.getBundle(defaultBundleName);
2168
de3c5a0416de 6801467: Defer get the launcher resource bundle until it's needed
mchung
parents: 1343
diff changeset
    89
    }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
    90
    private static PrintStream ostream;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
    91
    private static final ClassLoader scloader = ClassLoader.getSystemClassLoader();
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
    92
    private static Class<?> appClass; // application class, for GUI/reporting purposes
2168
de3c5a0416de 6801467: Defer get the launcher resource bundle until it's needed
mchung
parents: 1343
diff changeset
    93
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    94
    /*
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    95
     * A method called by the launcher to print out the standard settings,
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    96
     * by default -XshowSettings is equivalent to -XshowSettings:all,
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    97
     * Specific information may be gotten by using suboptions with possible
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    98
     * values vm, properties and locale.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
    99
     *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   100
     * printToStderr: choose between stdout and stderr
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   101
     *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   102
     * optionFlag: specifies which options to print default is all other
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   103
     *    possible values are vm, properties, locale.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   104
     *
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   105
     * initialHeapSize: in bytes, as set by the launcher, a zero-value indicates
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   106
     *    this code should determine this value, using a suitable method or
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   107
     *    the line could be omitted.
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   108
     *
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   109
     * maxHeapSize: in bytes, as set by the launcher, a zero-value indicates
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   110
     *    this code should determine this value, using a suitable method.
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   111
     *
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   112
     * stackSize: in bytes, as set by the launcher, a zero-value indicates
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   113
     *    this code determine this value, using a suitable method or omit the
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   114
     *    line entirely.
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   115
     */
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   116
    static void showSettings(boolean printToStderr, String optionFlag,
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   117
            long initialHeapSize, long maxHeapSize, long stackSize,
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   118
            boolean isServer) {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   119
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   120
        initOutput(printToStderr);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   121
        String opts[] = optionFlag.split(":");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   122
        String optStr = (opts.length > 1 && opts[1] != null)
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   123
                ? opts[1].trim()
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   124
                : "all";
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   125
        switch (optStr) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   126
            case "vm":
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   127
                printVmSettings(initialHeapSize, maxHeapSize,
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   128
                                stackSize, isServer);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   129
                break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   130
            case "properties":
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   131
                printProperties();
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   132
                break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   133
            case "locale":
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   134
                printLocale();
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   135
                break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   136
            default:
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   137
                printVmSettings(initialHeapSize, maxHeapSize, stackSize,
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   138
                                isServer);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   139
                printProperties();
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   140
                printLocale();
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   141
                break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   142
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   143
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   144
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   145
    /*
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   146
     * prints the main vm settings subopt/section
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   147
     */
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   148
    private static void printVmSettings(
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   149
            long initialHeapSize, long maxHeapSize,
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   150
            long stackSize, boolean isServer) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   151
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   152
        ostream.println(VM_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   153
        if (stackSize != 0L) {
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   154
            ostream.println(INDENT + "Stack Size: " +
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   155
                    SizePrefix.scaleValue(stackSize));
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   156
        }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   157
        if (initialHeapSize != 0L) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   158
             ostream.println(INDENT + "Min. Heap Size: " +
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   159
                    SizePrefix.scaleValue(initialHeapSize));
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   160
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   161
        if (maxHeapSize != 0L) {
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   162
            ostream.println(INDENT + "Max. Heap Size: " +
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   163
                    SizePrefix.scaleValue(maxHeapSize));
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   164
        } else {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   165
            ostream.println(INDENT + "Max. Heap Size (Estimated): "
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   166
                    + SizePrefix.scaleValue(Runtime.getRuntime().maxMemory()));
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   167
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   168
        ostream.println(INDENT + "Ergonomics Machine Class: "
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   169
                + ((isServer) ? "server" : "client"));
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   170
        ostream.println(INDENT + "Using VM: "
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   171
                + System.getProperty("java.vm.name"));
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   172
        ostream.println();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   173
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   174
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   175
    /*
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   176
     * prints the properties subopt/section
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   177
     */
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   178
    private static void printProperties() {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   179
        Properties p = System.getProperties();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   180
        ostream.println(PROP_SETTINGS);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   181
        List<String> sortedPropertyKeys = new ArrayList<>();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   182
        sortedPropertyKeys.addAll(p.stringPropertyNames());
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   183
        Collections.sort(sortedPropertyKeys);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   184
        for (String x : sortedPropertyKeys) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   185
            printPropertyValue(x, p.getProperty(x));
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   186
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   187
        ostream.println();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   188
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   189
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   190
    private static boolean isPath(String key) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   191
        return key.endsWith(".dirs") || key.endsWith(".path");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   192
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   193
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   194
    private static void printPropertyValue(String key, String value) {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   195
        ostream.print(INDENT + key + " = ");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   196
        if (key.equals("line.separator")) {
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   197
            for (byte b : value.getBytes()) {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   198
                switch (b) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   199
                    case 0xd:
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   200
                        ostream.print("\\r ");
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   201
                        break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   202
                    case 0xa:
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   203
                        ostream.print("\\n ");
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   204
                        break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   205
                    default:
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   206
                        // print any bizzare line separators in hex, but really
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   207
                        // shouldn't happen.
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   208
                        ostream.printf("0x%02X", b & 0xff);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   209
                        break;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   210
                }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   211
            }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   212
            ostream.println();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   213
            return;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   214
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   215
        if (!isPath(key)) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   216
            ostream.println(value);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   217
            return;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   218
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   219
        String[] values = value.split(System.getProperty("path.separator"));
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   220
        boolean first = true;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   221
        for (String s : values) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   222
            if (first) { // first line treated specially
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   223
                ostream.println(s);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   224
                first = false;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   225
            } else { // following lines prefix with indents
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   226
                ostream.println(INDENT + INDENT + s);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   227
            }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   228
        }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   229
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   230
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   231
    /*
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   232
     * prints the locale subopt/section
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   233
     */
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   234
    private static void printLocale() {
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   235
        Locale locale = Locale.getDefault();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   236
        ostream.println(LOCALE_SETTINGS);
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   237
        ostream.println(INDENT + "default locale = " +
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   238
                locale.getDisplayLanguage());
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   239
        ostream.println(INDENT + "default display locale = " +
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   240
                Locale.getDefault(Category.DISPLAY).getDisplayName());
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   241
        ostream.println(INDENT + "default format locale = " +
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   242
                Locale.getDefault(Category.FORMAT).getDisplayName());
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   243
        printLocales();
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   244
        ostream.println();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   245
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   246
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   247
    private static void printLocales() {
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   248
        Locale[] tlocales = Locale.getAvailableLocales();
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   249
        final int len = tlocales == null ? 0 : tlocales.length;
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   250
        if (len < 1 ) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   251
            return;
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   252
        }
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   253
        // Locale does not implement Comparable so we convert it to String
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   254
        // and sort it for pretty printing.
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   255
        Set<String> sortedSet = new TreeSet<>();
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   256
        for (Locale l : tlocales) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   257
            sortedSet.add(l.toString());
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   258
        }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   259
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   260
        ostream.print(INDENT + "available locales = ");
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   261
        Iterator<String> iter = sortedSet.iterator();
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   262
        final int last = len - 1;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   263
        for (int i = 0 ; iter.hasNext() ; i++) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   264
            String s = iter.next();
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   265
            ostream.print(s);
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   266
            if (i != last) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   267
                ostream.print(", ");
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   268
            }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   269
            // print columns of 8
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   270
            if ((i + 1) % 8 == 0) {
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   271
                ostream.println();
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   272
                ostream.print(INDENT + INDENT);
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   273
            }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   274
        }
7810
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   275
    }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   276
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   277
    private enum SizePrefix {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   278
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   279
        KILO(1024, "K"),
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   280
        MEGA(1024 * 1024, "M"),
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   281
        GIGA(1024 * 1024 * 1024, "G"),
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   282
        TERA(1024L * 1024L * 1024L * 1024L, "T");
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   283
        long size;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   284
        String abbrev;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   285
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   286
        SizePrefix(long size, String abbrev) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   287
            this.size = size;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   288
            this.abbrev = abbrev;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   289
        }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   290
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   291
        private static String scale(long v, SizePrefix prefix) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   292
            return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size),
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   293
                    2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev;
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   294
        }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   295
        /*
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   296
         * scale the incoming values to a human readable form, represented as
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   297
         * K, M, G and T, see java.c parse_size for the scaled values and
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   298
         * suffixes. The lowest possible scaled value is Kilo.
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   299
         */
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   300
        static String scaleValue(long v) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   301
            if (v < MEGA.size) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   302
                return scale(v, KILO);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   303
            } else if (v < GIGA.size) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   304
                return scale(v, MEGA);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   305
            } else if (v < TERA.size) {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   306
                return scale(v, GIGA);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   307
            } else {
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   308
                return scale(v, TERA);
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   309
            }
d4730191e53c 7002386: (launcher) fix XshowSettings
ksrini
parents: 7297
diff changeset
   310
        }
7297
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   311
    }
906c58a8b849 6452854: Provide a flag to print the java configuration
ksrini
parents: 5982
diff changeset
   312
1323
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
     * A private helper method to get a localized message and also
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   315
     * apply any arguments that we might pass.
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
    private static String getLocalizedMessage(String key, Object... args) {
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   318
        String msg = ResourceBundleHolder.RB.getString(key);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   319
        return (args != null) ? MessageFormat.format(msg, args) : msg;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   320
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   321
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
     * The java -help message is split into 3 parts, an invariant, followed
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   324
     * by a set of platform dependent variant messages, finally an invariant
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   325
     * set of lines.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   326
     * This method initializes the help message for the first time, and also
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   327
     * assembles the invariant header part of the message.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   328
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   329
    static void initHelpMessage(String progname) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   330
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.header",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   331
                (progname == null) ? "java" : progname ));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   332
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.datamodel",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   333
                32));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   334
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.datamodel",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   335
                64));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   336
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   337
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   338
    /**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   339
     * Appends the vm selection messages to the header, already created.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   340
     * initHelpSystem must already be called.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   341
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   342
    static void appendVmSelectMessage(String vm1, String vm2) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   343
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.vmselect",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   344
                vm1, vm2));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   345
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   346
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   347
    /**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   348
     * Appends the vm synoym message to the header, already created.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   349
     * initHelpSystem must be called before using this method.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   350
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   351
    static void appendVmSynonymMessage(String vm1, String vm2) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   352
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.hotspot",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   353
                vm1, vm2));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   354
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   355
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   356
    /**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   357
     * Appends the vm Ergo message to the header, already created.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   358
     * initHelpSystem must be called before using this method.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   359
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   360
    static void appendVmErgoMessage(boolean isServerClass, String vm) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   361
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.ergo.message1",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   362
                vm));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   363
        outBuf = (isServerClass)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   364
             ? outBuf.append(",\n" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   365
                getLocalizedMessage("java.launcher.ergo.message2") + "\n\n")
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   366
             : outBuf.append(".\n\n");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   367
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   368
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   369
    /**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   370
     * Appends the last invariant part to the previously created messages,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   371
     * and finishes up the printing to the desired output stream.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   372
     * initHelpSystem must be called before using this method.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   373
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   374
    static void printHelpMessage(boolean printToStderr) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   375
        initOutput(printToStderr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   376
        outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.footer",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   377
                File.pathSeparator));
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   378
        ostream.println(outBuf.toString());
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   379
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   380
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   381
    /**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   382
     * Prints the Xusage text to the desired output stream.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   383
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   384
    static void printXUsageMessage(boolean printToStderr) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   385
        initOutput(printToStderr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   386
        ostream.println(getLocalizedMessage("java.launcher.X.usage",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   387
                File.pathSeparator));
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12047
diff changeset
   388
        if (System.getProperty("os.name").contains("OS X")) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11125
diff changeset
   389
            ostream.println(getLocalizedMessage("java.launcher.X.macosx.usage",
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11125
diff changeset
   390
                        File.pathSeparator));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11125
diff changeset
   391
        }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   392
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   393
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   394
    static void initOutput(boolean printToStderr) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   395
        ostream =  (printToStderr) ? System.err : System.out;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   396
    }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   397
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   398
    static String getMainClassFromJar(String jarname) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   399
        String mainValue = null;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   400
        try (JarFile jarFile = new JarFile(jarname)) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   401
            Manifest manifest = jarFile.getManifest();
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   402
            if (manifest == null) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   403
                abort(null, "java.launcher.jar.error2", jarname);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   404
            }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   405
            Attributes mainAttrs = manifest.getMainAttributes();
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   406
            if (mainAttrs == null) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   407
                abort(null, "java.launcher.jar.error3", jarname);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   408
            }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   409
            mainValue = mainAttrs.getValue(MAIN_CLASS);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   410
            if (mainValue == null) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   411
                abort(null, "java.launcher.jar.error3", jarname);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   412
            }
15682
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 15003
diff changeset
   413
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 15003
diff changeset
   414
            /*
15687
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   415
             * Hand off to FXHelper if it detects a JavaFX application
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   416
             * This must be done after ensuring a Main-Class entry
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   417
             * exists to enforce compliance with the jar specification
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   418
             */
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   419
            if (mainAttrs.containsKey(
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   420
                    new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   421
                return FXHelper.class.getName();
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   422
            }
9f473a0b9e86 8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents: 15682
diff changeset
   423
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   424
            return mainValue.trim();
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   425
        } catch (IOException ioe) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   426
            abort(ioe, "java.launcher.jar.error1", jarname);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   427
        }
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   428
        return null;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   429
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   430
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   431
    // From src/share/bin/java.c:
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   432
    //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR };
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   433
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   434
    private static final int LM_UNKNOWN = 0;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   435
    private static final int LM_CLASS   = 1;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   436
    private static final int LM_JAR     = 2;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   437
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   438
    static void abort(Throwable t, String msgKey, Object... args) {
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   439
        if (msgKey != null) {
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   440
            ostream.println(getLocalizedMessage(msgKey, args));
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   441
        }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   442
        if (trace) {
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   443
            if (t != null) {
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   444
                t.printStackTrace();
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   445
            } else {
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 10126
diff changeset
   446
                Thread.dumpStack();
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   447
            }
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   448
        }
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   449
        System.exit(1);
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   450
    }
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   451
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   452
    /**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   453
     * This method does the following:
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   454
     * 1. gets the classname from a Jar's manifest, if necessary
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   455
     * 2. loads the class using the System ClassLoader
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   456
     * 3. ensures the availability and accessibility of the main method,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   457
     *    using signatureDiagnostic method.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   458
     *    a. does the class exist
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   459
     *    b. is there a main
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   460
     *    c. is the main public
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   461
     *    d. is the main static
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   462
     *    e. does the main take a String array for args
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   463
     * 4. if no main method and if the class extends FX Application, then call
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   464
     *    on FXHelper to determine the main class to launch
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   465
     * 5. and off we go......
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   466
     *
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   467
     * @param printToStderr if set, all output will be routed to stderr
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   468
     * @param mode LaunchMode as determined by the arguments passed on the
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   469
     * command line
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   470
     * @param what either the jar file to launch or the main class when using
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   471
     * LM_CLASS mode
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   472
     * @return the application's main class
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   473
     */
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   474
    public static Class<?> checkAndLoadMain(boolean printToStderr,
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   475
                                            int mode,
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   476
                                            String what) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   477
        initOutput(printToStderr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   478
        // get the class name
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   479
        String cn = null;
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   480
        switch (mode) {
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   481
            case LM_CLASS:
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   482
                cn = what;
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   483
                break;
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   484
            case LM_JAR:
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   485
                cn = getMainClassFromJar(what);
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   486
                break;
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   487
            default:
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   488
                // should never happen
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7997
diff changeset
   489
                throw new InternalError("" + mode + ": Unknown launch mode");
7997
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   490
        }
78536cac0841 6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents: 7810
diff changeset
   491
        cn = cn.replace('/', '.');
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   492
        Class<?> mainClass = null;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   493
        try {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   494
            mainClass = scloader.loadClass(cn);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   495
        } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   496
            abort(cnfe, "java.launcher.cls.error1", cn);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   497
        }
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   498
        // set to mainClass
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   499
        appClass = mainClass;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   500
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   501
        /*
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   502
         * Check if FXHelper can launch it using the FX launcher. In an FX app,
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   503
         * the main class may or may not have a main method, so do this before
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   504
         * validating the main class.
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   505
         */
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   506
        if (mainClass.equals(FXHelper.class) ||
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   507
                FXHelper.doesExtendFXApplication(mainClass)) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   508
            // Will abort() if there are problems with the FX runtime
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   509
            FXHelper.setFXLaunchParameters(what, mode);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   510
            return FXHelper.class;
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   511
        }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   512
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   513
        validateMainClass(mainClass);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   514
        return mainClass;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   515
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   516
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   517
    /*
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   518
     * Accessor method called by the launcher after getting the main class via
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   519
     * checkAndLoadMain(). The "application class" is the class that is finally
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   520
     * executed to start the application and in this case is used to report
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   521
     * the correct application name, typically for UI purposes.
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   522
     */
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   523
    public static Class<?> getApplicationClass() {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   524
        return appClass;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   525
    }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   526
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   527
    // Check the existence and signature of main and abort if incorrect
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   528
    static void validateMainClass(Class<?> mainClass) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   529
        Method mainMethod;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   530
        try {
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   531
            mainMethod = mainClass.getMethod("main", String[].class);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   532
        } catch (NoSuchMethodException nsme) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   533
            // invalid main or not FX application, abort with an error
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   534
            abort(null, "java.launcher.cls.error4", mainClass.getName(),
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   535
                  FXHelper.JAVAFX_APPLICATION_CLASS_NAME);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   536
            return; // Avoid compiler issues
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   537
        }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   538
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   539
        /*
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   540
         * getMethod (above) will choose the correct method, based
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   541
         * on its name and parameter type, however, we still have to
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   542
         * ensure that the method is static and returns a void.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   543
         */
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   544
        int mod = mainMethod.getModifiers();
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   545
        if (!Modifier.isStatic(mod)) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   546
            abort(null, "java.launcher.cls.error2", "static",
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   547
                  mainMethod.getDeclaringClass().getName());
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   548
        }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   549
        if (mainMethod.getReturnType() != java.lang.Void.TYPE) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   550
            abort(null, "java.launcher.cls.error3",
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   551
                  mainMethod.getDeclaringClass().getName());
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   552
        }
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   553
    }
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   554
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   555
    private static final String encprop = "sun.jnu.encoding";
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   556
    private static String encoding = null;
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   557
    private static boolean isCharsetSupported = false;
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   558
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   559
    /*
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   560
     * converts a c or a byte array to a platform specific string,
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   561
     * previously implemented as a native method in the launcher.
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   562
     */
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   563
    static String makePlatformString(boolean printToStderr, byte[] inArray) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   564
        initOutput(printToStderr);
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   565
        if (encoding == null) {
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   566
            encoding = System.getProperty(encprop);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   567
            isCharsetSupported = Charset.isSupported(encoding);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   568
        }
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   569
        try {
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   570
            String out = isCharsetSupported
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   571
                    ? new String(inArray, encoding)
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   572
                    : new String(inArray);
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   573
            return out;
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   574
        } catch (UnsupportedEncodingException uee) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   575
            abort(uee, null);
8806
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   576
        }
c81d4e10ffb7 7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents: 8174
diff changeset
   577
        return null; // keep the compiler happy
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   578
    }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   579
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   580
    static String[] expandArgs(String[] argArray) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   581
        List<StdArg> aList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   582
        for (String x : argArray) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   583
            aList.add(new StdArg(x));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   584
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   585
        return expandArgs(aList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   586
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   587
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   588
    static String[] expandArgs(List<StdArg> argList) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   589
        ArrayList<String> out = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   590
        if (trace) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   591
            System.err.println("Incoming arguments:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   592
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   593
        for (StdArg a : argList) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   594
            if (trace) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   595
                System.err.println(a);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   596
            }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   597
            if (a.needsExpansion) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   598
                File x = new File(a.arg);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   599
                File parent = x.getParentFile();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   600
                String glob = x.getName();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   601
                if (parent == null) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   602
                    parent = new File(".");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   603
                }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   604
                try (DirectoryStream<Path> dstream =
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   605
                        Files.newDirectoryStream(parent.toPath(), glob)) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   606
                    int entries = 0;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   607
                    for (Path p : dstream) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   608
                        out.add(p.normalize().toString());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   609
                        entries++;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   610
                    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   611
                    if (entries == 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   612
                        out.add(a.arg);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   613
                    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   614
                } catch (Exception e) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   615
                    out.add(a.arg);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   616
                    if (trace) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   617
                        System.err.println("Warning: passing argument as-is " + a);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   618
                        System.err.print(e);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   619
                    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   620
                }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   621
            } else {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   622
                out.add(a.arg);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   623
            }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   624
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   625
        String[] oarray = new String[out.size()];
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   626
        out.toArray(oarray);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   627
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   628
        if (trace) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   629
            System.err.println("Expanded arguments:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   630
            for (String x : oarray) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   631
                System.err.println(x);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   632
            }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   633
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   634
        return oarray;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   635
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   636
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   637
    /* duplicate of the native StdArg struct */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   638
    private static class StdArg {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   639
        final String arg;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   640
        final boolean needsExpansion;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   641
        StdArg(String arg, boolean expand) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   642
            this.arg = arg;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   643
            this.needsExpansion = expand;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   644
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   645
        // protocol: first char indicates whether expansion is required
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   646
        // 'T' = true ; needs expansion
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   647
        // 'F' = false; needs no expansion
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   648
        StdArg(String in) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   649
            this.arg = in.substring(1);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   650
            needsExpansion = in.charAt(0) == 'T';
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   651
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   652
        public String toString() {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   653
            return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}';
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   654
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12538
diff changeset
   655
    }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   656
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   657
    static final class FXHelper {
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   658
        // Marker entry in jar manifest that designates a JavaFX application jar
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   659
        private static final String JAVAFX_APPLICATION_MARKER =
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   660
                "JavaFX-Application-Class";
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   661
        private static final String JAVAFX_APPLICATION_CLASS_NAME =
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   662
                "javafx.application.Application";
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   663
        private static final String JAVAFX_LAUNCHER_CLASS_NAME =
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   664
                "com.sun.javafx.application.LauncherImpl";
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   665
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   666
        /*
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   667
         * The launch method used to invoke the JavaFX launcher. These must
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   668
         * match the strings used in the launchApplication method.
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   669
         *
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   670
         * Command line                 JavaFX-App-Class  Launch mode  FX Launch mode
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   671
         * java -cp fxapp.jar FXClass   N/A               LM_CLASS     "LM_CLASS"
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   672
         * java -cp somedir FXClass     N/A               LM_CLASS     "LM_CLASS"
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   673
         * java -jar fxapp.jar          Present           LM_JAR       "LM_JAR"
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   674
         * java -jar fxapp.jar          Not Present       LM_JAR       "LM_JAR"
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   675
         */
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   676
        private static final String JAVAFX_LAUNCH_MODE_CLASS = "LM_CLASS";
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   677
        private static final String JAVAFX_LAUNCH_MODE_JAR = "LM_JAR";
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   678
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   679
        /*
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   680
         * FX application launcher and launch method, so we can launch
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   681
         * applications with no main method.
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   682
         */
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   683
        private static String fxLaunchName = null;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   684
        private static String fxLaunchMode = null;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   685
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   686
        private static Class<?> fxLauncherClass    = null;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   687
        private static Method   fxLauncherMethod   = null;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   688
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   689
        /*
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   690
         * Set the launch params according to what was passed to LauncherHelper
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   691
         * so we can use the same launch mode for FX. Abort if there is any
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   692
         * issue with loading the FX runtime or with the launcher method.
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   693
         */
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   694
        private static void setFXLaunchParameters(String what, int mode) {
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   695
            // Check for the FX launcher classes
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   696
            try {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   697
                fxLauncherClass = scloader.loadClass(JAVAFX_LAUNCHER_CLASS_NAME);
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   698
                /*
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   699
                 * signature must be:
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   700
                 * public static void launchApplication(String launchName,
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   701
                 *     String launchMode, String[] args);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   702
                 */
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   703
                fxLauncherMethod = fxLauncherClass.getMethod("launchApplication",
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   704
                        String.class, String.class, String[].class);
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   705
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   706
                // verify launcher signature as we do when validating the main method
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   707
                int mod = fxLauncherMethod.getModifiers();
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   708
                if (!Modifier.isStatic(mod)) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   709
                    abort(null, "java.launcher.javafx.error1");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   710
                }
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   711
                if (fxLauncherMethod.getReturnType() != java.lang.Void.TYPE) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   712
                    abort(null, "java.launcher.javafx.error1");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   713
                }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   714
            } catch (ClassNotFoundException | NoSuchMethodException ex) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   715
                abort(ex, "java.launcher.cls.error5", ex);
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   716
            }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   717
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   718
            fxLaunchName = what;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   719
            switch (mode) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   720
                case LM_CLASS:
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   721
                    fxLaunchMode = JAVAFX_LAUNCH_MODE_CLASS;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   722
                    break;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   723
                case LM_JAR:
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   724
                    fxLaunchMode = JAVAFX_LAUNCH_MODE_JAR;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   725
                    break;
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   726
                default:
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   727
                    // should not have gotten this far...
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   728
                    throw new InternalError(mode + ": Unknown launch mode");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   729
            }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   730
        }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   731
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   732
        /*
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   733
         * Check if the given class is a JavaFX Application class. This is done
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   734
         * in a way that does not cause the Application class to load or throw
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   735
         * ClassNotFoundException if the JavaFX runtime is not available.
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   736
         */
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   737
        private static boolean doesExtendFXApplication(Class<?> mainClass) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   738
            for (Class<?> sc = mainClass.getSuperclass(); sc != null;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   739
                    sc = sc.getSuperclass()) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   740
                if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) {
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   741
                    return true;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   742
                }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   743
            }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   744
            return false;
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   745
        }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   746
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   747
        public static void main(String... args) throws Exception {
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   748
            if (fxLauncherMethod == null
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   749
                    || fxLaunchMode == null
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   750
                    || fxLaunchName == null) {
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   751
                throw new RuntimeException("Invalid JavaFX launch parameters");
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   752
            }
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   753
            // launch appClass via fxLauncherMethod
15003
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   754
            fxLauncherMethod.invoke(null,
364408faddeb 8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents: 14518
diff changeset
   755
                    new Object[] {fxLaunchName, fxLaunchMode, args});
14518
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   756
        }
f4b1adde53b3 8001533: java launcher must launch javafx applications
ksrini
parents: 13411
diff changeset
   757
    }
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff changeset
   758
}