src/share/classes/sun/launcher/LauncherHelper.java

Print this page
rev 9771 : 8035782 : sun/launcher/LauncherHelper loaded unnecessarily

*** 67,76 **** --- 67,84 ---- import java.util.jar.JarFile; import java.util.jar.Manifest; public enum LauncherHelper { 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 = + "LauncherHelper$FXHelper"; private static final String MAIN_CLASS = "Main-Class"; private static StringBuilder outBuf = new StringBuilder(); private static final String INDENT = " ";
*** 416,426 **** * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( ! new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { --- 424,435 ---- * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( ! new Attributes.Name(JAVAFX_APPLICATION_MARKER))) { ! FXHelper.setFXLaunchParameters(jarname, LM_JAR); return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) {
*** 514,526 **** /* * Check if FXHelper can launch it using the FX launcher. In an FX app, * the main class may or may not have a main method, so do this before * validating the main class. */ ! if (mainClass.equals(FXHelper.class) || ! FXHelper.doesExtendFXApplication(mainClass)) { ! // Will abort() if there are problems with the FX runtime FXHelper.setFXLaunchParameters(what, mode); return FXHelper.class; } validateMainClass(mainClass); --- 523,535 ---- /* * Check if FXHelper can launch it using the FX launcher. In an FX app, * the main class may or may not have a main method, so do this before * validating the main class. */ ! if ( mainClass.getName().contains(JAVAFX_FXHELPER_CLASS_NAME_SUFFIX) || ! doesExtendFXApplication(mainClass)) { ! // Will abort() if there are problems with FX runtime FXHelper.setFXLaunchParameters(what, mode); return FXHelper.class; } validateMainClass(mainClass);
*** 535,553 **** */ public static Class<?> getApplicationClass() { return appClass; } // Check the existence and signature of main and abort if incorrect static void validateMainClass(Class<?> mainClass) { Method mainMethod; try { mainMethod = mainClass.getMethod("main", String[].class); } catch (NoSuchMethodException nsme) { // invalid main or not FX application, abort with an error abort(null, "java.launcher.cls.error4", mainClass.getName(), ! FXHelper.JAVAFX_APPLICATION_CLASS_NAME); return; // Avoid compiler issues } /* * getMethod (above) will choose the correct method, based --- 544,577 ---- */ public static Class<?> getApplicationClass() { 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 static void validateMainClass(Class<?> mainClass) { Method mainMethod; try { mainMethod = mainClass.getMethod("main", String[].class); } catch (NoSuchMethodException nsme) { // invalid main or not FX application, abort with an error abort(null, "java.launcher.cls.error4", mainClass.getName(), ! JAVAFX_APPLICATION_CLASS_NAME); return; // Avoid compiler issues } /* * getMethod (above) will choose the correct method, based
*** 561,570 **** --- 585,595 ---- } if (mainMethod.getReturnType() != java.lang.Void.TYPE) { abort(null, "java.launcher.cls.error3", mainMethod.getDeclaringClass().getName()); } + return; } private static final String encprop = "sun.jnu.encoding"; private static String encoding = null; private static boolean isCharsetSupported = false;
*** 666,680 **** return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}'; } } 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 = "com.sun.javafx.application.LauncherImpl"; /* * The launch method used to invoke the JavaFX launcher. These must --- 691,701 ---- return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}'; } } static final class FXHelper { ! private static final String JAVAFX_LAUNCHER_CLASS_NAME = "com.sun.javafx.application.LauncherImpl"; /* * The launch method used to invoke the JavaFX launcher. These must
*** 740,764 **** // should not have gotten this far... throw new InternalError(mode + ": Unknown launch mode"); } } - /* - * 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 { if (fxLauncherMethod == null || fxLaunchMode == null || fxLaunchName == null) { throw new RuntimeException("Invalid JavaFX launch parameters"); --- 761,770 ----