src/share/classes/sun/launcher/LauncherHelper.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File jdk Sdiff src/share/classes/sun/launcher

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

Print this page




  48 import java.math.BigDecimal;
  49 import java.math.RoundingMode;
  50 import java.nio.charset.Charset;
  51 import java.nio.file.DirectoryStream;
  52 import java.nio.file.Files;
  53 import java.nio.file.Path;
  54 import java.util.ResourceBundle;
  55 import java.text.MessageFormat;
  56 import java.util.ArrayList;
  57 import java.util.Collections;
  58 import java.util.Iterator;
  59 import java.util.List;
  60 import java.util.Locale;
  61 import java.util.Locale.Category;
  62 import java.util.Properties;
  63 import java.util.Set;
  64 import java.util.TreeSet;
  65 import java.util.jar.Attributes;
  66 import java.util.jar.JarFile;
  67 import java.util.jar.Manifest;


  68 
  69 public enum LauncherHelper {
  70     INSTANCE;
  71     private static final String MAIN_CLASS = "Main-Class";


  72     private static StringBuilder outBuf = new StringBuilder();
  73 
  74     private static final String INDENT = "    ";
  75     private static final String VM_SETTINGS     = "VM settings:";
  76     private static final String PROP_SETTINGS   = "Property settings:";
  77     private static final String LOCALE_SETTINGS = "Locale settings:";
  78 
  79     // sync with java.c and sun.misc.VM
  80     private static final String diagprop = "sun.java.launcher.diag";
  81     final static boolean trace = sun.misc.VM.getSavedProperty(diagprop) != null;
  82 
  83     private static final String defaultBundleName =
  84             "sun.launcher.resources.launcher";
  85     private static class ResourceBundleHolder {
  86         private static final ResourceBundle RB =
  87                 ResourceBundle.getBundle(defaultBundleName);
  88     }
  89     private static PrintStream ostream;
  90     private static final ClassLoader scloader = ClassLoader.getSystemClassLoader();
  91     private static Class<?> appClass; // application class, for GUI/reporting purposes


 392 
 393     static void initOutput(boolean printToStderr) {
 394         ostream =  (printToStderr) ? System.err : System.out;
 395     }
 396 
 397     static String getMainClassFromJar(String jarname) {
 398         String mainValue = null;
 399         try (JarFile jarFile = new JarFile(jarname)) {
 400             Manifest manifest = jarFile.getManifest();
 401             if (manifest == null) {
 402                 abort(null, "java.launcher.jar.error2", jarname);
 403             }
 404             Attributes mainAttrs = manifest.getMainAttributes();
 405             if (mainAttrs == null) {
 406                 abort(null, "java.launcher.jar.error3", jarname);
 407             }
 408             mainValue = mainAttrs.getValue(MAIN_CLASS);
 409             if (mainValue == null) {
 410                 abort(null, "java.launcher.jar.error3", jarname);
 411             }



















 412             return mainValue.trim();
 413         } catch (IOException ioe) {
 414             abort(ioe, "java.launcher.jar.error1", jarname);
 415         }
 416         return null;
 417     }
 418 
 419     // From src/share/bin/java.c:
 420     //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR };
 421 
 422     private static final int LM_UNKNOWN = 0;
 423     private static final int LM_CLASS   = 1;
 424     private static final int LM_JAR     = 2;
 425 
 426     static void abort(Throwable t, String msgKey, Object... args) {
 427         if (msgKey != null) {
 428             ostream.println(getLocalizedMessage(msgKey, args));
 429         }
 430         if (trace) {
 431             if (t != null) {


 686          * in a way that does not cause the Application class to load or throw
 687          * ClassNotFoundException if the JavaFX runtime is not available.
 688          */
 689         private static boolean doesExtendFXApplication(Class<?> mainClass) {
 690             for (Class<?> sc = mainClass.getSuperclass(); sc != null;
 691                     sc = sc.getSuperclass()) {
 692                 if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) {
 693                     return true;
 694                 }
 695             }
 696             return false;
 697         }
 698 
 699         // preloader ?
 700         public static void main(String... args) throws Exception {
 701             // launch appClass via fxLauncherMethod
 702             fxLauncherMethod.invoke(null, new Object[] {appClass, args});
 703         }
 704     }
 705 }
 706 


  48 import java.math.BigDecimal;
  49 import java.math.RoundingMode;
  50 import java.nio.charset.Charset;
  51 import java.nio.file.DirectoryStream;
  52 import java.nio.file.Files;
  53 import java.nio.file.Path;
  54 import java.util.ResourceBundle;
  55 import java.text.MessageFormat;
  56 import java.util.ArrayList;
  57 import java.util.Collections;
  58 import java.util.Iterator;
  59 import java.util.List;
  60 import java.util.Locale;
  61 import java.util.Locale.Category;
  62 import java.util.Properties;
  63 import java.util.Set;
  64 import java.util.TreeSet;
  65 import java.util.jar.Attributes;
  66 import java.util.jar.JarFile;
  67 import java.util.jar.Manifest;
  68 import sun.misc.Version;
  69 import sun.misc.URLClassPath;
  70 
  71 public enum LauncherHelper {
  72     INSTANCE;
  73     private static final String MAIN_CLASS = "Main-Class";
  74     private static final String PROFILE    = "Profile";
  75 
  76     private static StringBuilder outBuf = new StringBuilder();
  77 
  78     private static final String INDENT = "    ";
  79     private static final String VM_SETTINGS     = "VM settings:";
  80     private static final String PROP_SETTINGS   = "Property settings:";
  81     private static final String LOCALE_SETTINGS = "Locale settings:";
  82 
  83     // sync with java.c and sun.misc.VM
  84     private static final String diagprop = "sun.java.launcher.diag";
  85     final static boolean trace = sun.misc.VM.getSavedProperty(diagprop) != null;
  86 
  87     private static final String defaultBundleName =
  88             "sun.launcher.resources.launcher";
  89     private static class ResourceBundleHolder {
  90         private static final ResourceBundle RB =
  91                 ResourceBundle.getBundle(defaultBundleName);
  92     }
  93     private static PrintStream ostream;
  94     private static final ClassLoader scloader = ClassLoader.getSystemClassLoader();
  95     private static Class<?> appClass; // application class, for GUI/reporting purposes


 396 
 397     static void initOutput(boolean printToStderr) {
 398         ostream =  (printToStderr) ? System.err : System.out;
 399     }
 400 
 401     static String getMainClassFromJar(String jarname) {
 402         String mainValue = null;
 403         try (JarFile jarFile = new JarFile(jarname)) {
 404             Manifest manifest = jarFile.getManifest();
 405             if (manifest == null) {
 406                 abort(null, "java.launcher.jar.error2", jarname);
 407             }
 408             Attributes mainAttrs = manifest.getMainAttributes();
 409             if (mainAttrs == null) {
 410                 abort(null, "java.launcher.jar.error3", jarname);
 411             }
 412             mainValue = mainAttrs.getValue(MAIN_CLASS);
 413             if (mainValue == null) {
 414                 abort(null, "java.launcher.jar.error3", jarname);
 415             }
 416 
 417             // if this is not a full JRE then the Profile attribute must be
 418             // present with the Main-Class attribute so as to indicate the minimum
 419             // profile required. Note that we need to suppress checking of the Profile
 420             // attribute after we detect an error. This is because the abort may
 421             // need to lookup resources and this may involve opening additional JAR
 422             // files that would result in errors that suppress the main error.
 423             String profile = mainAttrs.getValue(PROFILE);
 424             if (profile == null) {
 425                 if (!Version.isFullJre()) {
 426                     URLClassPath.suppressProfileCheckForLauncher();
 427                     abort(null, "java.launcher.jar.error4", jarname);
 428                 }
 429             } else {
 430                 if (!Version.supportsProfile(profile)) {
 431                     URLClassPath.suppressProfileCheckForLauncher();
 432                     abort(null, "java.launcher.jar.error5", profile, jarname);
 433                 }
 434             }
 435             return mainValue.trim();
 436         } catch (IOException ioe) {
 437             abort(ioe, "java.launcher.jar.error1", jarname);
 438         }
 439         return null;
 440     }
 441 
 442     // From src/share/bin/java.c:
 443     //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR };
 444 
 445     private static final int LM_UNKNOWN = 0;
 446     private static final int LM_CLASS   = 1;
 447     private static final int LM_JAR     = 2;
 448 
 449     static void abort(Throwable t, String msgKey, Object... args) {
 450         if (msgKey != null) {
 451             ostream.println(getLocalizedMessage(msgKey, args));
 452         }
 453         if (trace) {
 454             if (t != null) {


 709          * in a way that does not cause the Application class to load or throw
 710          * ClassNotFoundException if the JavaFX runtime is not available.
 711          */
 712         private static boolean doesExtendFXApplication(Class<?> mainClass) {
 713             for (Class<?> sc = mainClass.getSuperclass(); sc != null;
 714                     sc = sc.getSuperclass()) {
 715                 if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) {
 716                     return true;
 717                 }
 718             }
 719             return false;
 720         }
 721 
 722         // preloader ?
 723         public static void main(String... args) throws Exception {
 724             // launch appClass via fxLauncherMethod
 725             fxLauncherMethod.invoke(null, new Object[] {appClass, args});
 726         }
 727     }
 728 }

src/share/classes/sun/launcher/LauncherHelper.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File