jdk/src/java.base/share/classes/java/lang/VersionProps.java.template
author amurillo
Fri, 22 Apr 2016 01:04:01 -0700
changeset 38339 65b26013c786
parent 36225 6ae0eebc46e9
child 39302 aa8d0bc2a6d2
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36225
6ae0eebc46e9 8150162: Move sun.misc.Version to a truly internal package
chegar
parents: 34011
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
36225
6ae0eebc46e9 8150162: Move sun.misc.Version to a truly internal package
chegar
parents: 34011
diff changeset
    26
package java.lang;
6ae0eebc46e9 8150162: Move sun.misc.Version to a truly internal package
chegar
parents: 34011
diff changeset
    27
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
36225
6ae0eebc46e9 8150162: Move sun.misc.Version to a truly internal package
chegar
parents: 34011
diff changeset
    30
class VersionProps {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private static final String launcher_name =
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 27565
diff changeset
    34
        "@@LAUNCHER_NAME@@";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static final String java_version =
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 27565
diff changeset
    37
        "@@VERSION_SHORT@@";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static final String java_runtime_name =
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 27565
diff changeset
    40
        "@@RUNTIME_NAME@@";
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final String java_runtime_version =
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 27565
diff changeset
    43
        "@@VERSION_STRING@@";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        System.setProperty("java.version", java_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        System.setProperty("java.runtime.version", java_runtime_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        System.setProperty("java.runtime.name", java_runtime_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * In case you were wondering this method is called by java -version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Sad that it prints to stderr; would be nicer if default printed on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * stdout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static void print() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        print(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * This is the same as print except that it adds an extra line-feed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * at the end, typically used by the -showversion in the launcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static void println() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        print(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Give a stream, it will print version info on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static void print(PrintStream ps) {
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    77
        boolean isHeadless = false;
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    78
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    79
        /* Report that we're running headless if the property is true */
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    80
        String headless = System.getProperty("java.awt.headless");
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    81
        if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    82
            isHeadless = true;
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    83
        }
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    84
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        /* First line: platform version. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        ps.println(launcher_name + " version \"" + java_version + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        /* Second line: runtime version (ie, libraries). */
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    89
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    90
        String jdk_debug_level = System.getProperty("jdk.debug", "release");
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    91
        /* Debug level is not printed for "release" builds */
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    92
        if ("release".equals(jdk_debug_level)) {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    93
            jdk_debug_level = "";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    94
        } else {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    95
            jdk_debug_level = jdk_debug_level + " ";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    96
        }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    97
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
    98
        ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    99
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   100
        if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   101
            // embedded builds report headless state
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   102
            ps.print(", headless");
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   103
        }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   104
        ps.println(')');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /* Third line: JVM information. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        String java_vm_name    = System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        String java_vm_version = System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        String java_vm_info    = System.getProperty("java.vm.info");
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 34003
diff changeset
   110
        ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                   java_vm_info + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
36225
6ae0eebc46e9 8150162: Move sun.misc.Version to a truly internal package
chegar
parents: 34011
diff changeset
   114
}