jdk/src/share/classes/sun/misc/Version.java.template
changeset 15683 3acd10709925
parent 8993 9076d969ffdf
child 16731 c6f7eeb4acc0
equal deleted inserted replaced
15682:793a36de151d 15683:3acd10709925
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    34 
    34 
    35     private static final String java_version =
    35     private static final String java_version =
    36         "@@java_version@@";
    36         "@@java_version@@";
    37 
    37 
    38     private static final String java_runtime_name =
    38     private static final String java_runtime_name =
    39 	"@@java_runtime_name@@";
    39         "@@java_runtime_name@@";
    40  
    40 
       
    41     private static final String java_profile_name =
       
    42         "@@java_profile_name@@";
       
    43 
    41     private static final String java_runtime_version =
    44     private static final String java_runtime_version =
    42         "@@java_runtime_version@@";
    45         "@@java_runtime_version@@";
    43 
    46 
    44     static {
    47     static {
    45         init();
    48         init();
    47 
    50 
    48     public static void init() {
    51     public static void init() {
    49         System.setProperty("java.version", java_version);
    52         System.setProperty("java.version", java_version);
    50         System.setProperty("java.runtime.version", java_runtime_version);
    53         System.setProperty("java.runtime.version", java_runtime_version);
    51         System.setProperty("java.runtime.name", java_runtime_name);
    54         System.setProperty("java.runtime.name", java_runtime_name);
       
    55         if (java_profile_name.length() > 0)
       
    56             System.setProperty("java.runtime.profile", java_profile_name);
    52     }
    57     }
    53 
    58 
    54     private static boolean versionsInitialized = false;
    59     private static boolean versionsInitialized = false;
    55     private static int jvm_major_version = 0;
    60     private static int jvm_major_version = 0;
    56     private static int jvm_minor_version = 0;
    61     private static int jvm_minor_version = 0;
    88      */
    93      */
    89     public static void print(PrintStream ps) {
    94     public static void print(PrintStream ps) {
    90         boolean isHeadless = false;
    95         boolean isHeadless = false;
    91 
    96 
    92         /* Report that we're running headless if the property is true */
    97         /* Report that we're running headless if the property is true */
    93 	String headless = System.getProperty("java.awt.headless");
    98         String headless = System.getProperty("java.awt.headless");
    94 	if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
    99         if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
    95             isHeadless = true;
   100             isHeadless = true;
    96 	} 
   101         }
    97 
   102 
    98         /* First line: platform version. */
   103         /* First line: platform version. */
    99         ps.println(launcher_name + " version \"" + java_version + "\"");
   104         ps.println(launcher_name + " version \"" + java_version + "\"");
   100 
   105 
   101         /* Second line: runtime version (ie, libraries). */
   106         /* Second line: runtime version (ie, libraries). */
   102 
   107 
   103 	ps.print(java_runtime_name + " (build " + java_runtime_version);
   108         ps.print(java_runtime_name + " (build " + java_runtime_version);
   104 
   109 
   105 	if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
   110         if (java_profile_name.length() > 0) {
   106 	    // embedded builds report headless state
   111             // profile name
   107 	    ps.print(", headless");
   112             ps.print(", profile " + java_profile_name);
   108 	}
   113         }
   109 	ps.println(')');
   114 
       
   115         if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
       
   116             // embedded builds report headless state
       
   117             ps.print(", headless");
       
   118         }
       
   119         ps.println(')');
   110 
   120 
   111         /* Third line: JVM information. */
   121         /* Third line: JVM information. */
   112         String java_vm_name    = System.getProperty("java.vm.name");
   122         String java_vm_name    = System.getProperty("java.vm.name");
   113         String java_vm_version = System.getProperty("java.vm.version");
   123         String java_vm_version = System.getProperty("java.vm.version");
   114         String java_vm_info    = System.getProperty("java.vm.info");
   124         String java_vm_info    = System.getProperty("java.vm.info");
   330     //
   340     //
   331     // Return false if not available which implies an old VM (Tiger or before).
   341     // Return false if not available which implies an old VM (Tiger or before).
   332     private static native boolean getJvmVersionInfo();
   342     private static native boolean getJvmVersionInfo();
   333     private static native void getJdkVersionInfo();
   343     private static native void getJdkVersionInfo();
   334 
   344 
       
   345     // Possible runtime profiles, ordered from small to large
       
   346     private final static String[] PROFILES = { "compact1", "compact2", "compact3" };
       
   347 
       
   348     /**
       
   349      * Returns the name of the profile that this runtime implements. The empty
       
   350      * string is returned for the full Java Runtime.
       
   351      */
       
   352     public static String profileName() {
       
   353         return java_profile_name;
       
   354     }
       
   355 
       
   356     /**
       
   357      * Indicates if this runtime implements the full Java Runtime.
       
   358      */
       
   359     public static boolean isFullJre() {
       
   360         return java_profile_name.length() == 0;
       
   361     }
       
   362 
       
   363     // cached index of this profile's name in PROFILES (1-based)
       
   364     private static int thisRuntimeIndex;
       
   365 
       
   366     /**
       
   367      * Indicates if this runtime supports the given profile. Profile names are
       
   368      * case sensitive. 
       
   369      *
       
   370      * @return {@code true} if the given profile is supported
       
   371      */
       
   372     public static boolean supportsProfile(String requiredProfile) {
       
   373         int x = thisRuntimeIndex - 1;
       
   374         if (x < 0) {
       
   375             String profile = profileName();
       
   376             if (profile.length() > 0) {
       
   377                 x = 0;
       
   378                 while (x < PROFILES.length) {
       
   379                     if (PROFILES[x].equals(profile))
       
   380                         break;
       
   381                     x++;
       
   382                 }
       
   383                 if (x >= PROFILES.length)
       
   384                     throw new InternalError(profile + " not known to sun.misc.Version");
       
   385 
       
   386                 // okay if another thread has already set it
       
   387                 thisRuntimeIndex = x + 1;
       
   388             }
       
   389             // else we are a full JRE
       
   390         }
       
   391 
       
   392         int y = 0;
       
   393         while (y < PROFILES.length) {
       
   394             if (PROFILES[y].equals(requiredProfile))
       
   395                 break;
       
   396             y++;
       
   397         }
       
   398         if (y >= PROFILES.length) {
       
   399             // profile not found so caller has requested something that is not defined
       
   400             return false;
       
   401         }
       
   402 
       
   403         return x < 0 || x >= y;
       
   404     }
       
   405 
   335 }
   406 }
   336 
   407 
   337 // Help Emacs a little because this file doesn't end in .java.
   408 // Help Emacs a little because this file doesn't end in .java.
   338 //
   409 //
   339 // Local Variables: ***
   410 // Local Variables: ***