1 /*
2 * Copyright (c) 1999, 2011, 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.
85
86 /**
87 * Give a stream, it will print version info on it.
88 */
89 public static void print(PrintStream ps) {
90 boolean isHeadless = false;
91
92 /* Report that we're running headless if the property is true */
93 String headless = System.getProperty("java.awt.headless");
94 if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
95 isHeadless = true;
96 }
97
98 /* First line: platform version. */
99 ps.println(launcher_name + " version \"" + java_version + "\"");
100
101 /* Second line: runtime version (ie, libraries). */
102
103 ps.print(java_runtime_name + " (build " + java_runtime_version);
104
105 if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
106 // embedded builds report headless state
107 ps.print(", headless");
108 }
109 ps.println(')');
110
111 /* Third line: JVM information. */
112 String java_vm_name = System.getProperty("java.vm.name");
113 String java_vm_version = System.getProperty("java.vm.version");
114 String java_vm_info = System.getProperty("java.vm.info");
115 ps.println(java_vm_name + " (build " + java_vm_version + ", " +
116 java_vm_info + ")");
117 }
118
119
120 /**
121 * Returns the major version of the running JVM if it's 1.6 or newer
122 * or any RE VM build. It will return 0 if it's an internal 1.5 or
123 * 1.4.x build.
124 *
314 Character.isDigit(s.charAt(1)) &&
315 Character.isDigit(s.charAt(2))) {
316 jvm_build_number =
317 Integer.valueOf(s.substring(1, 3)).intValue();
318 break;
319 }
320 }
321 }
322 }
323 }
324 getJdkVersionInfo();
325 versionsInitialized = true;
326 }
327
328 // Gets the JVM version info if available and sets the jvm_*_version fields
329 // and its capabilities.
330 //
331 // Return false if not available which implies an old VM (Tiger or before).
332 private static native boolean getJvmVersionInfo();
333 private static native void getJdkVersionInfo();
334
335 }
336
337 // Help Emacs a little because this file doesn't end in .java.
338 //
339 // Local Variables: ***
340 // mode: java ***
341 // End: ***
|
1 /*
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.
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_profile_name =
42 "@@java_profile_name@@";
43
44 private static final String java_runtime_version =
45 "@@java_runtime_version@@";
46
47 static {
48 init();
49 }
50
51 public static void init() {
52 System.setProperty("java.version", java_version);
53 System.setProperty("java.runtime.version", java_runtime_version);
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);
57 }
58
59 private static boolean versionsInitialized = false;
60 private static int jvm_major_version = 0;
61 private static int jvm_minor_version = 0;
62 private static int jvm_micro_version = 0;
63 private static int jvm_update_version = 0;
64 private static int jvm_build_number = 0;
65 private static String jvm_special_version = null;
66 private static int jdk_major_version = 0;
67 private static int jdk_minor_version = 0;
68 private static int jdk_micro_version = 0;
69 private static int jdk_update_version = 0;
70 private static int jdk_build_number = 0;
71 private static String jdk_special_version = null;
72
73 /**
74 * In case you were wondering this method is called by java -version.
75 * Sad that it prints to stderr; would be nicer if default printed on
76 * stdout.
90
91 /**
92 * Give a stream, it will print version info on it.
93 */
94 public static void print(PrintStream ps) {
95 boolean isHeadless = false;
96
97 /* Report that we're running headless if the property is true */
98 String headless = System.getProperty("java.awt.headless");
99 if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
100 isHeadless = true;
101 }
102
103 /* First line: platform version. */
104 ps.println(launcher_name + " version \"" + java_version + "\"");
105
106 /* Second line: runtime version (ie, libraries). */
107
108 ps.print(java_runtime_name + " (build " + java_runtime_version);
109
110 if (java_profile_name.length() > 0) {
111 // profile name
112 ps.print(", profile " + java_profile_name);
113 }
114
115 if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
116 // embedded builds report headless state
117 ps.print(", headless");
118 }
119 ps.println(')');
120
121 /* Third line: JVM information. */
122 String java_vm_name = System.getProperty("java.vm.name");
123 String java_vm_version = System.getProperty("java.vm.version");
124 String java_vm_info = System.getProperty("java.vm.info");
125 ps.println(java_vm_name + " (build " + java_vm_version + ", " +
126 java_vm_info + ")");
127 }
128
129
130 /**
131 * Returns the major version of the running JVM if it's 1.6 or newer
132 * or any RE VM build. It will return 0 if it's an internal 1.5 or
133 * 1.4.x build.
134 *
324 Character.isDigit(s.charAt(1)) &&
325 Character.isDigit(s.charAt(2))) {
326 jvm_build_number =
327 Integer.valueOf(s.substring(1, 3)).intValue();
328 break;
329 }
330 }
331 }
332 }
333 }
334 getJdkVersionInfo();
335 versionsInitialized = true;
336 }
337
338 // Gets the JVM version info if available and sets the jvm_*_version fields
339 // and its capabilities.
340 //
341 // Return false if not available which implies an old VM (Tiger or before).
342 private static native boolean getJvmVersionInfo();
343 private static native void getJdkVersionInfo();
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
364 private static int thisRuntimeIndex = -1;
365
366 /**
367 * Indicates if this runtime supports the given profile. Profile names are
368 * compared without regard to case. Returns {@code false} if the given profile
369 * name is not a supported profile.
370 */
371 public static boolean supportsProfile(String requiredProfile) {
372 int x = thisRuntimeIndex;
373 if (x < 0) {
374 String profile = profileName();
375 if (profile.length() > 0) {
376 x = 0;
377 while (x < PROFILES.length) {
378 if (PROFILES[x].equalsIgnoreCase(profile))
379 break;
380 x++;
381 }
382 if (x >= PROFILES.length)
383 throw new InternalError(profile + " not known to sun.misc.Version");
384
385 // okay if another thread has already set it
386 thisRuntimeIndex = x;
387 }
388 // else we are a full JRE
389 }
390
391 int y = 0;
392 while (y < PROFILES.length) {
393 if (PROFILES[y].equalsIgnoreCase(requiredProfile))
394 break;
395 y++;
396 }
397 if (y >= PROFILES.length) {
398 // profile not found so caller has requested something that is not defined
399 return false;
400 }
401
402 return x < 0 || x >= y;
403 }
404
405 }
406
407 // Help Emacs a little because this file doesn't end in .java.
408 //
409 // Local Variables: ***
410 // mode: java ***
411 // End: ***
|