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


 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             /*
 413              * Hand off to FXHelper if it detects a JavaFX application
 414              * This must be done after ensuring a Main-Class entry
 415              * exists to enforce compliance with the jar specification
 416              */
 417             if (mainAttrs.containsKey(
 418                     new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
 419                 return FXHelper.class.getName();
 420             }






















 421             return mainValue.trim();
 422         } catch (IOException ioe) {
 423             abort(ioe, "java.launcher.jar.error1", jarname);
 424         }
 425         return null;
 426     }
 427 
 428     // From src/share/bin/java.c:
 429     //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR };
 430 
 431     private static final int LM_UNKNOWN = 0;
 432     private static final int LM_CLASS   = 1;
 433     private static final int LM_JAR     = 2;
 434 
 435     static void abort(Throwable t, String msgKey, Object... args) {
 436         if (msgKey != null) {
 437             ostream.println(getLocalizedMessage(msgKey, args));
 438         }
 439         if (trace) {
 440             if (t != null) {




  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


 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              * Hand off to FXHelper if it detects a JavaFX application
 418              * This must be done after ensuring a Main-Class entry
 419              * exists to enforce compliance with the jar specification
 420              */
 421             if (mainAttrs.containsKey(
 422                     new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
 423                 return FXHelper.class.getName();
 424             }
 425 
 426             /*
 427              * If this is not a full JRE then the Profile attribute must be
 428              * present with the Main-Class attribute so as to indicate the minimum
 429              * profile required. Note that we need to suppress checking of the Profile
 430              * attribute after we detect an error. This is because the abort may
 431              * need to lookup resources and this may involve opening additional JAR
 432              * files that would result in errors that suppress the main error.
 433              */
 434             String profile = mainAttrs.getValue(PROFILE);
 435             if (profile == null) {
 436                 if (!Version.isFullJre()) {
 437                     URLClassPath.suppressProfileCheckForLauncher();
 438                     abort(null, "java.launcher.jar.error4", jarname);
 439                 }
 440             } else {
 441                 if (!Version.supportsProfile(profile)) {
 442                     URLClassPath.suppressProfileCheckForLauncher();
 443                     abort(null, "java.launcher.jar.error5", profile, jarname);
 444                 }
 445             }
 446 
 447             return mainValue.trim();
 448         } catch (IOException ioe) {
 449             abort(ioe, "java.launcher.jar.error1", jarname);
 450         }
 451         return null;
 452     }
 453 
 454     // From src/share/bin/java.c:
 455     //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR };
 456 
 457     private static final int LM_UNKNOWN = 0;
 458     private static final int LM_CLASS   = 1;
 459     private static final int LM_JAR     = 2;
 460 
 461     static void abort(Throwable t, String msgKey, Object... args) {
 462         if (msgKey != null) {
 463             ostream.println(getLocalizedMessage(msgKey, args));
 464         }
 465         if (trace) {
 466             if (t != null) {


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