8035782: sun/launcher/LauncherHelper$FXHelper loaded unnecessarily
Reviewed-by: ddehaven, kcr, ksrini, mchung
This commit is contained in:
parent
bd948f1ace
commit
a3798db37e
@ -69,6 +69,14 @@ import java.util.jar.Manifest;
|
|||||||
|
|
||||||
public enum LauncherHelper {
|
public enum LauncherHelper {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
|
// used to identify JavaFX applications
|
||||||
|
private static final String JAVAFX_APPLICATION_MARKER =
|
||||||
|
"JavaFX-Application-Class";
|
||||||
|
private static final String JAVAFX_APPLICATION_CLASS_NAME =
|
||||||
|
"javafx.application.Application";
|
||||||
|
private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX =
|
||||||
|
"sun.launcher.LauncherHelper$FXHelper";
|
||||||
private static final String MAIN_CLASS = "Main-Class";
|
private static final String MAIN_CLASS = "Main-Class";
|
||||||
|
|
||||||
private static StringBuilder outBuf = new StringBuilder();
|
private static StringBuilder outBuf = new StringBuilder();
|
||||||
@ -418,7 +426,8 @@ public enum LauncherHelper {
|
|||||||
* exists to enforce compliance with the jar specification
|
* exists to enforce compliance with the jar specification
|
||||||
*/
|
*/
|
||||||
if (mainAttrs.containsKey(
|
if (mainAttrs.containsKey(
|
||||||
new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
|
new Attributes.Name(JAVAFX_APPLICATION_MARKER))) {
|
||||||
|
FXHelper.setFXLaunchParameters(jarname, LM_JAR);
|
||||||
return FXHelper.class.getName();
|
return FXHelper.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,9 +525,9 @@ public enum LauncherHelper {
|
|||||||
* the main class may or may not have a main method, so do this before
|
* the main class may or may not have a main method, so do this before
|
||||||
* validating the main class.
|
* validating the main class.
|
||||||
*/
|
*/
|
||||||
if (mainClass.equals(FXHelper.class) ||
|
if (JAVAFX_FXHELPER_CLASS_NAME_SUFFIX.equals(mainClass.getName()) ||
|
||||||
FXHelper.doesExtendFXApplication(mainClass)) {
|
doesExtendFXApplication(mainClass)) {
|
||||||
// Will abort() if there are problems with the FX runtime
|
// Will abort() if there are problems with FX runtime
|
||||||
FXHelper.setFXLaunchParameters(what, mode);
|
FXHelper.setFXLaunchParameters(what, mode);
|
||||||
return FXHelper.class;
|
return FXHelper.class;
|
||||||
}
|
}
|
||||||
@ -537,6 +546,21 @@ public enum LauncherHelper {
|
|||||||
return appClass;
|
return appClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the given class is a JavaFX Application class. This is done
|
||||||
|
* in a way that does not cause the Application class to load or throw
|
||||||
|
* ClassNotFoundException if the JavaFX runtime is not available.
|
||||||
|
*/
|
||||||
|
private static boolean doesExtendFXApplication(Class<?> mainClass) {
|
||||||
|
for (Class<?> sc = mainClass.getSuperclass(); sc != null;
|
||||||
|
sc = sc.getSuperclass()) {
|
||||||
|
if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the existence and signature of main and abort if incorrect
|
// Check the existence and signature of main and abort if incorrect
|
||||||
static void validateMainClass(Class<?> mainClass) {
|
static void validateMainClass(Class<?> mainClass) {
|
||||||
Method mainMethod;
|
Method mainMethod;
|
||||||
@ -545,7 +569,7 @@ public enum LauncherHelper {
|
|||||||
} catch (NoSuchMethodException nsme) {
|
} catch (NoSuchMethodException nsme) {
|
||||||
// invalid main or not FX application, abort with an error
|
// invalid main or not FX application, abort with an error
|
||||||
abort(null, "java.launcher.cls.error4", mainClass.getName(),
|
abort(null, "java.launcher.cls.error4", mainClass.getName(),
|
||||||
FXHelper.JAVAFX_APPLICATION_CLASS_NAME);
|
JAVAFX_APPLICATION_CLASS_NAME);
|
||||||
return; // Avoid compiler issues
|
return; // Avoid compiler issues
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,11 +692,7 @@ public enum LauncherHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static final class FXHelper {
|
static final class FXHelper {
|
||||||
// Marker entry in jar manifest that designates a JavaFX application jar
|
|
||||||
private static final String JAVAFX_APPLICATION_MARKER =
|
|
||||||
"JavaFX-Application-Class";
|
|
||||||
private static final String JAVAFX_APPLICATION_CLASS_NAME =
|
|
||||||
"javafx.application.Application";
|
|
||||||
private static final String JAVAFX_LAUNCHER_CLASS_NAME =
|
private static final String JAVAFX_LAUNCHER_CLASS_NAME =
|
||||||
"com.sun.javafx.application.LauncherImpl";
|
"com.sun.javafx.application.LauncherImpl";
|
||||||
|
|
||||||
@ -742,21 +762,6 @@ public enum LauncherHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if the given class is a JavaFX Application class. This is done
|
|
||||||
* in a way that does not cause the Application class to load or throw
|
|
||||||
* ClassNotFoundException if the JavaFX runtime is not available.
|
|
||||||
*/
|
|
||||||
private static boolean doesExtendFXApplication(Class<?> mainClass) {
|
|
||||||
for (Class<?> sc = mainClass.getSuperclass(); sc != null;
|
|
||||||
sc = sc.getSuperclass()) {
|
|
||||||
if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
if (fxLauncherMethod == null
|
if (fxLauncherMethod == null
|
||||||
|| fxLaunchMode == null
|
|| fxLaunchMode == null
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8001533 8004547
|
* @bug 8001533 8004547 8035782
|
||||||
* @summary Test launching FX application with java -jar
|
* @summary Test launching FX application with java -jar
|
||||||
* Test uses main method and blank main method, a jfx app class and an incorrest
|
* Test uses main method and blank main method, a jfx app class and an incorrest
|
||||||
* jfx app class, a main-class for the manifest, a bogus one and none.
|
* jfx app class, a main-class for the manifest, a bogus one and none.
|
||||||
@ -373,6 +373,11 @@ public class FXLauncherTest extends TestHelper {
|
|||||||
System.out.println(tr);
|
System.out.println(tr);
|
||||||
throw new Exception("jfxrt.jar is being loaded, it should not be!");
|
throw new Exception("jfxrt.jar is being loaded, it should not be!");
|
||||||
}
|
}
|
||||||
|
if (!tr.notContains("sun.launcher.LauncherHelper$FXHelper")) {
|
||||||
|
System.out.println("testing for extraneous 'sun.launcher.LauncherHelper$FXHelper'");
|
||||||
|
System.out.println(tr);
|
||||||
|
throw new Exception("FXHelper is being loaded, it should not be!");
|
||||||
|
}
|
||||||
for (String p : APP_PARMS) {
|
for (String p : APP_PARMS) {
|
||||||
if (!tr.contains(p)) {
|
if (!tr.contains(p)) {
|
||||||
System.err.println("ERROR: Did not find "
|
System.err.println("ERROR: Did not find "
|
||||||
|
Loading…
Reference in New Issue
Block a user