jdk/src/java.base/share/classes/java/lang/VersionProps.java.template
changeset 36225 6ae0eebc46e9
parent 34011 b1ce08dd7f17
child 39302 aa8d0bc2a6d2
equal deleted inserted replaced
36224:6a0a5bdfe79f 36225:6ae0eebc46e9
       
     1 /*
       
     2  * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     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
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package java.lang;
       
    27 
       
    28 import java.io.PrintStream;
       
    29 
       
    30 class VersionProps {
       
    31 
       
    32 
       
    33     private static final String launcher_name =
       
    34         "@@LAUNCHER_NAME@@";
       
    35 
       
    36     private static final String java_version =
       
    37         "@@VERSION_SHORT@@";
       
    38 
       
    39     private static final String java_runtime_name =
       
    40         "@@RUNTIME_NAME@@";
       
    41 
       
    42     private static final String java_runtime_version =
       
    43         "@@VERSION_STRING@@";
       
    44 
       
    45     static {
       
    46         init();
       
    47     }
       
    48 
       
    49     public static void init() {
       
    50         System.setProperty("java.version", java_version);
       
    51         System.setProperty("java.runtime.version", java_runtime_version);
       
    52         System.setProperty("java.runtime.name", java_runtime_name);
       
    53     }
       
    54 
       
    55     /**
       
    56      * In case you were wondering this method is called by java -version.
       
    57      * Sad that it prints to stderr; would be nicer if default printed on
       
    58      * stdout.
       
    59      */
       
    60     public static void print() {
       
    61         print(System.err);
       
    62     }
       
    63 
       
    64     /**
       
    65      * This is the same as print except that it adds an extra line-feed
       
    66      * at the end, typically used by the -showversion in the launcher
       
    67      */
       
    68     public static void println() {
       
    69         print(System.err);
       
    70         System.err.println();
       
    71     }
       
    72 
       
    73     /**
       
    74      * Give a stream, it will print version info on it.
       
    75      */
       
    76     public static void print(PrintStream ps) {
       
    77         boolean isHeadless = false;
       
    78 
       
    79         /* Report that we're running headless if the property is true */
       
    80         String headless = System.getProperty("java.awt.headless");
       
    81         if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
       
    82             isHeadless = true;
       
    83         }
       
    84 
       
    85         /* First line: platform version. */
       
    86         ps.println(launcher_name + " version \"" + java_version + "\"");
       
    87 
       
    88         /* Second line: runtime version (ie, libraries). */
       
    89 
       
    90         String jdk_debug_level = System.getProperty("jdk.debug", "release");
       
    91         /* Debug level is not printed for "release" builds */
       
    92         if ("release".equals(jdk_debug_level)) {
       
    93             jdk_debug_level = "";
       
    94         } else {
       
    95             jdk_debug_level = jdk_debug_level + " ";
       
    96         }
       
    97 
       
    98         ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
       
    99 
       
   100         if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
       
   101             // embedded builds report headless state
       
   102             ps.print(", headless");
       
   103         }
       
   104         ps.println(')');
       
   105 
       
   106         /* Third line: JVM information. */
       
   107         String java_vm_name    = System.getProperty("java.vm.name");
       
   108         String java_vm_version = System.getProperty("java.vm.version");
       
   109         String java_vm_info    = System.getProperty("java.vm.info");
       
   110         ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
       
   111                    java_vm_info + ")");
       
   112     }
       
   113 
       
   114 }