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