author | alanb |
Thu, 21 Jun 2018 18:56:35 +0100 | |
changeset 50700 | 97e9c4f58986 |
parent 50546 | 52b866a1a63a |
child 55233 | 6c2d69a41ff9 |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
1 |
/* |
50453 | 2 |
* Copyright (c) 2007, 2018, 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; |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
46 |
import java.lang.module.Configuration; |
36511 | 47 |
import java.lang.module.ModuleDescriptor; |
48 |
import java.lang.module.ModuleDescriptor.Requires; |
|
49 |
import java.lang.module.ModuleDescriptor.Exports; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
50 |
import java.lang.module.ModuleDescriptor.Opens; |
36511 | 51 |
import java.lang.module.ModuleDescriptor.Provides; |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
52 |
import java.lang.module.ModuleFinder; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
53 |
import java.lang.module.ModuleReference; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
54 |
import java.lang.module.ResolvedModule; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
55 |
import java.lang.reflect.InvocationTargetException; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
56 |
import java.lang.reflect.Method; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
57 |
import java.lang.reflect.Modifier; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
58 |
import java.math.BigDecimal; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
59 |
import java.math.RoundingMode; |
36511 | 60 |
import java.net.URI; |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
61 |
import java.nio.charset.Charset; |
13411
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
62 |
import java.nio.file.DirectoryStream; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
63 |
import java.nio.file.Files; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
64 |
import java.nio.file.Path; |
20179 | 65 |
import java.text.Normalizer; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
66 |
import java.text.MessageFormat; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
67 |
import java.util.ArrayList; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
68 |
import java.util.Collections; |
36511 | 69 |
import java.util.Comparator; |
7810 | 70 |
import java.util.Iterator; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
71 |
import java.util.List; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
72 |
import java.util.Locale; |
7810 | 73 |
import java.util.Locale.Category; |
36511 | 74 |
import java.util.Optional; |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
75 |
import java.util.Properties; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
76 |
import java.util.ResourceBundle; |
7810 | 77 |
import java.util.Set; |
78 |
import java.util.TreeSet; |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
79 |
import java.util.jar.Attributes; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
80 |
import java.util.jar.JarFile; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
81 |
import java.util.jar.Manifest; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
82 |
import java.util.stream.Collectors; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
83 |
import java.util.stream.Stream; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
84 |
|
34882 | 85 |
import jdk.internal.misc.VM; |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
86 |
import jdk.internal.module.ModuleBootstrap; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
87 |
import jdk.internal.module.Modules; |
50545 | 88 |
import jdk.internal.platform.Container; |
89 |
import jdk.internal.platform.Metrics; |
|
90 |
||
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
91 |
|
37788
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
92 |
public final class LauncherHelper { |
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
93 |
|
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
94 |
// No instantiation |
81ce381a91f6
8155939: sun.launcher.LauncherHelper INSTANCE is unused
redestad
parents:
36511
diff
changeset
|
95 |
private LauncherHelper() {} |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
96 |
|
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
97 |
// used to identify JavaFX applications |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
98 |
private static final String JAVAFX_APPLICATION_MARKER = |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
99 |
"JavaFX-Application-Class"; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
100 |
private static final String JAVAFX_APPLICATION_CLASS_NAME = |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
101 |
"javafx.application.Application"; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
102 |
private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX = |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
103 |
"sun.launcher.LauncherHelper$FXHelper"; |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
104 |
private static final String LAUNCHER_AGENT_CLASS = "Launcher-Agent-Class"; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
105 |
private static final String MAIN_CLASS = "Main-Class"; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
106 |
private static final String ADD_EXPORTS = "Add-Exports"; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
107 |
private static final String ADD_OPENS = "Add-Opens"; |
15682
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
15003
diff
changeset
|
108 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
109 |
private static StringBuilder outBuf = new StringBuilder(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
110 |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
111 |
private static final String INDENT = " "; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
112 |
private static final String VM_SETTINGS = "VM settings:"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
113 |
private static final String PROP_SETTINGS = "Property settings:"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
114 |
private static final String LOCALE_SETTINGS = "Locale settings:"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
115 |
|
34882 | 116 |
// sync with java.c and jdk.internal.misc.VM |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
117 |
private static final String diagprop = "sun.java.launcher.diag"; |
34882 | 118 |
static final boolean trace = VM.getSavedProperty(diagprop) != null; |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
119 |
|
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
120 |
private static final String defaultBundleName = |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
121 |
"sun.launcher.resources.launcher"; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
122 |
private static class ResourceBundleHolder { |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
123 |
private static final ResourceBundle RB = |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
124 |
ResourceBundle.getBundle(defaultBundleName); |
2168
de3c5a0416de
6801467: Defer get the launcher resource bundle until it's needed
mchung
parents:
1343
diff
changeset
|
125 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
126 |
private static PrintStream ostream; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
127 |
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
|
128 |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
129 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
130 |
* 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
|
131 |
* by default -XshowSettings is equivalent to -XshowSettings:all, |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
132 |
* 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
|
133 |
* values vm, properties and locale. |
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 |
* printToStderr: choose between stdout and stderr |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
136 |
* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
137 |
* 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
|
138 |
* possible values are vm, properties, locale. |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
139 |
* |
7810 | 140 |
* initialHeapSize: in bytes, as set by the launcher, a zero-value indicates |
141 |
* this code should determine this value, using a suitable method or |
|
142 |
* the line could be omitted. |
|
143 |
* |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
144 |
* 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
|
145 |
* 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
|
146 |
* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
147 |
* stackSize: in bytes, as set by the launcher, a zero-value indicates |
7810 | 148 |
* this code determine this value, using a suitable method or omit the |
149 |
* line entirely. |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
150 |
*/ |
50545 | 151 |
@SuppressWarnings("fallthrough") |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
152 |
static void showSettings(boolean printToStderr, String optionFlag, |
41966 | 153 |
long initialHeapSize, long maxHeapSize, long stackSize) { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
154 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
155 |
initOutput(printToStderr); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
156 |
String opts[] = optionFlag.split(":"); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
157 |
String optStr = (opts.length > 1 && opts[1] != null) |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
158 |
? opts[1].trim() |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
159 |
: "all"; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
160 |
switch (optStr) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
161 |
case "vm": |
41966 | 162 |
printVmSettings(initialHeapSize, maxHeapSize, stackSize); |
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 "properties": |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
165 |
printProperties(); |
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 |
case "locale": |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
168 |
printLocale(); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
169 |
break; |
50545 | 170 |
case "system": |
171 |
if (System.getProperty("os.name").contains("Linux")) { |
|
172 |
printSystemMetrics(); |
|
173 |
break; |
|
174 |
} |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
175 |
default: |
41966 | 176 |
printVmSettings(initialHeapSize, maxHeapSize, stackSize); |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
177 |
printProperties(); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
178 |
printLocale(); |
50545 | 179 |
if (System.getProperty("os.name").contains("Linux")) { |
180 |
printSystemMetrics(); |
|
181 |
} |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
182 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
183 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
184 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
185 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
186 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
187 |
* prints the main vm settings subopt/section |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
188 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
189 |
private static void printVmSettings( |
7810 | 190 |
long initialHeapSize, long maxHeapSize, |
41966 | 191 |
long stackSize) { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
192 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
193 |
ostream.println(VM_SETTINGS); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
194 |
if (stackSize != 0L) { |
7810 | 195 |
ostream.println(INDENT + "Stack Size: " + |
196 |
SizePrefix.scaleValue(stackSize)); |
|
197 |
} |
|
198 |
if (initialHeapSize != 0L) { |
|
199 |
ostream.println(INDENT + "Min. Heap Size: " + |
|
200 |
SizePrefix.scaleValue(initialHeapSize)); |
|
7297
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 |
if (maxHeapSize != 0L) { |
7810 | 203 |
ostream.println(INDENT + "Max. Heap Size: " + |
204 |
SizePrefix.scaleValue(maxHeapSize)); |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
205 |
} else { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
206 |
ostream.println(INDENT + "Max. Heap Size (Estimated): " |
7810 | 207 |
+ SizePrefix.scaleValue(Runtime.getRuntime().maxMemory())); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
208 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
209 |
ostream.println(INDENT + "Using VM: " |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
210 |
+ System.getProperty("java.vm.name")); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
211 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
212 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
213 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
214 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
215 |
* prints the properties subopt/section |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
216 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
217 |
private static void printProperties() { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
218 |
Properties p = System.getProperties(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
219 |
ostream.println(PROP_SETTINGS); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
220 |
List<String> sortedPropertyKeys = new ArrayList<>(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
221 |
sortedPropertyKeys.addAll(p.stringPropertyNames()); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
222 |
Collections.sort(sortedPropertyKeys); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
223 |
for (String x : sortedPropertyKeys) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
224 |
printPropertyValue(x, p.getProperty(x)); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
225 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
226 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
227 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
228 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
229 |
private static boolean isPath(String key) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
230 |
return key.endsWith(".dirs") || key.endsWith(".path"); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
231 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
232 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
233 |
private static void printPropertyValue(String key, String value) { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
234 |
ostream.print(INDENT + key + " = "); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
235 |
if (key.equals("line.separator")) { |
7810 | 236 |
for (byte b : value.getBytes()) { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
237 |
switch (b) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
238 |
case 0xd: |
7810 | 239 |
ostream.print("\\r "); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
240 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
241 |
case 0xa: |
7810 | 242 |
ostream.print("\\n "); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
243 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
244 |
default: |
7810 | 245 |
// print any bizzare line separators in hex, but really |
246 |
// shouldn't happen. |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
247 |
ostream.printf("0x%02X", b & 0xff); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
248 |
break; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
249 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
250 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
251 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
252 |
return; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
253 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
254 |
if (!isPath(key)) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
255 |
ostream.println(value); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
256 |
return; |
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 |
String[] values = value.split(System.getProperty("path.separator")); |
7810 | 259 |
boolean first = true; |
260 |
for (String s : values) { |
|
261 |
if (first) { // first line treated specially |
|
262 |
ostream.println(s); |
|
263 |
first = false; |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
264 |
} else { // following lines prefix with indents |
7810 | 265 |
ostream.println(INDENT + INDENT + s); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
266 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
267 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
268 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
269 |
|
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
270 |
/* |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
271 |
* prints the locale subopt/section |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
272 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
273 |
private static void printLocale() { |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
274 |
Locale locale = Locale.getDefault(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
275 |
ostream.println(LOCALE_SETTINGS); |
7810 | 276 |
ostream.println(INDENT + "default locale = " + |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
277 |
locale.getDisplayName()); |
7810 | 278 |
ostream.println(INDENT + "default display locale = " + |
279 |
Locale.getDefault(Category.DISPLAY).getDisplayName()); |
|
280 |
ostream.println(INDENT + "default format locale = " + |
|
281 |
Locale.getDefault(Category.FORMAT).getDisplayName()); |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
282 |
printLocales(); |
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
283 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
284 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
285 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
286 |
private static void printLocales() { |
7810 | 287 |
Locale[] tlocales = Locale.getAvailableLocales(); |
288 |
final int len = tlocales == null ? 0 : tlocales.length; |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
289 |
if (len < 1 ) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
290 |
return; |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
291 |
} |
7810 | 292 |
// Locale does not implement Comparable so we convert it to String |
293 |
// and sort it for pretty printing. |
|
294 |
Set<String> sortedSet = new TreeSet<>(); |
|
295 |
for (Locale l : tlocales) { |
|
296 |
sortedSet.add(l.toString()); |
|
297 |
} |
|
298 |
||
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
299 |
ostream.print(INDENT + "available locales = "); |
7810 | 300 |
Iterator<String> iter = sortedSet.iterator(); |
301 |
final int last = len - 1; |
|
302 |
for (int i = 0 ; iter.hasNext() ; i++) { |
|
303 |
String s = iter.next(); |
|
304 |
ostream.print(s); |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
305 |
if (i != last) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
306 |
ostream.print(", "); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
307 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
308 |
// print columns of 8 |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
309 |
if ((i + 1) % 8 == 0) { |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
310 |
ostream.println(); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
311 |
ostream.print(INDENT + INDENT); |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
312 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
313 |
} |
7810 | 314 |
} |
315 |
||
50545 | 316 |
public static void printSystemMetrics() { |
317 |
Metrics c = Container.metrics(); |
|
318 |
||
319 |
ostream.println("Operating System Metrics:"); |
|
320 |
||
321 |
if (c == null) { |
|
322 |
ostream.println(INDENT + "No metrics available for this platform"); |
|
323 |
return; |
|
324 |
} |
|
325 |
||
326 |
ostream.println(INDENT + "Provider: " + c.getProvider()); |
|
327 |
ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount()); |
|
328 |
ostream.println(INDENT + "CPU Period: " + c.getCpuPeriod() + |
|
329 |
(c.getCpuPeriod() == -1 ? "" : "us")); |
|
330 |
ostream.println(INDENT + "CPU Quota: " + c.getCpuQuota() + |
|
331 |
(c.getCpuQuota() == -1 ? "" : "us")); |
|
332 |
ostream.println(INDENT + "CPU Shares: " + c.getCpuShares()); |
|
333 |
||
334 |
int cpus[] = c.getCpuSetCpus(); |
|
335 |
ostream.println(INDENT + "List of Processors, " |
|
336 |
+ cpus.length + " total: "); |
|
337 |
||
338 |
ostream.print(INDENT); |
|
339 |
for (int i = 0; i < cpus.length; i++) { |
|
340 |
ostream.print(cpus[i] + " "); |
|
341 |
} |
|
342 |
if (cpus.length > 0) { |
|
343 |
ostream.println(""); |
|
344 |
} |
|
345 |
||
346 |
cpus = c.getEffectiveCpuSetCpus(); |
|
347 |
ostream.println(INDENT + "List of Effective Processors, " |
|
348 |
+ cpus.length + " total: "); |
|
349 |
||
350 |
ostream.print(INDENT); |
|
351 |
for (int i = 0; i < cpus.length; i++) { |
|
352 |
ostream.print(cpus[i] + " "); |
|
353 |
} |
|
354 |
if (cpus.length > 0) { |
|
355 |
ostream.println(""); |
|
356 |
} |
|
357 |
||
358 |
int mems[] = c.getCpuSetMems(); |
|
359 |
ostream.println(INDENT + "List of Memory Nodes, " |
|
360 |
+ mems.length + " total: "); |
|
361 |
||
362 |
ostream.print(INDENT); |
|
363 |
for (int i = 0; i < mems.length; i++) { |
|
364 |
ostream.print(mems[i] + " "); |
|
365 |
} |
|
366 |
if (mems.length > 0) { |
|
367 |
ostream.println(""); |
|
368 |
} |
|
369 |
||
370 |
mems = c.getEffectiveCpuSetMems(); |
|
371 |
ostream.println(INDENT + "List of Available Memory Nodes, " |
|
372 |
+ mems.length + " total: "); |
|
373 |
||
374 |
ostream.print(INDENT); |
|
375 |
for (int i = 0; i < mems.length; i++) { |
|
376 |
ostream.print(mems[i] + " "); |
|
377 |
} |
|
378 |
if (mems.length > 0) { |
|
379 |
ostream.println(""); |
|
380 |
} |
|
381 |
||
382 |
ostream.println(INDENT + "CPUSet Memory Pressure Enabled: " |
|
383 |
+ c.isCpuSetMemoryPressureEnabled()); |
|
384 |
||
385 |
long limit = c.getMemoryLimit(); |
|
386 |
ostream.println(INDENT + "Memory Limit: " + |
|
387 |
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
388 |
||
389 |
limit = c.getMemorySoftLimit(); |
|
390 |
ostream.println(INDENT + "Memory Soft Limit: " + |
|
391 |
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
392 |
||
393 |
limit = c.getMemoryAndSwapLimit(); |
|
394 |
ostream.println(INDENT + "Memory & Swap Limit: " + |
|
395 |
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
396 |
||
397 |
limit = c.getKernelMemoryLimit(); |
|
398 |
ostream.println(INDENT + "Kernel Memory Limit: " + |
|
399 |
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
400 |
||
401 |
limit = c.getTcpMemoryLimit(); |
|
402 |
ostream.println(INDENT + "TCP Memory Limit: " + |
|
403 |
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
404 |
||
405 |
ostream.println(INDENT + "Out Of Memory Killer Enabled: " |
|
406 |
+ c.isMemoryOOMKillEnabled()); |
|
407 |
||
408 |
ostream.println(""); |
|
409 |
} |
|
410 |
||
7810 | 411 |
private enum SizePrefix { |
412 |
||
413 |
KILO(1024, "K"), |
|
414 |
MEGA(1024 * 1024, "M"), |
|
415 |
GIGA(1024 * 1024 * 1024, "G"), |
|
416 |
TERA(1024L * 1024L * 1024L * 1024L, "T"); |
|
417 |
long size; |
|
418 |
String abbrev; |
|
419 |
||
420 |
SizePrefix(long size, String abbrev) { |
|
421 |
this.size = size; |
|
422 |
this.abbrev = abbrev; |
|
423 |
} |
|
424 |
||
425 |
private static String scale(long v, SizePrefix prefix) { |
|
426 |
return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size), |
|
427 |
2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev; |
|
428 |
} |
|
429 |
/* |
|
430 |
* scale the incoming values to a human readable form, represented as |
|
431 |
* K, M, G and T, see java.c parse_size for the scaled values and |
|
432 |
* suffixes. The lowest possible scaled value is Kilo. |
|
433 |
*/ |
|
434 |
static String scaleValue(long v) { |
|
435 |
if (v < MEGA.size) { |
|
436 |
return scale(v, KILO); |
|
437 |
} else if (v < GIGA.size) { |
|
438 |
return scale(v, MEGA); |
|
439 |
} else if (v < TERA.size) { |
|
440 |
return scale(v, GIGA); |
|
441 |
} else { |
|
442 |
return scale(v, TERA); |
|
443 |
} |
|
444 |
} |
|
7297
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
445 |
} |
906c58a8b849
6452854: Provide a flag to print the java configuration
ksrini
parents:
5982
diff
changeset
|
446 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
447 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
448 |
* A private helper method to get a localized message and also |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
449 |
* apply any arguments that we might pass. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
450 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
451 |
private static String getLocalizedMessage(String key, Object... args) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
452 |
String msg = ResourceBundleHolder.RB.getString(key); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
453 |
return (args != null) ? MessageFormat.format(msg, args) : msg; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
454 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
455 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
456 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
457 |
* The java -help message is split into 3 parts, an invariant, followed |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
458 |
* by a set of platform dependent variant messages, finally an invariant |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
459 |
* set of lines. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
460 |
* This method initializes the help message for the first time, and also |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
461 |
* assembles the invariant header part of the message. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
462 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
463 |
static void initHelpMessage(String progname) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
464 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.header", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
465 |
(progname == null) ? "java" : progname )); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
466 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
467 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
468 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
469 |
* Appends the vm selection messages to the header, already created. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
470 |
* initHelpSystem must already be called. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
471 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
472 |
static void appendVmSelectMessage(String vm1, String vm2) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
473 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.vmselect", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
474 |
vm1, vm2)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
475 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
476 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
477 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
478 |
* Appends the vm synoym message to the header, already created. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
479 |
* initHelpSystem must be called before using this method. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
480 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
481 |
static void appendVmSynonymMessage(String vm1, String vm2) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
482 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.hotspot", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
483 |
vm1, vm2)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
484 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
485 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
486 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
487 |
* Appends the last invariant part to the previously created messages, |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
488 |
* and finishes up the printing to the desired output stream. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
489 |
* initHelpSystem must be called before using this method. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
490 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
491 |
static void printHelpMessage(boolean printToStderr) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
492 |
initOutput(printToStderr); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
493 |
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.footer", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
494 |
File.pathSeparator)); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
495 |
ostream.println(outBuf.toString()); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
496 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
497 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
498 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
499 |
* Prints the Xusage text to the desired output stream. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
500 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
501 |
static void printXUsageMessage(boolean printToStderr) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
502 |
initOutput(printToStderr); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
503 |
ostream.println(getLocalizedMessage("java.launcher.X.usage", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
504 |
File.pathSeparator)); |
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12047
diff
changeset
|
505 |
if (System.getProperty("os.name").contains("OS X")) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11125
diff
changeset
|
506 |
ostream.println(getLocalizedMessage("java.launcher.X.macosx.usage", |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11125
diff
changeset
|
507 |
File.pathSeparator)); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11125
diff
changeset
|
508 |
} |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
509 |
} |
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 |
static void initOutput(boolean printToStderr) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
512 |
ostream = (printToStderr) ? System.err : System.out; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
513 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
514 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
515 |
static void initOutput(PrintStream ps) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
516 |
ostream = ps; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
517 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
518 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
519 |
static String getMainClassFromJar(String jarname) { |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
520 |
String mainValue; |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
521 |
try (JarFile jarFile = new JarFile(jarname)) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
522 |
Manifest manifest = jarFile.getManifest(); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
523 |
if (manifest == null) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
524 |
abort(null, "java.launcher.jar.error2", jarname); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
525 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
526 |
Attributes mainAttrs = manifest.getMainAttributes(); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
527 |
if (mainAttrs == null) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
528 |
abort(null, "java.launcher.jar.error3", jarname); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
529 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
530 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
531 |
// Main-Class |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
532 |
mainValue = mainAttrs.getValue(MAIN_CLASS); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
533 |
if (mainValue == null) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
534 |
abort(null, "java.launcher.jar.error3", jarname); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
535 |
} |
15682
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
15003
diff
changeset
|
536 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
537 |
// Launcher-Agent-Class (only check for this when Main-Class present) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
538 |
String agentClass = mainAttrs.getValue(LAUNCHER_AGENT_CLASS); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
539 |
if (agentClass != null) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
540 |
ModuleLayer.boot().findModule("java.instrument").ifPresent(m -> { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
541 |
try { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
542 |
String cn = "sun.instrument.InstrumentationImpl"; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
543 |
Class<?> clazz = Class.forName(cn, false, null); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
544 |
Method loadAgent = clazz.getMethod("loadAgent", String.class); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
545 |
loadAgent.invoke(null, jarname); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
546 |
} catch (Throwable e) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
547 |
if (e instanceof InvocationTargetException) e = e.getCause(); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
548 |
abort(e, "java.launcher.jar.error4", jarname); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
549 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
550 |
}); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
551 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
552 |
|
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
553 |
// Add-Exports and Add-Opens |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
554 |
String exports = mainAttrs.getValue(ADD_EXPORTS); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
555 |
if (exports != null) { |
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
556 |
addExportsOrOpens(exports, false); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
557 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
558 |
String opens = mainAttrs.getValue(ADD_OPENS); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
559 |
if (opens != null) { |
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
560 |
addExportsOrOpens(opens, true); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
561 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
562 |
|
15682
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
15003
diff
changeset
|
563 |
/* |
15687
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
564 |
* 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
|
565 |
* 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
|
566 |
* 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
|
567 |
*/ |
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
568 |
if (mainAttrs.containsKey( |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
569 |
new Attributes.Name(JAVAFX_APPLICATION_MARKER))) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
570 |
FXHelper.setFXLaunchParameters(jarname, LM_JAR); |
15687
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
571 |
return FXHelper.class.getName(); |
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
572 |
} |
9f473a0b9e86
8006667: Merge issue: Profile attribute need to be examined before custom attributes
dholmes
parents:
15682
diff
changeset
|
573 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
574 |
return mainValue.trim(); |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
575 |
} catch (IOException ioe) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
576 |
abort(ioe, "java.launcher.jar.error1", jarname); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
577 |
} |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
578 |
return null; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
579 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
580 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
581 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
582 |
* Process the Add-Exports or Add-Opens value. The value is |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
583 |
* {@code <module>/<package> ( <module>/<package>)*}. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
584 |
*/ |
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
585 |
static void addExportsOrOpens(String value, boolean open) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
586 |
for (String moduleAndPackage : value.split(" ")) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
587 |
String[] s = moduleAndPackage.trim().split("/"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
588 |
if (s.length == 2) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
589 |
String mn = s[0]; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
590 |
String pn = s[1]; |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
591 |
ModuleLayer.boot() |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
592 |
.findModule(mn) |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
593 |
.filter(m -> m.getDescriptor().packages().contains(pn)) |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
594 |
.ifPresent(m -> { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
595 |
if (open) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
596 |
Modules.addOpensToAllUnnamed(m, pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
597 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
598 |
Modules.addExportsToAllUnnamed(m, pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
599 |
} |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
600 |
}); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
601 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
602 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
603 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
604 |
|
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
605 |
// From src/share/bin/java.c: |
50453 | 606 |
// enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR, LM_MODULE, LM_SOURCE } |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
607 |
|
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
608 |
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
|
609 |
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
|
610 |
private static final int LM_JAR = 2; |
36511 | 611 |
private static final int LM_MODULE = 3; |
50453 | 612 |
private static final int LM_SOURCE = 4; |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
613 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
614 |
static void abort(Throwable t, String msgKey, Object... args) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
615 |
if (msgKey != null) { |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
616 |
ostream.println(getLocalizedMessage(msgKey, args)); |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
617 |
} |
13411
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
618 |
if (trace) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
619 |
if (t != null) { |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
620 |
t.printStackTrace(); |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
621 |
} else { |
11125
99b115114fa3
7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents:
10126
diff
changeset
|
622 |
Thread.dumpStack(); |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
623 |
} |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
624 |
} |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
625 |
System.exit(1); |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
626 |
} |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
627 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
628 |
/** |
36511 | 629 |
* This method: |
630 |
* 1. Loads the main class from the module or class path |
|
631 |
* 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
|
632 |
* 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
|
633 |
* perform the launch. |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
634 |
* |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
635 |
* @param printToStderr if set, all output will be routed to stderr |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
636 |
* @param mode LaunchMode as determined by the arguments passed on the |
36511 | 637 |
* command line |
638 |
* @param what the module name[/class], JAR file, or the main class |
|
639 |
* depending on the mode |
|
640 |
* |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
641 |
* @return the application's main class |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
642 |
*/ |
50453 | 643 |
@SuppressWarnings("fallthrough") |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
644 |
public static Class<?> checkAndLoadMain(boolean printToStderr, |
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
645 |
int mode, |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
646 |
String what) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
647 |
initOutput(printToStderr); |
36511 | 648 |
|
50453 | 649 |
Class<?> mainClass = null; |
650 |
switch (mode) { |
|
651 |
case LM_MODULE: case LM_SOURCE: |
|
652 |
mainClass = loadModuleMainClass(what); |
|
653 |
break; |
|
654 |
default: |
|
655 |
mainClass = loadMainClass(mode, what); |
|
656 |
break; |
|
657 |
} |
|
36511 | 658 |
|
42178
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
659 |
// 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
|
660 |
// 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
|
661 |
appClass = mainClass; |
36511 | 662 |
|
42178
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
663 |
/* |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
664 |
* 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
|
665 |
* 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
|
666 |
* validating the main class. |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
667 |
*/ |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
668 |
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
|
669 |
doesExtendFXApplication(mainClass)) { |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
670 |
// 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
|
671 |
FXHelper.setFXLaunchParameters(what, mode); |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
672 |
mainClass = FXHelper.class; |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
673 |
} |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
674 |
|
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
675 |
validateMainClass(mainClass); |
36511 | 676 |
return mainClass; |
677 |
} |
|
678 |
||
679 |
/** |
|
680 |
* Returns the main class for a module. The query is either a module name |
|
681 |
* or module-name/main-class. For the former then the module's main class |
|
682 |
* is obtained from the module descriptor (MainClass attribute). |
|
683 |
*/ |
|
684 |
private static Class<?> loadModuleMainClass(String what) { |
|
685 |
int i = what.indexOf('/'); |
|
686 |
String mainModule; |
|
687 |
String mainClass; |
|
688 |
if (i == -1) { |
|
689 |
mainModule = what; |
|
690 |
mainClass = null; |
|
691 |
} else { |
|
692 |
mainModule = what.substring(0, i); |
|
693 |
mainClass = what.substring(i+1); |
|
694 |
} |
|
695 |
||
696 |
// main module is in the boot layer |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
697 |
ModuleLayer layer = ModuleLayer.boot(); |
36511 | 698 |
Optional<Module> om = layer.findModule(mainModule); |
699 |
if (!om.isPresent()) { |
|
700 |
// should not happen |
|
701 |
throw new InternalError("Module " + mainModule + " not in boot Layer"); |
|
702 |
} |
|
703 |
Module m = om.get(); |
|
704 |
||
705 |
// get main class |
|
706 |
if (mainClass == null) { |
|
707 |
Optional<String> omc = m.getDescriptor().mainClass(); |
|
708 |
if (!omc.isPresent()) { |
|
709 |
abort(null, "java.launcher.module.error1", mainModule); |
|
710 |
} |
|
711 |
mainClass = omc.get(); |
|
712 |
} |
|
713 |
||
714 |
// 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
|
715 |
Class<?> c = null; |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
716 |
try { |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
717 |
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
|
718 |
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
|
719 |
&& Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) { |
36511 | 720 |
|
43496
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
721 |
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
|
722 |
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
|
723 |
} |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
724 |
} catch (LinkageError le) { |
43689
8ccdae71dba3
8173943: Change error reporting of LauncherHelper to include actual Error class name
rpatil
parents:
43496
diff
changeset
|
725 |
abort(null, "java.launcher.module.error3", mainClass, m.getName(), |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
726 |
le.getClass().getName() + ": " + le.getLocalizedMessage()); |
36511 | 727 |
} |
728 |
if (c == null) { |
|
729 |
abort(null, "java.launcher.module.error2", mainClass, mainModule); |
|
730 |
} |
|
731 |
||
732 |
System.setProperty("jdk.module.main.class", c.getName()); |
|
733 |
return c; |
|
734 |
} |
|
735 |
||
736 |
/** |
|
737 |
* Loads the main class from the class path (LM_CLASS or LM_JAR). |
|
738 |
*/ |
|
739 |
private static Class<?> loadMainClass(int mode, String what) { |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
740 |
// get the class name |
36511 | 741 |
String cn; |
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
742 |
switch (mode) { |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
743 |
case LM_CLASS: |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
744 |
cn = what; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
745 |
break; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
746 |
case LM_JAR: |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
747 |
cn = getMainClassFromJar(what); |
8174
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
748 |
break; |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
749 |
default: |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
750 |
// should never happen |
89e3a22d4cd7
6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents:
7997
diff
changeset
|
751 |
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
|
752 |
} |
36511 | 753 |
|
754 |
// load the main class |
|
7997
78536cac0841
6912013: Remove the temporary launcher fix to add modules in the bootclasspath
mchung
parents:
7810
diff
changeset
|
755 |
cn = cn.replace('/', '.'); |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
756 |
Class<?> mainClass = null; |
36511 | 757 |
ClassLoader scl = ClassLoader.getSystemClassLoader(); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
758 |
try { |
43496
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
759 |
try { |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
760 |
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
|
761 |
} catch (NoClassDefFoundError | ClassNotFoundException cnfe) { |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
762 |
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
|
763 |
&& 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
|
764 |
try { |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
765 |
// 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
|
766 |
// 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
|
767 |
// 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
|
768 |
// to re-compose it |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
769 |
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
|
770 |
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
|
771 |
} catch (NoClassDefFoundError | ClassNotFoundException cnfe1) { |
43809
c3669a70a7ab
8174694: improve error message shown when main class can't be loaded
vromero
parents:
43713
diff
changeset
|
772 |
abort(cnfe1, "java.launcher.cls.error1", cn, |
c3669a70a7ab
8174694: improve error message shown when main class can't be loaded
vromero
parents:
43713
diff
changeset
|
773 |
cnfe1.getClass().getCanonicalName(), cnfe1.getMessage()); |
43496
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
774 |
} |
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
775 |
} else { |
43809
c3669a70a7ab
8174694: improve error message shown when main class can't be loaded
vromero
parents:
43713
diff
changeset
|
776 |
abort(cnfe, "java.launcher.cls.error1", cn, |
c3669a70a7ab
8174694: improve error message shown when main class can't be loaded
vromero
parents:
43713
diff
changeset
|
777 |
cnfe.getClass().getCanonicalName(), cnfe.getMessage()); |
20179 | 778 |
} |
779 |
} |
|
43496
fbafb9f36e96
8167063: spurious message "A JNI error has occurred" if start-class cannot be initialized
rpatil
parents:
42339
diff
changeset
|
780 |
} catch (LinkageError le) { |
43689
8ccdae71dba3
8173943: Change error reporting of LauncherHelper to include actual Error class name
rpatil
parents:
43496
diff
changeset
|
781 |
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
|
782 |
le.getClass().getName() + ": " + le.getLocalizedMessage()); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
783 |
} |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
784 |
return mainClass; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
785 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
786 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
787 |
/* |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
788 |
* 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
|
789 |
* checkAndLoadMain(). The "application class" is the class that is finally |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
790 |
* 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
|
791 |
* the correct application name, typically for UI purposes. |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
792 |
*/ |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
793 |
public static Class<?> getApplicationClass() { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
794 |
return appClass; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
795 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
796 |
|
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
797 |
/* |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
798 |
* 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
|
799 |
* 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
|
800 |
* ClassNotFoundException if the JavaFX runtime is not available. |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
801 |
*/ |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
802 |
private static boolean doesExtendFXApplication(Class<?> mainClass) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
803 |
for (Class<?> sc = mainClass.getSuperclass(); sc != null; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
804 |
sc = sc.getSuperclass()) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
805 |
if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) { |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
806 |
return true; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
807 |
} |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
808 |
} |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
809 |
return false; |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
810 |
} |
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
811 |
|
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
812 |
// 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
|
813 |
static void validateMainClass(Class<?> mainClass) { |
45339
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
814 |
Method mainMethod = null; |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
815 |
try { |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
816 |
mainMethod = mainClass.getMethod("main", String[].class); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
817 |
} catch (NoSuchMethodException nsme) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
818 |
// 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
|
819 |
abort(null, "java.launcher.cls.error4", mainClass.getName(), |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
820 |
JAVAFX_APPLICATION_CLASS_NAME); |
45339
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
821 |
} catch (Throwable e) { |
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
822 |
if (mainClass.getModule().isNamed()) { |
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
823 |
abort(e, "java.launcher.module.error5", |
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
824 |
mainClass.getName(), mainClass.getModule(), |
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
825 |
e.getClass().getName(), e.getLocalizedMessage()); |
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
826 |
} else { |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45339
diff
changeset
|
827 |
abort(e, "java.launcher.cls.error7", mainClass.getName(), |
45339
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
828 |
e.getClass().getName(), e.getLocalizedMessage()); |
f2ab1225d11f
8181033: Confusing message: A JNI error has occurred, please check your installation and try again
mchung
parents:
45004
diff
changeset
|
829 |
} |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
830 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
831 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
832 |
/* |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
833 |
* 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
|
834 |
* 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
|
835 |
* ensure that the method is static and returns a void. |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
836 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
837 |
int mod = mainMethod.getModifiers(); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
838 |
if (!Modifier.isStatic(mod)) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
839 |
abort(null, "java.launcher.cls.error2", "static", |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
840 |
mainMethod.getDeclaringClass().getName()); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
841 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
842 |
if (mainMethod.getReturnType() != java.lang.Void.TYPE) { |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
843 |
abort(null, "java.launcher.cls.error3", |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
844 |
mainMethod.getDeclaringClass().getName()); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
845 |
} |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
846 |
} |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
847 |
|
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
848 |
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
|
849 |
private static String encoding = null; |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
850 |
private static boolean isCharsetSupported = false; |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
851 |
|
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
852 |
/* |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
853 |
* 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
|
854 |
* 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
|
855 |
*/ |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
856 |
static String makePlatformString(boolean printToStderr, byte[] inArray) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
857 |
initOutput(printToStderr); |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
858 |
if (encoding == null) { |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
859 |
encoding = System.getProperty(encprop); |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
860 |
isCharsetSupported = Charset.isSupported(encoding); |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
861 |
} |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
862 |
try { |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
863 |
String out = isCharsetSupported |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
864 |
? new String(inArray, encoding) |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
865 |
: new String(inArray); |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
866 |
return out; |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
867 |
} catch (UnsupportedEncodingException uee) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
868 |
abort(uee, null); |
8806
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
869 |
} |
c81d4e10ffb7
7026184: (launcher) Regression: class with unicode name can't be launched by java.
ksrini
parents:
8174
diff
changeset
|
870 |
return null; // keep the compiler happy |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
871 |
} |
13411
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
872 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
873 |
static String[] expandArgs(String[] argArray) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
874 |
List<StdArg> aList = new ArrayList<>(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
875 |
for (String x : argArray) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
876 |
aList.add(new StdArg(x)); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
877 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
878 |
return expandArgs(aList); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
879 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
880 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
881 |
static String[] expandArgs(List<StdArg> argList) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
882 |
ArrayList<String> out = new ArrayList<>(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
883 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
884 |
System.err.println("Incoming arguments:"); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
885 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
886 |
for (StdArg a : argList) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
887 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
888 |
System.err.println(a); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
889 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
890 |
if (a.needsExpansion) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
891 |
File x = new File(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
892 |
File parent = x.getParentFile(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
893 |
String glob = x.getName(); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
894 |
if (parent == null) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
895 |
parent = new File("."); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
896 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
897 |
try (DirectoryStream<Path> dstream = |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
898 |
Files.newDirectoryStream(parent.toPath(), glob)) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
899 |
int entries = 0; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
900 |
for (Path p : dstream) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
901 |
out.add(p.normalize().toString()); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
902 |
entries++; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
903 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
904 |
if (entries == 0) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
905 |
out.add(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
906 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
907 |
} catch (Exception e) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
908 |
out.add(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
909 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
910 |
System.err.println("Warning: passing argument as-is " + a); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
911 |
System.err.print(e); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
912 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
913 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
914 |
} else { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
915 |
out.add(a.arg); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
916 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
917 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
918 |
String[] oarray = new String[out.size()]; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
919 |
out.toArray(oarray); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
920 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
921 |
if (trace) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
922 |
System.err.println("Expanded arguments:"); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
923 |
for (String x : oarray) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
924 |
System.err.println(x); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
925 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
926 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
927 |
return oarray; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
928 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
929 |
|
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
930 |
/* duplicate of the native StdArg struct */ |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
931 |
private static class StdArg { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
932 |
final String arg; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
933 |
final boolean needsExpansion; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
934 |
StdArg(String arg, boolean expand) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
935 |
this.arg = arg; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
936 |
this.needsExpansion = expand; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
937 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
938 |
// protocol: first char indicates whether expansion is required |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
939 |
// 'T' = true ; needs expansion |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
940 |
// 'F' = false; needs no expansion |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
941 |
StdArg(String in) { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
942 |
this.arg = in.substring(1); |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
943 |
needsExpansion = in.charAt(0) == 'T'; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
944 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
945 |
public String toString() { |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
946 |
return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}'; |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
947 |
} |
224a28370893
7146424: Wildcard expansion for single entry classpath
ksrini
parents:
12538
diff
changeset
|
948 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
949 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
950 |
static final class FXHelper { |
24254
2da866863b98
8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
ksrini
parents:
20179
diff
changeset
|
951 |
|
36511 | 952 |
private static final String JAVAFX_GRAPHICS_MODULE_NAME = |
953 |
"javafx.graphics"; |
|
954 |
||
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
955 |
private static final String JAVAFX_LAUNCHER_CLASS_NAME = |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
956 |
"com.sun.javafx.application.LauncherImpl"; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
957 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
958 |
/* |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
959 |
* 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
|
960 |
* 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
|
961 |
* |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
962 |
* 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
|
963 |
* 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
|
964 |
* 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
|
965 |
* 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
|
966 |
* 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
|
967 |
* 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
|
968 |
* 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
|
969 |
* |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
970 |
* [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
|
971 |
* 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
|
972 |
*/ |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
973 |
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
|
974 |
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
|
975 |
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
|
976 |
|
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
977 |
/* |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
978 |
* FX application launcher and launch method, so we can launch |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
979 |
* applications with no main method. |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
980 |
*/ |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
981 |
private static String fxLaunchName = null; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
982 |
private static String fxLaunchMode = null; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
983 |
|
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
984 |
private static Class<?> fxLauncherClass = null; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
985 |
private static Method fxLauncherMethod = null; |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
986 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
987 |
/* |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
988 |
* 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
|
989 |
* 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
|
990 |
* 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
|
991 |
*/ |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
992 |
private static void setFXLaunchParameters(String what, int mode) { |
36511 | 993 |
|
994 |
// find the module with the FX launcher |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
995 |
Optional<Module> om = ModuleLayer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME); |
36511 | 996 |
if (!om.isPresent()) { |
997 |
abort(null, "java.launcher.cls.error5"); |
|
998 |
} |
|
999 |
||
1000 |
// load the FX launcher class |
|
1001 |
fxLauncherClass = Class.forName(om.get(), JAVAFX_LAUNCHER_CLASS_NAME); |
|
1002 |
if (fxLauncherClass == null) { |
|
1003 |
abort(null, "java.launcher.cls.error5"); |
|
1004 |
} |
|
1005 |
||
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1006 |
try { |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1007 |
/* |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1008 |
* signature must be: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1009 |
* public static void launchApplication(String launchName, |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1010 |
* String launchMode, String[] args); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1011 |
*/ |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1012 |
fxLauncherMethod = fxLauncherClass.getMethod("launchApplication", |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1013 |
String.class, String.class, String[].class); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1014 |
|
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1015 |
// 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
|
1016 |
int mod = fxLauncherMethod.getModifiers(); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1017 |
if (!Modifier.isStatic(mod)) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1018 |
abort(null, "java.launcher.javafx.error1"); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1019 |
} |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1020 |
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
|
1021 |
abort(null, "java.launcher.javafx.error1"); |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1022 |
} |
36511 | 1023 |
} catch (NoSuchMethodException ex) { |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1024 |
abort(ex, "java.launcher.cls.error5", ex); |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1025 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1026 |
|
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1027 |
fxLaunchName = what; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1028 |
switch (mode) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1029 |
case LM_CLASS: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1030 |
fxLaunchMode = JAVAFX_LAUNCH_MODE_CLASS; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1031 |
break; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1032 |
case LM_JAR: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1033 |
fxLaunchMode = JAVAFX_LAUNCH_MODE_JAR; |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1034 |
break; |
42178
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
1035 |
case LM_MODULE: |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
1036 |
fxLaunchMode = JAVAFX_LAUNCH_MODE_MODULE; |
cb5cb430e207
8169289: JavaFX application in named module fails to launch if no main method
ddehaven
parents:
41966
diff
changeset
|
1037 |
break; |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1038 |
default: |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1039 |
// should not have gotten this far... |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1040 |
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
|
1041 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1042 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1043 |
|
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1044 |
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
|
1045 |
if (fxLauncherMethod == null |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1046 |
|| fxLaunchMode == null |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1047 |
|| fxLaunchName == null) { |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1048 |
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
|
1049 |
} |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1050 |
// launch appClass via fxLauncherMethod |
15003
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1051 |
fxLauncherMethod.invoke(null, |
364408faddeb
8004547: Extend JavaFX launcher support to allow full JavaFX launch feature set
ksrini
parents:
14518
diff
changeset
|
1052 |
new Object[] {fxLaunchName, fxLaunchMode, args}); |
14518
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1053 |
} |
f4b1adde53b3
8001533: java launcher must launch javafx applications
ksrini
parents:
13411
diff
changeset
|
1054 |
} |
36511 | 1055 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1056 |
/** |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1057 |
* Called by the launcher to list the observable modules. |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1058 |
*/ |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1059 |
static void listModules() { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1060 |
initOutput(System.out); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1061 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1062 |
ModuleBootstrap.limitedFinder().findAll().stream() |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1063 |
.sorted(new JrtFirstComparator()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1064 |
.forEach(LauncherHelper::showModule); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1065 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1066 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1067 |
/** |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1068 |
* Called by the launcher to show the resolved modules |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1069 |
*/ |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1070 |
static void showResolvedModules() { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1071 |
initOutput(System.out); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1072 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1073 |
ModuleLayer bootLayer = ModuleLayer.boot(); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1074 |
Configuration cf = bootLayer.configuration(); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1075 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1076 |
cf.modules().stream() |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1077 |
.map(ResolvedModule::reference) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1078 |
.sorted(new JrtFirstComparator()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1079 |
.forEach(LauncherHelper::showModule); |
36511 | 1080 |
} |
1081 |
||
1082 |
/** |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1083 |
* Called by the launcher to describe a module |
36511 | 1084 |
*/ |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1085 |
static void describeModule(String moduleName) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1086 |
initOutput(System.out); |
36511 | 1087 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1088 |
ModuleFinder finder = ModuleBootstrap.limitedFinder(); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1089 |
ModuleReference mref = finder.find(moduleName).orElse(null); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1090 |
if (mref == null) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1091 |
abort(null, "java.launcher.module.error4", moduleName); |
36511 | 1092 |
} |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1093 |
ModuleDescriptor md = mref.descriptor(); |
36511 | 1094 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1095 |
// one-line summary |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1096 |
showModule(mref); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1097 |
|
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1098 |
// unqualified exports (sorted by package) |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1099 |
md.exports().stream() |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1100 |
.filter(e -> !e.isQualified()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1101 |
.sorted(Comparator.comparing(Exports::source)) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1102 |
.map(e -> Stream.concat(Stream.of(e.source()), |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1103 |
toStringStream(e.modifiers())) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1104 |
.collect(Collectors.joining(" "))) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1105 |
.forEach(sourceAndMods -> ostream.format("exports %s%n", sourceAndMods)); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1106 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1107 |
// dependences |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1108 |
for (Requires r : md.requires()) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1109 |
String nameAndMods = Stream.concat(Stream.of(r.name()), |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1110 |
toStringStream(r.modifiers())) |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1111 |
.collect(Collectors.joining(" ")); |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1112 |
ostream.format("requires %s", nameAndMods); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1113 |
finder.find(r.name()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1114 |
.map(ModuleReference::descriptor) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1115 |
.filter(ModuleDescriptor::isAutomatic) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1116 |
.ifPresent(any -> ostream.print(" automatic")); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1117 |
ostream.println(); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1118 |
} |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1119 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1120 |
// service use and provides |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1121 |
for (String s : md.uses()) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1122 |
ostream.format("uses %s%n", s); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1123 |
} |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1124 |
for (Provides ps : md.provides()) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1125 |
String names = ps.providers().stream().collect(Collectors.joining(" ")); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1126 |
ostream.format("provides %s with %s%n", ps.service(), names); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1127 |
|
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1128 |
} |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1129 |
|
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1130 |
// qualified exports |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1131 |
for (Exports e : md.exports()) { |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1132 |
if (e.isQualified()) { |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1133 |
String who = e.targets().stream().collect(Collectors.joining(" ")); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1134 |
ostream.format("qualified exports %s to %s%n", e.source(), who); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1135 |
} |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1136 |
} |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1137 |
|
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1138 |
// open packages |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1139 |
for (Opens opens: md.opens()) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1140 |
if (opens.isQualified()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1141 |
ostream.print("qualified "); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1142 |
String sourceAndMods = Stream.concat(Stream.of(opens.source()), |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1143 |
toStringStream(opens.modifiers())) |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1144 |
.collect(Collectors.joining(" ")); |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1145 |
ostream.format("opens %s", sourceAndMods); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1146 |
if (opens.isQualified()) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1147 |
String who = opens.targets().stream().collect(Collectors.joining(" ")); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1148 |
ostream.format(" to %s", who); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1149 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1150 |
ostream.println(); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1151 |
} |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1152 |
|
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1153 |
// non-exported/non-open packages |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1154 |
Set<String> concealed = new TreeSet<>(md.packages()); |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1155 |
md.exports().stream().map(Exports::source).forEach(concealed::remove); |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1156 |
md.opens().stream().map(Opens::source).forEach(concealed::remove); |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1157 |
concealed.forEach(p -> ostream.format("contains %s%n", p)); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1158 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1159 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1160 |
/** |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1161 |
* Prints a single line with the module name, version and modifiers |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1162 |
*/ |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1163 |
private static void showModule(ModuleReference mref) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1164 |
ModuleDescriptor md = mref.descriptor(); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1165 |
ostream.print(md.toNameAndVersion()); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1166 |
mref.location() |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1167 |
.filter(uri -> !isJrt(uri)) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1168 |
.ifPresent(uri -> ostream.format(" %s", uri)); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1169 |
if (md.isOpen()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1170 |
ostream.print(" open"); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1171 |
if (md.isAutomatic()) |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1172 |
ostream.print(" automatic"); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1173 |
ostream.println(); |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1174 |
} |
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
1175 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1176 |
/** |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1177 |
* A ModuleReference comparator that considers modules in the run-time |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1178 |
* image to be less than modules than not in the run-time image. |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1179 |
*/ |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1180 |
private static class JrtFirstComparator implements Comparator<ModuleReference> { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1181 |
private final Comparator<ModuleReference> real; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1182 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1183 |
JrtFirstComparator() { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1184 |
this.real = Comparator.comparing(ModuleReference::descriptor); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1185 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1186 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1187 |
@Override |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1188 |
public int compare(ModuleReference a, ModuleReference b) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1189 |
if (isJrt(a)) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1190 |
return isJrt(b) ? real.compare(a, b) : -1; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1191 |
} else { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1192 |
return isJrt(b) ? 1 : real.compare(a, b); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1193 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1194 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
1195 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
1196 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1197 |
private static <T> Stream<String> toStringStream(Set<T> s) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
1198 |
return s.stream().map(e -> e.toString().toLowerCase()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
1199 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41966
diff
changeset
|
1200 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1201 |
private static boolean isJrt(ModuleReference mref) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1202 |
return isJrt(mref.location().orElse(null)); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1203 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1204 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1205 |
private static boolean isJrt(URI uri) { |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1206 |
return (uri != null && uri.getScheme().equalsIgnoreCase("jrt")); |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1207 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
1208 |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
diff
changeset
|
1209 |
} |