annotate src/java.base/share/classes/sun/misc/Version.java.template @ 13184:60387e5d6822

8087202: Add support for PATCH field and remove unused fields of new version string Reviewed-by: dholmes, alanb
author amurillo
date Fri, 19 Jun 2015 10:58:00 -0700
parents 474db9ef5ee7
children 9cea16b048db
rev   line source
duke@0 1 /*
ihse@13182 2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 package sun.misc;
duke@0 27 import java.io.PrintStream;
duke@0 28
duke@0 29 public class Version {
duke@0 30
duke@0 31
duke@0 32 private static final String launcher_name =
ihse@13182 33 "@@LAUNCHER_NAME@@";
duke@0 34
duke@0 35 private static final String java_version =
ihse@13182 36 "@@VERSION_SHORT@@";
duke@0 37
duke@0 38 private static final String java_runtime_name =
ihse@13182 39 "@@RUNTIME_NAME@@";
alanb@6573 40
duke@0 41 private static final String java_runtime_version =
ihse@13182 42 "@@VERSION_STRING@@";
duke@0 43
duke@0 44 static {
duke@0 45 init();
duke@0 46 }
duke@0 47
duke@0 48 public static void init() {
duke@0 49 System.setProperty("java.version", java_version);
duke@0 50 System.setProperty("java.runtime.version", java_runtime_version);
duke@0 51 System.setProperty("java.runtime.name", java_runtime_name);
duke@0 52 }
duke@0 53
duke@0 54 private static boolean versionsInitialized = false;
duke@0 55 private static int jvm_major_version = 0;
duke@0 56 private static int jvm_minor_version = 0;
ihse@13182 57 private static int jvm_security_version = 0;
amurillo@13184 58 private static int jvm_patch_version = 0;
duke@0 59 private static int jvm_build_number = 0;
duke@0 60 private static int jdk_major_version = 0;
duke@0 61 private static int jdk_minor_version = 0;
ihse@13182 62 private static int jdk_security_version = 0;
amurillo@13184 63 private static int jdk_patch_version = 0;
duke@0 64 private static int jdk_build_number = 0;
duke@0 65
duke@0 66 /**
duke@0 67 * In case you were wondering this method is called by java -version.
duke@0 68 * Sad that it prints to stderr; would be nicer if default printed on
duke@0 69 * stdout.
duke@0 70 */
duke@0 71 public static void print() {
duke@0 72 print(System.err);
duke@0 73 }
duke@0 74
duke@0 75 /**
duke@0 76 * This is the same as print except that it adds an extra line-feed
duke@0 77 * at the end, typically used by the -showversion in the launcher
duke@0 78 */
duke@0 79 public static void println() {
duke@0 80 print(System.err);
duke@0 81 System.err.println();
duke@0 82 }
duke@0 83
duke@0 84 /**
duke@0 85 * Give a stream, it will print version info on it.
duke@0 86 */
duke@0 87 public static void print(PrintStream ps) {
dholmes@3867 88 boolean isHeadless = false;
dholmes@3867 89
dholmes@3867 90 /* Report that we're running headless if the property is true */
alanb@6573 91 String headless = System.getProperty("java.awt.headless");
alanb@6573 92 if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
dholmes@3867 93 isHeadless = true;
alanb@6573 94 }
dholmes@3867 95
duke@0 96 /* First line: platform version. */
duke@0 97 ps.println(launcher_name + " version \"" + java_version + "\"");
duke@0 98
duke@0 99 /* Second line: runtime version (ie, libraries). */
dholmes@3867 100
alanb@6573 101 ps.print(java_runtime_name + " (build " + java_runtime_version);
dholmes@3867 102
alanb@6573 103 if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
alanb@6573 104 // embedded builds report headless state
alanb@6573 105 ps.print(", headless");
alanb@6573 106 }
alanb@6573 107 ps.println(')');
duke@0 108
duke@0 109 /* Third line: JVM information. */
duke@0 110 String java_vm_name = System.getProperty("java.vm.name");
duke@0 111 String java_vm_version = System.getProperty("java.vm.version");
duke@0 112 String java_vm_info = System.getProperty("java.vm.info");
duke@0 113 ps.println(java_vm_name + " (build " + java_vm_version + ", " +
duke@0 114 java_vm_info + ")");
duke@0 115 }
duke@0 116
duke@0 117
duke@0 118 /**
duke@0 119 * Returns the major version of the running JVM if it's 1.6 or newer
duke@0 120 * or any RE VM build. It will return 0 if it's an internal 1.5 or
duke@0 121 * 1.4.x build.
duke@0 122 *
duke@0 123 * @since 1.6
duke@0 124 */
duke@0 125 public static synchronized int jvmMajorVersion() {
duke@0 126 if (!versionsInitialized) {
duke@0 127 initVersions();
duke@0 128 }
duke@0 129 return jvm_major_version;
duke@0 130 }
duke@0 131
duke@0 132 /**
duke@0 133 * Returns the minor version of the running JVM if it's 1.6 or newer
duke@0 134 * or any RE VM build. It will return 0 if it's an internal 1.5 or
duke@0 135 * 1.4.x build.
duke@0 136 * @since 1.6
duke@0 137 */
duke@0 138 public static synchronized int jvmMinorVersion() {
duke@0 139 if (!versionsInitialized) {
duke@0 140 initVersions();
duke@0 141 }
duke@0 142 return jvm_minor_version;
duke@0 143 }
duke@0 144
duke@0 145
duke@0 146 /**
amurillo@13184 147 * Returns the security version of the running JVM
duke@0 148 * @since 1.6
duke@0 149 */
ihse@13182 150 public static synchronized int jvmSecurityVersion() {
duke@0 151 if (!versionsInitialized) {
duke@0 152 initVersions();
duke@0 153 }
ihse@13182 154 return jvm_security_version;
duke@0 155 }
duke@0 156
duke@0 157 /**
amurillo@13184 158 * Returns the patch release version of the running JVM
amurillo@13184 159 * @since JDK9
duke@0 160 */
amurillo@13184 161 public static synchronized int jvmPatchVersion() {
duke@0 162 if (!versionsInitialized) {
duke@0 163 initVersions();
duke@0 164 }
amurillo@13184 165 return jvm_patch_version;
duke@0 166 }
duke@0 167
duke@0 168 /**
amurillo@13184 169 * Returns the build number of the running JVM
duke@0 170 * @since 1.6
duke@0 171 */
duke@0 172 public static synchronized int jvmBuildNumber() {
duke@0 173 if (!versionsInitialized) {
duke@0 174 initVersions();
duke@0 175 }
duke@0 176 return jvm_build_number;
duke@0 177 }
duke@0 178
duke@0 179 /**
duke@0 180 * Returns the major version of the running JDK.
duke@0 181 *
duke@0 182 * @since 1.6
duke@0 183 */
duke@0 184 public static synchronized int jdkMajorVersion() {
duke@0 185 if (!versionsInitialized) {
duke@0 186 initVersions();
duke@0 187 }
duke@0 188 return jdk_major_version;
duke@0 189 }
duke@0 190
duke@0 191 /**
duke@0 192 * Returns the minor version of the running JDK.
duke@0 193 * @since 1.6
duke@0 194 */
duke@0 195 public static synchronized int jdkMinorVersion() {
duke@0 196 if (!versionsInitialized) {
duke@0 197 initVersions();
duke@0 198 }
duke@0 199 return jdk_minor_version;
duke@0 200 }
duke@0 201
duke@0 202 /**
ihse@13182 203 * Returns the security version of the running JDK.
duke@0 204 * @since 1.6
duke@0 205 */
ihse@13182 206 public static synchronized int jdkSecurityVersion() {
duke@0 207 if (!versionsInitialized) {
duke@0 208 initVersions();
duke@0 209 }
ihse@13182 210 return jdk_security_version;
duke@0 211 }
duke@0 212
duke@0 213 /**
amurillo@13184 214 * Returns the patch release version of the running JDK
amurillo@13184 215 * @since 9
duke@0 216 */
amurillo@13184 217 public static synchronized int jdkPatchVersion() {
duke@0 218 if (!versionsInitialized) {
duke@0 219 initVersions();
duke@0 220 }
amurillo@13184 221 return jdk_patch_version;
duke@0 222 }
duke@0 223
duke@0 224 /**
amurillo@13184 225 * Returns the build number of the running JDK
duke@0 226 * @since 1.6
duke@0 227 */
duke@0 228 public static synchronized int jdkBuildNumber() {
duke@0 229 if (!versionsInitialized) {
duke@0 230 initVersions();
duke@0 231 }
duke@0 232 return jdk_build_number;
duke@0 233 }
duke@0 234
duke@0 235 private static synchronized void initVersions() {
duke@0 236 if (versionsInitialized) {
duke@0 237 return;
duke@0 238 }
amurillo@13184 239 if (!getJvmVersionInfo()) {
amurillo@13184 240 throw new InternalError("Unable to obtain JVM version info");
duke@0 241 }
duke@0 242 getJdkVersionInfo();
duke@0 243 versionsInitialized = true;
duke@0 244 }
duke@0 245
duke@0 246 // Gets the JVM version info if available and sets the jvm_*_version fields
duke@0 247 // and its capabilities.
duke@0 248 private static native boolean getJvmVersionInfo();
duke@0 249 private static native void getJdkVersionInfo();
duke@0 250 }
duke@0 251
duke@0 252 // Help Emacs a little because this file doesn't end in .java.
duke@0 253 //
duke@0 254 // Local Variables: ***
duke@0 255 // mode: java ***
duke@0 256 // End: ***