1 /*
2 * Copyright (c) 1999, 2013, 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 sun.misc;
27 import java.io.PrintStream;
28
29 public class Version {
30
31
32 private static final String launcher_name =
33 "@@launcher_name@@";
34
35 private static final String java_version =
36 "@@java_version@@";
37
38 private static final String java_runtime_name =
39 "@@java_runtime_name@@";
40
41 private static final String java_runtime_version =
42 "@@java_runtime_version@@";
43
44 static {
45 init();
46 }
47
48 public static void init() {
49 System.setProperty("java.version", java_version);
50 System.setProperty("java.runtime.version", java_runtime_version);
51 System.setProperty("java.runtime.name", java_runtime_name);
52 }
53
54 private static boolean versionsInitialized = false;
55 private static int jvm_major_version = 0;
56 private static int jvm_minor_version = 0;
57 private static int jvm_micro_version = 0;
58 private static int jvm_update_version = 0;
59 private static int jvm_build_number = 0;
60 private static String jvm_special_version = null;
61 private static int jdk_major_version = 0;
62 private static int jdk_minor_version = 0;
63 private static int jdk_micro_version = 0;
64 private static int jdk_update_version = 0;
65 private static int jdk_build_number = 0;
66 private static String jdk_special_version = null;
67
68 /**
69 * In case you were wondering this method is called by java -version.
70 * Sad that it prints to stderr; would be nicer if default printed on
71 * stdout.
72 */
73 public static void print() {
74 print(System.err);
75 }
76
77 /**
78 * This is the same as print except that it adds an extra line-feed
79 * at the end, typically used by the -showversion in the launcher
80 */
81 public static void println() {
82 print(System.err);
83 System.err.println();
129 initVersions();
130 }
131 return jvm_major_version;
132 }
133
134 /**
135 * Returns the minor version of the running JVM if it's 1.6 or newer
136 * or any RE VM build. It will return 0 if it's an internal 1.5 or
137 * 1.4.x build.
138 * @since 1.6
139 */
140 public static synchronized int jvmMinorVersion() {
141 if (!versionsInitialized) {
142 initVersions();
143 }
144 return jvm_minor_version;
145 }
146
147
148 /**
149 * Returns the micro version of the running JVM if it's 1.6 or newer
150 * or any RE VM build. It will return 0 if it's an internal 1.5 or
151 * 1.4.x build.
152 * @since 1.6
153 */
154 public static synchronized int jvmMicroVersion() {
155 if (!versionsInitialized) {
156 initVersions();
157 }
158 return jvm_micro_version;
159 }
160
161 /**
162 * Returns the update release version of the running JVM if it's
163 * a RE build. It will return 0 if it's an internal build.
164 * @since 1.6
165 */
166 public static synchronized int jvmUpdateVersion() {
167 if (!versionsInitialized) {
168 initVersions();
169 }
170 return jvm_update_version;
171 }
172
173 public static synchronized String jvmSpecialVersion() {
174 if (!versionsInitialized) {
175 initVersions();
176 }
177 if (jvm_special_version == null) {
178 jvm_special_version = getJvmSpecialVersion();
200 */
201 public static synchronized int jdkMajorVersion() {
202 if (!versionsInitialized) {
203 initVersions();
204 }
205 return jdk_major_version;
206 }
207
208 /**
209 * Returns the minor version of the running JDK.
210 * @since 1.6
211 */
212 public static synchronized int jdkMinorVersion() {
213 if (!versionsInitialized) {
214 initVersions();
215 }
216 return jdk_minor_version;
217 }
218
219 /**
220 * Returns the micro version of the running JDK.
221 * @since 1.6
222 */
223 public static synchronized int jdkMicroVersion() {
224 if (!versionsInitialized) {
225 initVersions();
226 }
227 return jdk_micro_version;
228 }
229
230 /**
231 * Returns the update release version of the running JDK if it's
232 * a RE build. It will return 0 if it's an internal build.
233 * @since 1.6
234 */
235 public static synchronized int jdkUpdateVersion() {
236 if (!versionsInitialized) {
237 initVersions();
238 }
239 return jdk_update_version;
240 }
241
242 public static synchronized String jdkSpecialVersion() {
243 if (!versionsInitialized) {
244 initVersions();
245 }
246 if (jdk_special_version == null) {
247 jdk_special_version = getJdkSpecialVersion();
264
265 // true if JVM exports the version info including the capabilities
266 private static boolean jvmVersionInfoAvailable;
267 private static synchronized void initVersions() {
268 if (versionsInitialized) {
269 return;
270 }
271 jvmVersionInfoAvailable = getJvmVersionInfo();
272 if (!jvmVersionInfoAvailable) {
273 // parse java.vm.version for older JVM before the
274 // new JVM_GetVersionInfo is added.
275 // valid format of the version string is:
276 // n.n.n[_uu[c]][-<identifer>]-bxx
277 CharSequence cs = System.getProperty("java.vm.version");
278 if (cs.length() >= 5 &&
279 Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
280 Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
281 Character.isDigit(cs.charAt(4))) {
282 jvm_major_version = Character.digit(cs.charAt(0), 10);
283 jvm_minor_version = Character.digit(cs.charAt(2), 10);
284 jvm_micro_version = Character.digit(cs.charAt(4), 10);
285 cs = cs.subSequence(5, cs.length());
286 if (cs.charAt(0) == '_' && cs.length() >= 3 &&
287 Character.isDigit(cs.charAt(1)) &&
288 Character.isDigit(cs.charAt(2))) {
289 int nextChar = 3;
290 try {
291 String uu = cs.subSequence(1, 3).toString();
292 jvm_update_version = Integer.valueOf(uu).intValue();
293 if (cs.length() >= 4) {
294 char c = cs.charAt(3);
295 if (c >= 'a' && c <= 'z') {
296 jvm_special_version = Character.toString(c);
297 nextChar++;
298 }
299 }
300 } catch (NumberFormatException e) {
301 // not conforming to the naming convention
302 return;
303 }
304 cs = cs.subSequence(nextChar, cs.length());
|
1 /*
2 * Copyright (c) 1999, 2015, 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 sun.misc;
27 import java.io.PrintStream;
28
29 public class Version {
30
31
32 private static final String launcher_name =
33 "@@LAUNCHER_NAME@@";
34
35 private static final String java_version =
36 "@@VERSION_SHORT@@";
37
38 private static final String java_runtime_name =
39 "@@RUNTIME_NAME@@";
40
41 private static final String java_runtime_version =
42 "@@VERSION_STRING@@";
43
44 static {
45 init();
46 }
47
48 public static void init() {
49 System.setProperty("java.version", java_version);
50 System.setProperty("java.runtime.version", java_runtime_version);
51 System.setProperty("java.runtime.name", java_runtime_name);
52 }
53
54 private static boolean versionsInitialized = false;
55 private static int jvm_major_version = 0;
56 private static int jvm_minor_version = 0;
57 private static int jvm_security_version = 0;
58 private static int jvm_update_version = 0;
59 private static int jvm_build_number = 0;
60 private static String jvm_special_version = null;
61 private static int jdk_major_version = 0;
62 private static int jdk_minor_version = 0;
63 private static int jdk_security_version = 0;
64 private static int jdk_update_version = 0;
65 private static int jdk_build_number = 0;
66 private static String jdk_special_version = null;
67
68 /**
69 * In case you were wondering this method is called by java -version.
70 * Sad that it prints to stderr; would be nicer if default printed on
71 * stdout.
72 */
73 public static void print() {
74 print(System.err);
75 }
76
77 /**
78 * This is the same as print except that it adds an extra line-feed
79 * at the end, typically used by the -showversion in the launcher
80 */
81 public static void println() {
82 print(System.err);
83 System.err.println();
129 initVersions();
130 }
131 return jvm_major_version;
132 }
133
134 /**
135 * Returns the minor version of the running JVM if it's 1.6 or newer
136 * or any RE VM build. It will return 0 if it's an internal 1.5 or
137 * 1.4.x build.
138 * @since 1.6
139 */
140 public static synchronized int jvmMinorVersion() {
141 if (!versionsInitialized) {
142 initVersions();
143 }
144 return jvm_minor_version;
145 }
146
147
148 /**
149 * Returns the security version of the running JVM if it's 1.6 or newer
150 * or any RE VM build. It will return 0 if it's an internal 1.5 or
151 * 1.4.x build.
152 * @since 1.6
153 */
154 public static synchronized int jvmSecurityVersion() {
155 if (!versionsInitialized) {
156 initVersions();
157 }
158 return jvm_security_version;
159 }
160
161 /**
162 * Returns the update release version of the running JVM if it's
163 * a RE build. It will return 0 if it's an internal build.
164 * @since 1.6
165 */
166 public static synchronized int jvmUpdateVersion() {
167 if (!versionsInitialized) {
168 initVersions();
169 }
170 return jvm_update_version;
171 }
172
173 public static synchronized String jvmSpecialVersion() {
174 if (!versionsInitialized) {
175 initVersions();
176 }
177 if (jvm_special_version == null) {
178 jvm_special_version = getJvmSpecialVersion();
200 */
201 public static synchronized int jdkMajorVersion() {
202 if (!versionsInitialized) {
203 initVersions();
204 }
205 return jdk_major_version;
206 }
207
208 /**
209 * Returns the minor version of the running JDK.
210 * @since 1.6
211 */
212 public static synchronized int jdkMinorVersion() {
213 if (!versionsInitialized) {
214 initVersions();
215 }
216 return jdk_minor_version;
217 }
218
219 /**
220 * Returns the security version of the running JDK.
221 * @since 1.6
222 */
223 public static synchronized int jdkSecurityVersion() {
224 if (!versionsInitialized) {
225 initVersions();
226 }
227 return jdk_security_version;
228 }
229
230 /**
231 * Returns the update release version of the running JDK if it's
232 * a RE build. It will return 0 if it's an internal build.
233 * @since 1.6
234 */
235 public static synchronized int jdkUpdateVersion() {
236 if (!versionsInitialized) {
237 initVersions();
238 }
239 return jdk_update_version;
240 }
241
242 public static synchronized String jdkSpecialVersion() {
243 if (!versionsInitialized) {
244 initVersions();
245 }
246 if (jdk_special_version == null) {
247 jdk_special_version = getJdkSpecialVersion();
264
265 // true if JVM exports the version info including the capabilities
266 private static boolean jvmVersionInfoAvailable;
267 private static synchronized void initVersions() {
268 if (versionsInitialized) {
269 return;
270 }
271 jvmVersionInfoAvailable = getJvmVersionInfo();
272 if (!jvmVersionInfoAvailable) {
273 // parse java.vm.version for older JVM before the
274 // new JVM_GetVersionInfo is added.
275 // valid format of the version string is:
276 // n.n.n[_uu[c]][-<identifer>]-bxx
277 CharSequence cs = System.getProperty("java.vm.version");
278 if (cs.length() >= 5 &&
279 Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
280 Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
281 Character.isDigit(cs.charAt(4))) {
282 jvm_major_version = Character.digit(cs.charAt(0), 10);
283 jvm_minor_version = Character.digit(cs.charAt(2), 10);
284 jvm_security_version = Character.digit(cs.charAt(4), 10);
285 cs = cs.subSequence(5, cs.length());
286 if (cs.charAt(0) == '_' && cs.length() >= 3 &&
287 Character.isDigit(cs.charAt(1)) &&
288 Character.isDigit(cs.charAt(2))) {
289 int nextChar = 3;
290 try {
291 String uu = cs.subSequence(1, 3).toString();
292 jvm_update_version = Integer.valueOf(uu).intValue();
293 if (cs.length() >= 4) {
294 char c = cs.charAt(3);
295 if (c >= 'a' && c <= 'z') {
296 jvm_special_version = Character.toString(c);
297 nextChar++;
298 }
299 }
300 } catch (NumberFormatException e) {
301 // not conforming to the naming convention
302 return;
303 }
304 cs = cs.subSequence(nextChar, cs.length());
|