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