author | mchung |
Wed, 10 Aug 2016 15:51:25 -0700 | |
changeset 40261 | 86a49ba76f52 |
parent 39345 | 344e8211e184 |
child 41966 | bac52fa6e617 |
permissions | -rw-r--r-- |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
1 |
/* |
36511 | 2 |
* Copyright (c) 2007, 2015, 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 | 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 | 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 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
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; |
36511 | 46 |
import java.lang.module.ModuleFinder; |
47 |
import java.lang.module.ModuleReference; |
|
48 |
import java.lang.module.ModuleDescriptor; |
|
49 |
import java.lang.module.ModuleDescriptor.Requires; |
|
50 |
import java.lang.module.ModuleDescriptor.Exports; |
|
51 |
import java.lang.module.ModuleDescriptor.Provides; |
|
52 |
import java.lang.reflect.Layer; |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
53 |
import java.lang.reflect.Method; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
54 |
import java.lang.reflect.Modifier; |
36511 | 55 |
import java.lang.reflect.Module; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
56 |
import java.math.BigDecimal; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
57 |
import java.math.RoundingMode; |
36511 | 58 |
import java.net.URI; |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
59 |
import java.nio.charset.Charset; |
13411
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
60 |
import java.nio.file.DirectoryStream; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
61 |
import java.nio.file.Files; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
62 |
import java.nio.file.Path; |
20179 | 63 |
import java.text.Normalizer; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
64 |
import java.text.MessageFormat; |
36511 | 65 |
import java.util.ResourceBundle; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
66 |
import java.util.ArrayList; |
36511 | 67 |
import java.util.Collection; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
68 |
import java.util.Collections; |
36511 | 69 |
import java.util.Comparator; |
7810 | 70 |
import java.util.Iterator; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
71 |
import java.util.List; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
72 |
import java.util.Locale; |
7810 | 73 |
import java.util.Locale.Category; |
36511 | 74 |
import java.util.Optional; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
75 |
import java.util.Properties; |
36511 | 76 |
import java.util.Map; |
7810 | 77 |
import java.util.Set; |
78 |
import java.util.TreeSet; |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
79 |
import java.util.jar.Attributes; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
80 |
import java.util.jar.JarFile; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
81 |
import java.util.jar.Manifest; |
34882 | 82 |
import jdk.internal.misc.VM; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
83 |
|
36511 | 84 |
|
37788
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
85 |
public final class LauncherHelper { |
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
86 |
|
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
87 |
// No instantiation |
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
88 |
private LauncherHelper() {} |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
89 |
|
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
90 |
// used to identify JavaFX applications |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
91 |
private static final String JAVAFX_APPLICATION_MARKER = |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
92 |
"JavaFX-Application-Class"; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
93 |
private static final String JAVAFX_APPLICATION_CLASS_NAME = |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
94 |
"javafx.application.Application"; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
95 |
private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX = |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
96 |
"sun.launcher.LauncherHelper$FXHelper"; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
97 |
private static final String MAIN_CLASS = "Main-Class"; |
15682
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
15003
diff
changeset
|
98 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
99 |
private static StringBuilder outBuf = new StringBuilder(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
100 |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
101 |
private static final String INDENT = " "; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
102 |
private static final String VM_SETTINGS = "VM settings:"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
103 |
private static final String PROP_SETTINGS = "Property settings:"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
104 |
private static final String LOCALE_SETTINGS = "Locale settings:"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
105 |
|
34882 | 106 |
// sync with java.c and jdk.internal.misc.VM |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
107 |
private static final String diagprop = "sun.java.launcher.diag"; |
34882 | 108 |
static final boolean trace = VM.getSavedProperty(diagprop) != null; |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
109 |
|
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
110 |
private static final String defaultBundleName = |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
111 |
"sun.launcher.resources.launcher"; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
112 |
private static class ResourceBundleHolder { |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
113 |
private static final ResourceBundle RB = |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
114 |
ResourceBundle.getBundle(defaultBundleName); |
2168
de3c5a0416de
6801467: Defer get the launcher resource bundle until it's needed
mchung
parents:
1343
diff
changeset
|
115 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
116 |
private static PrintStream ostream; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
117 |
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
|
118 |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
119 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
120 |
* 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
|
121 |
* by default -XshowSettings is equivalent to -XshowSettings:all, |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
122 |
* 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
|
123 |
* values vm, properties and locale. |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
124 |
* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
125 |
* printToStderr: choose between stdout and stderr |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
126 |
* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
127 |
* 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
|
128 |
* possible values are vm, properties, locale. |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
129 |
* |
7810 | 130 |
* initialHeapSize: in bytes, as set by the launcher, a zero-value indicates |
131 |
* this code should determine this value, using a suitable method or |
|
132 |
* the line could be omitted. |
|
133 |
* |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
134 |
* 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
|
135 |
* 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
|
136 |
* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
137 |
* stackSize: in bytes, as set by the launcher, a zero-value indicates |
7810 | 138 |
* this code determine this value, using a suitable method or omit the |
139 |
* line entirely. |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
140 |
*/ |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
141 |
static void showSettings(boolean printToStderr, String optionFlag, |
7810 | 142 |
long initialHeapSize, long maxHeapSize, long stackSize, |
143 |
boolean isServer) { |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
144 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
145 |
initOutput(printToStderr); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
146 |
String opts[] = optionFlag.split(":"); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
147 |
String optStr = (opts.length > 1 && opts[1] != null) |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
148 |
? opts[1].trim() |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
149 |
: "all"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
150 |
switch (optStr) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
151 |
case "vm": |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
152 |
printVmSettings(initialHeapSize, maxHeapSize, |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
153 |
stackSize, isServer); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
154 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
155 |
case "properties": |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
156 |
printProperties(); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
157 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
158 |
case "locale": |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
159 |
printLocale(); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
160 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
161 |
default: |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
162 |
printVmSettings(initialHeapSize, maxHeapSize, stackSize, |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
163 |
isServer); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
164 |
printProperties(); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
165 |
printLocale(); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
166 |
break; |
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 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
169 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
170 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
171 |
* prints the main vm settings subopt/section |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
172 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
173 |
private static void printVmSettings( |
7810 | 174 |
long initialHeapSize, long maxHeapSize, |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
175 |
long stackSize, boolean isServer) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
176 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
177 |
ostream.println(VM_SETTINGS); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
178 |
if (stackSize != 0L) { |
7810 | 179 |
ostream.println(INDENT + "Stack Size: " + |
180 |
SizePrefix.scaleValue(stackSize)); |
|
181 |
} |
|
182 |
if (initialHeapSize != 0L) { |
|
183 |
ostream.println(INDENT + "Min. Heap Size: " + |
|
184 |
SizePrefix.scaleValue(initialHeapSize)); |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
185 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
186 |
if (maxHeapSize != 0L) { |
7810 | 187 |
ostream.println(INDENT + "Max. Heap Size: " + |
188 |
SizePrefix.scaleValue(maxHeapSize)); |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
189 |
} else { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
190 |
ostream.println(INDENT + "Max. Heap Size (Estimated): " |
7810 | 191 |
+ SizePrefix.scaleValue(Runtime.getRuntime().maxMemory())); |
7297
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 |
ostream.println(INDENT + "Ergonomics Machine Class: " |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
194 |
+ ((isServer) ? "server" : "client")); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
195 |
ostream.println(INDENT + "Using VM: " |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
196 |
+ System.getProperty("java.vm.name")); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
197 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
198 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
199 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
200 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
201 |
* prints the properties subopt/section |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
202 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
203 |
private static void printProperties() { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
204 |
Properties p = System.getProperties(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
205 |
ostream.println(PROP_SETTINGS); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
206 |
List<String> sortedPropertyKeys = new ArrayList<>(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
207 |
sortedPropertyKeys.addAll(p.stringPropertyNames()); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
208 |
Collections.sort(sortedPropertyKeys); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
209 |
for (String x : sortedPropertyKeys) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
210 |
printPropertyValue(x, p.getProperty(x)); |
7297
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 |
} |
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 |
private static boolean isPath(String key) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
216 |
return key.endsWith(".dirs") || key.endsWith(".path"); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
217 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
218 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
219 |
private static void printPropertyValue(String key, String value) { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
220 |
ostream.print(INDENT + key + " = "); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
221 |
if (key.equals("line.separator")) { |
7810 | 222 |
for (byte b : value.getBytes()) { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
223 |
switch (b) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
224 |
case 0xd: |
7810 | 225 |
ostream.print("\\r "); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
226 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
227 |
case 0xa: |
7810 | 228 |
ostream.print("\\n "); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
229 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
230 |
default: |
7810 | 231 |
// print any bizzare line separators in hex, but really |
232 |
// shouldn't happen. |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
233 |
ostream.printf("0x%02X", b & 0xff); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
234 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
235 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
236 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
237 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
238 |
return; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
239 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
240 |
if (!isPath(key)) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
241 |
ostream.println(value); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
242 |
return; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
243 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
244 |
String[] values = value.split(System.getProperty("path.separator")); |
7810 | 245 |
boolean first = true; |
246 |
for (String s : values) { |
|
247 |
if (first) { // first line treated specially |
|
248 |
ostream.println(s); |
|
249 |
first = false; |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
250 |
} else { // following lines prefix with indents |
7810 | 251 |
ostream.println(INDENT + INDENT + s); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
252 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
253 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
254 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
255 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
256 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
257 |
* prints the locale subopt/section |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
258 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
259 |
private static void printLocale() { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
260 |
Locale locale = Locale.getDefault(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
261 |
ostream.println(LOCALE_SETTINGS); |
7810 | 262 |
ostream.println(INDENT + "default locale = " + |
263 |
locale.getDisplayLanguage()); |
|
264 |
ostream.println(INDENT + "default display locale = " + |
|
265 |
Locale.getDefault(Category.DISPLAY).getDisplayName()); |
|
266 |
ostream.println(INDENT + "default format locale = " + |
|
267 |
Locale.getDefault(Category.FORMAT).getDisplayName()); |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
268 |
printLocales(); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
269 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
270 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
271 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
272 |
private static void printLocales() { |
7810 | 273 |
Locale[] tlocales = Locale.getAvailableLocales(); |
274 |
final int len = tlocales == null ? 0 : tlocales.length; |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
275 |
if (len < 1 ) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
276 |
return; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
277 |
} |
7810 | 278 |
// Locale does not implement Comparable so we convert it to String |
279 |
// and sort it for pretty printing. |
|
280 |
Set<String> sortedSet = new TreeSet<>(); |
|
281 |
for (Locale l : tlocales) { |
|
282 |
sortedSet.add(l.toString()); |
|
283 |
} |
|
284 |
||
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
285 |
ostream.print(INDENT + "available locales = "); |
7810 | 286 |
Iterator<String> iter = sortedSet.iterator(); |
287 |
final int last = len - 1; |
|
288 |
for (int i = 0 ; iter.hasNext() ; i++) { |
|
289 |
String s = iter.next(); |
|
290 |
ostream.print(s); |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
291 |
if (i != last) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
292 |
ostream.print(", "); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
293 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
294 |
// print columns of 8 |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
295 |
if ((i + 1) % 8 == 0) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
296 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
297 |
ostream.print(INDENT + INDENT); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
298 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
299 |
} |
7810 | 300 |
} |
301 |
||
302 |
private enum SizePrefix { |
|
303 |
||
304 |
KILO(1024, "K"), |
|
305 |
MEGA(1024 * 1024, "M"), |
|
306 |
GIGA(1024 * 1024 * 1024, "G"), |
|
307 |
TERA(1024L * 1024L * 1024L * 1024L, "T"); |
|
308 |
long size; |
|
309 |
String abbrev; |
|
310 |
||
311 |
SizePrefix(long size, String abbrev) { |
|
312 |
this.size = size; |
|
313 |
this.abbrev = abbrev; |
|
314 |
} |
|
315 |
||
316 |
private static String scale(long v, SizePrefix prefix) { |
|
317 |
return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size), |
|
318 |
2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev; |
|
319 |
} |
|
320 |
/* |
|
321 |
* scale the incoming values to a human readable form, represented as |
|
322 |
* K, M, G and T, see java.c parse_size for the scaled values and |
|
323 |
* suffixes. The lowest possible scaled value is Kilo. |
|
324 |
*/ |
|
325 |
static String scaleValue(long v) { |
|
326 |
if (v < MEGA.size) { |
|
327 |
return scale(v, KILO); |
|
328 |
} else if (v < GIGA.size) { |
|
329 |
return scale(v, MEGA); |
|
330 |
} else if (v < TERA.size) { |
|
331 |
return scale(v, GIGA); |
|
332 |
} else { |
|
333 |
return scale(v, TERA); |
|
334 |
} |
|
335 |
} |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
336 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
337 |
|
1323
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 |
* A private helper method to get a localized message and also |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
340 |
* apply any arguments that we might pass. |
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 |
private static String getLocalizedMessage(String key, Object... args) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
343 |
String msg = ResourceBundleHolder.RB.getString(key); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
344 |
return (args != null) ? MessageFormat.format(msg, args) : msg; |
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 |
* The java -help message is split into 3 parts, an invariant, followed |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
349 |
* by a set of platform dependent variant messages, finally an invariant |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
350 |
* set of lines. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
351 |
* This method initializes the help message for the first time, and also |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
352 |
* assembles the invariant header part of the message. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
353 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
354 |
static void initHelpMessage(String progname) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
355 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.header", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
356 |
(progname == null) ? "java" : progname )); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
357 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.datamodel", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
358 |
32)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
359 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.datamodel", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
360 |
64)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
361 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
362 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
363 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
364 |
* Appends the vm selection messages to the header, already created. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
365 |
* initHelpSystem must already be called. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
366 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
367 |
static void appendVmSelectMessage(String vm1, String vm2) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
368 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.vmselect", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
369 |
vm1, vm2)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
370 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
371 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
372 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
373 |
* Appends the vm synoym message to the header, already created. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
374 |
* initHelpSystem must be called before using this method. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
375 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
376 |
static void appendVmSynonymMessage(String vm1, String vm2) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
377 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.hotspot", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
378 |
vm1, vm2)); |
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 |
* Appends the vm Ergo message to the header, already created. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
383 |
* initHelpSystem must be called before using this method. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
384 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
385 |
static void appendVmErgoMessage(boolean isServerClass, String vm) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
386 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.ergo.message1", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
387 |
vm)); |
27957
24b4e6082f19
8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents:
25859
diff
changeset
|
388 |
outBuf = (isServerClass) ? outBuf.append(",\n") |
24b4e6082f19
8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents:
25859
diff
changeset
|
389 |
.append(getLocalizedMessage("java.launcher.ergo.message2")) |
24b4e6082f19
8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents:
25859
diff
changeset
|
390 |
.append("\n\n") : outBuf.append(".\n\n"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
391 |
} |
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 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
394 |
* Appends the last invariant part to the previously created messages, |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
395 |
* and finishes up the printing to the desired output stream. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
396 |
* initHelpSystem must be called before using this method. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
397 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
398 |
static void printHelpMessage(boolean printToStderr) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
399 |
initOutput(printToStderr); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
400 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.footer", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
401 |
File.pathSeparator)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
402 |
ostream.println(outBuf.toString()); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
403 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
404 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
405 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
406 |
* Prints the Xusage text to the desired output stream. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
407 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
408 |
static void printXUsageMessage(boolean printToStderr) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
409 |
initOutput(printToStderr); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
410 |
ostream.println(getLocalizedMessage("java.launcher.X.usage", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
411 |
File.pathSeparator)); |
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12047
diff
changeset
|
412 |
if (System.getProperty("os.name").contains("OS X")) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11125
diff
changeset
|
413 |
ostream.println(getLocalizedMessage("java.launcher.X.macosx.usage", |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11125
diff
changeset
|
414 |
File.pathSeparator)); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11125
diff
changeset
|
415 |
} |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
416 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
417 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
418 |
static void initOutput(boolean printToStderr) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
419 |
ostream = (printToStderr) ? System.err : System.out; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
420 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
421 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
422 |
static String getMainClassFromJar(String jarname) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
423 |
String mainValue = null; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
424 |
try (JarFile jarFile = new JarFile(jarname)) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
425 |
Manifest manifest = jarFile.getManifest(); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
426 |
if (manifest == null) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
427 |
abort(null, "java.launcher.jar.error2", jarname); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
428 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
429 |
Attributes mainAttrs = manifest.getMainAttributes(); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
430 |
if (mainAttrs == null) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
431 |
abort(null, "java.launcher.jar.error3", jarname); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
432 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
433 |
mainValue = mainAttrs.getValue(MAIN_CLASS); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
434 |
if (mainValue == null) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
435 |
abort(null, "java.launcher.jar.error3", jarname); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
436 |
} |
15682
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
15003
diff
changeset
|
437 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
15003
diff
changeset
|
438 |
/* |
15687
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
439 |
* 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
|
440 |
* 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
|
441 |
* 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
|
442 |
*/ |
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
443 |
if (mainAttrs.containsKey( |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
444 |
new Attributes.Name(JAVAFX_APPLICATION_MARKER))) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
445 |
FXHelper.setFXLaunchParameters(jarname, LM_JAR); |
15687
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
446 |
return FXHelper.class.getName(); |
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
447 |
} |
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
448 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
449 |
return mainValue.trim(); |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
450 |
} catch (IOException ioe) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
451 |
abort(ioe, "java.launcher.jar.error1", jarname); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
452 |
} |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
453 |
return null; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
454 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
455 |
|
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
456 |
// From src/share/bin/java.c: |
36511 | 457 |
// enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR, LM_MODULE } |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
458 |
|
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
459 |
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
|
460 |
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
|
461 |
private static final int LM_JAR = 2; |
36511 | 462 |
private static final int LM_MODULE = 3; |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
463 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
464 |
static void abort(Throwable t, String msgKey, Object... args) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
465 |
if (msgKey != null) { |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
466 |
ostream.println(getLocalizedMessage(msgKey, args)); |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
467 |
} |
13411
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
468 |
if (trace) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
469 |
if (t != null) { |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
470 |
t.printStackTrace(); |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
471 |
} else { |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
10126
diff
changeset
|
472 |
Thread.dumpStack(); |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
473 |
} |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
474 |
} |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
475 |
System.exit(1); |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
476 |
} |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
477 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
478 |
/** |
36511 | 479 |
* This method: |
480 |
* 1. Loads the main class from the module or class path |
|
481 |
* 2. Checks the public static void main method. |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
482 |
* |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
483 |
* @param printToStderr if set, all output will be routed to stderr |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
484 |
* @param mode LaunchMode as determined by the arguments passed on the |
36511 | 485 |
* command line |
486 |
* @param what the module name[/class], JAR file, or the main class |
|
487 |
* depending on the mode |
|
488 |
* |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
489 |
* @return the application's main class |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
490 |
*/ |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
491 |
public static Class<?> checkAndLoadMain(boolean printToStderr, |
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
492 |
int mode, |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
493 |
String what) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
494 |
initOutput(printToStderr); |
36511 | 495 |
|
496 |
Class<?> mainClass = (mode == LM_MODULE) ? loadModuleMainClass(what) |
|
497 |
: loadMainClass(mode, what); |
|
498 |
||
499 |
validateMainClass(mainClass); |
|
500 |
||
501 |
// record main class if not already set |
|
502 |
if (appClass == null) |
|
503 |
appClass = mainClass; |
|
504 |
||
505 |
return mainClass; |
|
506 |
} |
|
507 |
||
508 |
/** |
|
509 |
* Returns the main class for a module. The query is either a module name |
|
510 |
* or module-name/main-class. For the former then the module's main class |
|
511 |
* is obtained from the module descriptor (MainClass attribute). |
|
512 |
*/ |
|
513 |
private static Class<?> loadModuleMainClass(String what) { |
|
514 |
int i = what.indexOf('/'); |
|
515 |
String mainModule; |
|
516 |
String mainClass; |
|
517 |
if (i == -1) { |
|
518 |
mainModule = what; |
|
519 |
mainClass = null; |
|
520 |
} else { |
|
521 |
mainModule = what.substring(0, i); |
|
522 |
mainClass = what.substring(i+1); |
|
523 |
} |
|
524 |
||
525 |
// main module is in the boot layer |
|
526 |
Layer layer = Layer.boot(); |
|
527 |
Optional<Module> om = layer.findModule(mainModule); |
|
528 |
if (!om.isPresent()) { |
|
529 |
// should not happen |
|
530 |
throw new InternalError("Module " + mainModule + " not in boot Layer"); |
|
531 |
} |
|
532 |
Module m = om.get(); |
|
533 |
||
534 |
// get main class |
|
535 |
if (mainClass == null) { |
|
536 |
Optional<String> omc = m.getDescriptor().mainClass(); |
|
537 |
if (!omc.isPresent()) { |
|
538 |
abort(null, "java.launcher.module.error1", mainModule); |
|
539 |
} |
|
540 |
mainClass = omc.get(); |
|
541 |
} |
|
542 |
||
543 |
// load the class from the module |
|
544 |
Class<?> c = Class.forName(m, mainClass); |
|
545 |
if (c == null && System.getProperty("os.name", "").contains("OS X") |
|
546 |
&& Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) { |
|
547 |
||
548 |
String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC); |
|
549 |
c = Class.forName(m, cn); |
|
550 |
||
551 |
} |
|
552 |
if (c == null) { |
|
553 |
abort(null, "java.launcher.module.error2", mainClass, mainModule); |
|
554 |
} |
|
555 |
||
556 |
System.setProperty("jdk.module.main.class", c.getName()); |
|
557 |
return c; |
|
558 |
} |
|
559 |
||
560 |
/** |
|
561 |
* Loads the main class from the class path (LM_CLASS or LM_JAR). |
|
562 |
* If the main class extends FX Application then call on FXHelper to |
|
563 |
* determine the main class to launch. |
|
564 |
*/ |
|
565 |
private static Class<?> loadMainClass(int mode, String what) { |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
566 |
// get the class name |
36511 | 567 |
String cn; |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
568 |
switch (mode) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
569 |
case LM_CLASS: |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
570 |
cn = what; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
571 |
break; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
572 |
case LM_JAR: |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
573 |
cn = getMainClassFromJar(what); |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
574 |
break; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
575 |
default: |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
576 |
// should never happen |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
577 |
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
|
578 |
} |
36511 | 579 |
|
580 |
// load the main class |
|
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
581 |
cn = cn.replace('/', '.'); |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
582 |
Class<?> mainClass = null; |
36511 | 583 |
ClassLoader scl = ClassLoader.getSystemClassLoader(); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
584 |
try { |
39345
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
585 |
mainClass = Class.forName(cn, false, scl); |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
586 |
} catch (NoClassDefFoundError | ClassNotFoundException cnfe) { |
20179 | 587 |
if (System.getProperty("os.name", "").contains("OS X") |
36511 | 588 |
&& Normalizer.isNormalized(cn, Normalizer.Form.NFD)) { |
20179 | 589 |
try { |
39345
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
590 |
// On Mac OS X since all names with diacretic symbols are |
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
591 |
// given as decomposed it is possible that main class name |
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
592 |
// comes incorrectly from the command line and we have |
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
593 |
// to re-compose it |
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
594 |
String ncn = Normalizer.normalize(cn, Normalizer.Form.NFC); |
344e8211e184
8160698: java --dry-run should not cause main class be initialized
mchung
parents:
37788
diff
changeset
|
595 |
mainClass = Class.forName(ncn, false, scl); |
20179 | 596 |
} catch (NoClassDefFoundError | ClassNotFoundException cnfe1) { |
597 |
abort(cnfe, "java.launcher.cls.error1", cn); |
|
598 |
} |
|
599 |
} else { |
|
600 |
abort(cnfe, "java.launcher.cls.error1", cn); |
|
601 |
} |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
602 |
} |
36511 | 603 |
|
604 |
// record the main class |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
605 |
appClass = mainClass; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
606 |
|
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
607 |
/* |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
608 |
* 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
|
609 |
* 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
|
610 |
* validating the main class. |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
611 |
*/ |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
612 |
if (JAVAFX_FXHELPER_CLASS_NAME_SUFFIX.equals(mainClass.getName()) || |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
613 |
doesExtendFXApplication(mainClass)) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
614 |
// Will abort() if there are problems with FX runtime |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
615 |
FXHelper.setFXLaunchParameters(what, mode); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
616 |
return FXHelper.class; |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
617 |
} |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
618 |
return mainClass; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
619 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
620 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
621 |
/* |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
622 |
* 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
|
623 |
* checkAndLoadMain(). The "application class" is the class that is finally |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
624 |
* 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
|
625 |
* the correct application name, typically for UI purposes. |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
626 |
*/ |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
627 |
public static Class<?> getApplicationClass() { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
628 |
return appClass; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
629 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
630 |
|
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
631 |
/* |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
632 |
* Check if the given class is a JavaFX Application class. This is done |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
633 |
* in a way that does not cause the Application class to load or throw |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
634 |
* ClassNotFoundException if the JavaFX runtime is not available. |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
635 |
*/ |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
636 |
private static boolean doesExtendFXApplication(Class<?> mainClass) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
637 |
for (Class<?> sc = mainClass.getSuperclass(); sc != null; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
638 |
sc = sc.getSuperclass()) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
639 |
if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
640 |
return true; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
641 |
} |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
642 |
} |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
643 |
return false; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
644 |
} |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
645 |
|
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
646 |
// 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
|
647 |
static void validateMainClass(Class<?> mainClass) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
648 |
Method mainMethod; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
649 |
try { |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
650 |
mainMethod = mainClass.getMethod("main", String[].class); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
651 |
} catch (NoSuchMethodException nsme) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
652 |
// 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
|
653 |
abort(null, "java.launcher.cls.error4", mainClass.getName(), |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
654 |
JAVAFX_APPLICATION_CLASS_NAME); |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
655 |
return; // Avoid compiler issues |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
656 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
657 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
658 |
/* |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
659 |
* 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
|
660 |
* 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
|
661 |
* ensure that the method is static and returns a void. |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
662 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
663 |
int mod = mainMethod.getModifiers(); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
664 |
if (!Modifier.isStatic(mod)) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
665 |
abort(null, "java.launcher.cls.error2", "static", |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
666 |
mainMethod.getDeclaringClass().getName()); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
667 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
668 |
if (mainMethod.getReturnType() != java.lang.Void.TYPE) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
669 |
abort(null, "java.launcher.cls.error3", |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
670 |
mainMethod.getDeclaringClass().getName()); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
671 |
} |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
672 |
} |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
673 |
|
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
674 |
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
|
675 |
private static String encoding = null; |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
676 |
private static boolean isCharsetSupported = false; |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
677 |
|
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
678 |
/* |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
679 |
* 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
|
680 |
* 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
|
681 |
*/ |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
682 |
static String makePlatformString(boolean printToStderr, byte[] inArray) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
683 |
initOutput(printToStderr); |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
684 |
if (encoding == null) { |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
685 |
encoding = System.getProperty(encprop); |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
686 |
isCharsetSupported = Charset.isSupported(encoding); |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
687 |
} |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
688 |
try { |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
689 |
String out = isCharsetSupported |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
690 |
? new String(inArray, encoding) |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
691 |
: new String(inArray); |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
692 |
return out; |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
693 |
} catch (UnsupportedEncodingException uee) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
694 |
abort(uee, null); |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
695 |
} |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
696 |
return null; // keep the compiler happy |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
697 |
} |
13411
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
698 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
699 |
static String[] expandArgs(String[] argArray) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
700 |
List<StdArg> aList = new ArrayList<>(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
701 |
for (String x : argArray) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
702 |
aList.add(new StdArg(x)); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
703 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
704 |
return expandArgs(aList); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
705 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
706 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
707 |
static String[] expandArgs(List<StdArg> argList) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
708 |
ArrayList<String> out = new ArrayList<>(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
709 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
710 |
System.err.println("Incoming arguments:"); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
711 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
712 |
for (StdArg a : argList) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
713 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
714 |
System.err.println(a); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
715 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
716 |
if (a.needsExpansion) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
717 |
File x = new File(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
718 |
File parent = x.getParentFile(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
719 |
String glob = x.getName(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
720 |
if (parent == null) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
721 |
parent = new File("."); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
722 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
723 |
try (DirectoryStream<Path> dstream = |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
724 |
Files.newDirectoryStream(parent.toPath(), glob)) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
725 |
int entries = 0; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
726 |
for (Path p : dstream) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
727 |
out.add(p.normalize().toString()); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
728 |
entries++; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
729 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
730 |
if (entries == 0) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
731 |
out.add(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
732 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
733 |
} catch (Exception e) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
734 |
out.add(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
735 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
736 |
System.err.println("Warning: passing argument as-is " + a); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
737 |
System.err.print(e); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
738 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
739 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
740 |
} else { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
741 |
out.add(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
742 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
743 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
744 |
String[] oarray = new String[out.size()]; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
745 |
out.toArray(oarray); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
746 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
747 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
748 |
System.err.println("Expanded arguments:"); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
749 |
for (String x : oarray) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
750 |
System.err.println(x); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
751 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
752 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
753 |
return oarray; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
754 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
755 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
756 |
/* duplicate of the native StdArg struct */ |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
757 |
private static class StdArg { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
758 |
final String arg; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
759 |
final boolean needsExpansion; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
760 |
StdArg(String arg, boolean expand) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
761 |
this.arg = arg; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
762 |
this.needsExpansion = expand; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
763 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
764 |
// protocol: first char indicates whether expansion is required |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
765 |
// 'T' = true ; needs expansion |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
766 |
// 'F' = false; needs no expansion |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
767 |
StdArg(String in) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
768 |
this.arg = in.substring(1); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
769 |
needsExpansion = in.charAt(0) == 'T'; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
770 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
771 |
public String toString() { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
772 |
return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}'; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
773 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
774 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
775 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
776 |
static final class FXHelper { |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
777 |
|
36511 | 778 |
private static final String JAVAFX_GRAPHICS_MODULE_NAME = |
779 |
"javafx.graphics"; |
|
780 |
||
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
781 |
private static final String JAVAFX_LAUNCHER_CLASS_NAME = |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
782 |
"com.sun.javafx.application.LauncherImpl"; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
783 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
784 |
/* |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
785 |
* 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
|
786 |
* 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
|
787 |
* |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
788 |
* 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
|
789 |
* 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
|
790 |
* 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
|
791 |
* 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
|
792 |
* 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
|
793 |
*/ |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
794 |
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
|
795 |
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
|
796 |
|
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
797 |
/* |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
798 |
* FX application launcher and launch method, so we can launch |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
799 |
* applications with no main method. |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
800 |
*/ |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
801 |
private static String fxLaunchName = null; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
802 |
private static String fxLaunchMode = null; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
803 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
804 |
private static Class<?> fxLauncherClass = null; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
805 |
private static Method fxLauncherMethod = null; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
806 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
807 |
/* |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
808 |
* 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
|
809 |
* 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
|
810 |
* 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
|
811 |
*/ |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
812 |
private static void setFXLaunchParameters(String what, int mode) { |
36511 | 813 |
|
814 |
// find the module with the FX launcher |
|
815 |
Optional<Module> om = Layer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME); |
|
816 |
if (!om.isPresent()) { |
|
817 |
abort(null, "java.launcher.cls.error5"); |
|
818 |
} |
|
819 |
||
820 |
// load the FX launcher class |
|
821 |
fxLauncherClass = Class.forName(om.get(), JAVAFX_LAUNCHER_CLASS_NAME); |
|
822 |
if (fxLauncherClass == null) { |
|
823 |
abort(null, "java.launcher.cls.error5"); |
|
824 |
} |
|
825 |
||
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
826 |
try { |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
827 |
/* |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
828 |
* signature must be: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
829 |
* public static void launchApplication(String launchName, |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
830 |
* String launchMode, String[] args); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
831 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
832 |
fxLauncherMethod = fxLauncherClass.getMethod("launchApplication", |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
833 |
String.class, String.class, String[].class); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
834 |
|
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
835 |
// 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
|
836 |
int mod = fxLauncherMethod.getModifiers(); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
837 |
if (!Modifier.isStatic(mod)) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
838 |
abort(null, "java.launcher.javafx.error1"); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
839 |
} |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
840 |
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
|
841 |
abort(null, "java.launcher.javafx.error1"); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
842 |
} |
36511 | 843 |
} catch (NoSuchMethodException ex) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
844 |
abort(ex, "java.launcher.cls.error5", ex); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
845 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
846 |
|
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
847 |
fxLaunchName = what; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
848 |
switch (mode) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
849 |
case LM_CLASS: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
850 |
fxLaunchMode = JAVAFX_LAUNCH_MODE_CLASS; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
851 |
break; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
852 |
case LM_JAR: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
853 |
fxLaunchMode = JAVAFX_LAUNCH_MODE_JAR; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
854 |
break; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
855 |
default: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
856 |
// should not have gotten this far... |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
857 |
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
|
858 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
859 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
860 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
861 |
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
|
862 |
if (fxLauncherMethod == null |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
863 |
|| fxLaunchMode == null |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
864 |
|| fxLaunchName == null) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
865 |
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
|
866 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
867 |
// launch appClass via fxLauncherMethod |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
868 |
fxLauncherMethod.invoke(null, |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
869 |
new Object[] {fxLaunchName, fxLaunchMode, args}); |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
870 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
871 |
} |
36511 | 872 |
|
873 |
private static void formatCommaList(PrintStream out, |
|
874 |
String prefix, |
|
875 |
Collection<?> list) |
|
876 |
{ |
|
877 |
if (list.isEmpty()) |
|
878 |
return; |
|
879 |
out.format("%s", prefix); |
|
880 |
boolean first = true; |
|
881 |
for (Object ob : list) { |
|
882 |
if (first) { |
|
883 |
out.format(" %s", ob); |
|
884 |
first = false; |
|
885 |
} else { |
|
886 |
out.format(", %s", ob); |
|
887 |
} |
|
888 |
} |
|
889 |
out.format("%n"); |
|
890 |
} |
|
891 |
||
892 |
/** |
|
893 |
* Called by the launcher to list the observable modules. |
|
894 |
* If called without any sub-options then the output is a simple list of |
|
895 |
* the modules. If called with sub-options then the sub-options are the |
|
896 |
* names of the modules to list (-listmods:java.base,java.desktop for |
|
897 |
* example). |
|
898 |
*/ |
|
899 |
static void listModules(boolean printToStderr, String optionFlag) |
|
900 |
throws IOException, ClassNotFoundException |
|
901 |
{ |
|
902 |
initOutput(printToStderr); |
|
903 |
||
904 |
ModuleFinder finder = jdk.internal.module.ModuleBootstrap.finder(); |
|
905 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39345
diff
changeset
|
906 |
int colon = optionFlag.indexOf('='); |
36511 | 907 |
if (colon == -1) { |
908 |
finder.findAll().stream() |
|
909 |
.sorted(Comparator.comparing(ModuleReference::descriptor)) |
|
910 |
.forEach(md -> { |
|
911 |
ostream.println(midAndLocation(md.descriptor(), |
|
912 |
md.location())); |
|
913 |
}); |
|
914 |
} else { |
|
915 |
String[] names = optionFlag.substring(colon+1).split(","); |
|
916 |
for (String name: names) { |
|
917 |
ModuleReference mref = finder.find(name).orElse(null); |
|
918 |
if (mref == null) { |
|
919 |
// not found |
|
920 |
continue; |
|
921 |
} |
|
922 |
||
923 |
ModuleDescriptor md = mref.descriptor(); |
|
924 |
ostream.println(midAndLocation(md, mref.location())); |
|
925 |
||
926 |
for (Requires d : md.requires()) { |
|
927 |
ostream.format(" requires %s%n", d); |
|
928 |
} |
|
929 |
for (String s : md.uses()) { |
|
930 |
ostream.format(" uses %s%n", s); |
|
931 |
} |
|
932 |
||
933 |
// sorted exports |
|
934 |
Set<Exports> exports = new TreeSet<>(Comparator.comparing(Exports::source)); |
|
935 |
exports.addAll(md.exports()); |
|
936 |
for (Exports e : exports) { |
|
937 |
ostream.format(" exports %s", e.source()); |
|
938 |
if (e.isQualified()) { |
|
939 |
formatCommaList(ostream, " to", e.targets()); |
|
940 |
} else { |
|
941 |
ostream.println(); |
|
942 |
} |
|
943 |
} |
|
944 |
||
945 |
// concealed packages |
|
946 |
new TreeSet<>(md.conceals()) |
|
947 |
.forEach(p -> ostream.format(" conceals %s%n", p)); |
|
948 |
||
949 |
Map<String, Provides> provides = md.provides(); |
|
950 |
for (Provides ps : provides.values()) { |
|
951 |
for (String impl : ps.providers()) |
|
952 |
ostream.format(" provides %s with %s%n", ps.service(), impl); |
|
953 |
} |
|
954 |
} |
|
955 |
} |
|
956 |
} |
|
957 |
||
958 |
static String midAndLocation(ModuleDescriptor md, Optional<URI> location ) { |
|
959 |
URI loc = location.orElse(null); |
|
960 |
if (loc == null || loc.getScheme().equalsIgnoreCase("jrt")) |
|
961 |
return md.toNameAndVersion(); |
|
962 |
else |
|
963 |
return md.toNameAndVersion() + " (" + loc + ")"; |
|
964 |
} |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
965 |
} |