author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 23010 | jdk/src/share/classes/sun/misc/Version.java.template@6dadb192ad81 |
child 27565 | 729f9700483a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
19409
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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 = |
|
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
39 |
"@@java_runtime_name@@"; |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
40 |
|
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
41 |
private static final String java_profile_name = |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
42 |
"@@java_profile_name@@"; |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
43 |
|
2 | 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 |
} |
|
56 |
||
57 |
private static boolean versionsInitialized = false; |
|
58 |
private static int jvm_major_version = 0; |
|
59 |
private static int jvm_minor_version = 0; |
|
60 |
private static int jvm_micro_version = 0; |
|
61 |
private static int jvm_update_version = 0; |
|
62 |
private static int jvm_build_number = 0; |
|
63 |
private static String jvm_special_version = null; |
|
64 |
private static int jdk_major_version = 0; |
|
65 |
private static int jdk_minor_version = 0; |
|
66 |
private static int jdk_micro_version = 0; |
|
67 |
private static int jdk_update_version = 0; |
|
68 |
private static int jdk_build_number = 0; |
|
69 |
private static String jdk_special_version = null; |
|
70 |
||
71 |
/** |
|
72 |
* In case you were wondering this method is called by java -version. |
|
73 |
* Sad that it prints to stderr; would be nicer if default printed on |
|
74 |
* stdout. |
|
75 |
*/ |
|
76 |
public static void print() { |
|
77 |
print(System.err); |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* This is the same as print except that it adds an extra line-feed |
|
82 |
* at the end, typically used by the -showversion in the launcher |
|
83 |
*/ |
|
84 |
public static void println() { |
|
85 |
print(System.err); |
|
86 |
System.err.println(); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Give a stream, it will print version info on it. |
|
91 |
*/ |
|
92 |
public static void print(PrintStream ps) { |
|
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
93 |
boolean isHeadless = false; |
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
94 |
|
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
95 |
/* 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
|
96 |
String headless = System.getProperty("java.awt.headless"); |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
97 |
if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) { |
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
98 |
isHeadless = true; |
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
99 |
} |
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
100 |
|
2 | 101 |
/* First line: platform version. */ |
102 |
ps.println(launcher_name + " version \"" + java_version + "\""); |
|
103 |
||
104 |
/* Second line: runtime version (ie, libraries). */ |
|
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
105 |
|
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
106 |
ps.print(java_runtime_name + " (build " + java_runtime_version); |
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
107 |
|
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
108 |
if (java_profile_name.length() > 0) { |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
109 |
// profile name |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
110 |
ps.print(", profile " + java_profile_name); |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
111 |
} |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
112 |
|
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
113 |
if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) { |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
114 |
// embedded builds report headless state |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
115 |
ps.print(", headless"); |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
116 |
} |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
117 |
ps.println(')'); |
2 | 118 |
|
119 |
/* Third line: JVM information. */ |
|
120 |
String java_vm_name = System.getProperty("java.vm.name"); |
|
121 |
String java_vm_version = System.getProperty("java.vm.version"); |
|
122 |
String java_vm_info = System.getProperty("java.vm.info"); |
|
123 |
ps.println(java_vm_name + " (build " + java_vm_version + ", " + |
|
124 |
java_vm_info + ")"); |
|
125 |
} |
|
126 |
||
127 |
||
128 |
/** |
|
129 |
* Returns the major version of the running JVM if it's 1.6 or newer |
|
130 |
* or any RE VM build. It will return 0 if it's an internal 1.5 or |
|
131 |
* 1.4.x build. |
|
132 |
* |
|
133 |
* @since 1.6 |
|
134 |
*/ |
|
135 |
public static synchronized int jvmMajorVersion() { |
|
136 |
if (!versionsInitialized) { |
|
137 |
initVersions(); |
|
138 |
} |
|
139 |
return jvm_major_version; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Returns the minor version of the running JVM if it's 1.6 or newer |
|
144 |
* or any RE VM build. It will return 0 if it's an internal 1.5 or |
|
145 |
* 1.4.x build. |
|
146 |
* @since 1.6 |
|
147 |
*/ |
|
148 |
public static synchronized int jvmMinorVersion() { |
|
149 |
if (!versionsInitialized) { |
|
150 |
initVersions(); |
|
151 |
} |
|
152 |
return jvm_minor_version; |
|
153 |
} |
|
154 |
||
155 |
||
156 |
/** |
|
157 |
* Returns the micro version of the running JVM if it's 1.6 or newer |
|
158 |
* or any RE VM build. It will return 0 if it's an internal 1.5 or |
|
159 |
* 1.4.x build. |
|
160 |
* @since 1.6 |
|
161 |
*/ |
|
162 |
public static synchronized int jvmMicroVersion() { |
|
163 |
if (!versionsInitialized) { |
|
164 |
initVersions(); |
|
165 |
} |
|
166 |
return jvm_micro_version; |
|
167 |
} |
|
168 |
||
169 |
/** |
|
170 |
* Returns the update release version of the running JVM if it's |
|
171 |
* a RE build. It will return 0 if it's an internal build. |
|
172 |
* @since 1.6 |
|
173 |
*/ |
|
174 |
public static synchronized int jvmUpdateVersion() { |
|
175 |
if (!versionsInitialized) { |
|
176 |
initVersions(); |
|
177 |
} |
|
178 |
return jvm_update_version; |
|
179 |
} |
|
180 |
||
181 |
public static synchronized String jvmSpecialVersion() { |
|
182 |
if (!versionsInitialized) { |
|
183 |
initVersions(); |
|
184 |
} |
|
185 |
if (jvm_special_version == null) { |
|
186 |
jvm_special_version = getJvmSpecialVersion(); |
|
187 |
} |
|
188 |
return jvm_special_version; |
|
189 |
} |
|
190 |
public static native String getJvmSpecialVersion(); |
|
191 |
||
192 |
/** |
|
193 |
* Returns the build number of the running JVM if it's a RE build |
|
194 |
* It will return 0 if it's an internal build. |
|
195 |
* @since 1.6 |
|
196 |
*/ |
|
197 |
public static synchronized int jvmBuildNumber() { |
|
198 |
if (!versionsInitialized) { |
|
199 |
initVersions(); |
|
200 |
} |
|
201 |
return jvm_build_number; |
|
202 |
} |
|
203 |
||
204 |
/** |
|
205 |
* Returns the major version of the running JDK. |
|
206 |
* |
|
207 |
* @since 1.6 |
|
208 |
*/ |
|
209 |
public static synchronized int jdkMajorVersion() { |
|
210 |
if (!versionsInitialized) { |
|
211 |
initVersions(); |
|
212 |
} |
|
213 |
return jdk_major_version; |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Returns the minor version of the running JDK. |
|
218 |
* @since 1.6 |
|
219 |
*/ |
|
220 |
public static synchronized int jdkMinorVersion() { |
|
221 |
if (!versionsInitialized) { |
|
222 |
initVersions(); |
|
223 |
} |
|
224 |
return jdk_minor_version; |
|
225 |
} |
|
226 |
||
227 |
/** |
|
228 |
* Returns the micro version of the running JDK. |
|
229 |
* @since 1.6 |
|
230 |
*/ |
|
231 |
public static synchronized int jdkMicroVersion() { |
|
232 |
if (!versionsInitialized) { |
|
233 |
initVersions(); |
|
234 |
} |
|
235 |
return jdk_micro_version; |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Returns the update release version of the running JDK if it's |
|
240 |
* a RE build. It will return 0 if it's an internal build. |
|
241 |
* @since 1.6 |
|
242 |
*/ |
|
243 |
public static synchronized int jdkUpdateVersion() { |
|
244 |
if (!versionsInitialized) { |
|
245 |
initVersions(); |
|
246 |
} |
|
247 |
return jdk_update_version; |
|
248 |
} |
|
249 |
||
250 |
public static synchronized String jdkSpecialVersion() { |
|
251 |
if (!versionsInitialized) { |
|
252 |
initVersions(); |
|
253 |
} |
|
254 |
if (jdk_special_version == null) { |
|
255 |
jdk_special_version = getJdkSpecialVersion(); |
|
256 |
} |
|
257 |
return jdk_special_version; |
|
258 |
} |
|
259 |
public static native String getJdkSpecialVersion(); |
|
260 |
||
261 |
/** |
|
262 |
* Returns the build number of the running JDK if it's a RE build |
|
263 |
* It will return 0 if it's an internal build. |
|
264 |
* @since 1.6 |
|
265 |
*/ |
|
266 |
public static synchronized int jdkBuildNumber() { |
|
267 |
if (!versionsInitialized) { |
|
268 |
initVersions(); |
|
269 |
} |
|
270 |
return jdk_build_number; |
|
271 |
} |
|
272 |
||
273 |
// true if JVM exports the version info including the capabilities |
|
274 |
private static boolean jvmVersionInfoAvailable; |
|
275 |
private static synchronized void initVersions() { |
|
276 |
if (versionsInitialized) { |
|
277 |
return; |
|
278 |
} |
|
279 |
jvmVersionInfoAvailable = getJvmVersionInfo(); |
|
280 |
if (!jvmVersionInfoAvailable) { |
|
281 |
// parse java.vm.version for older JVM before the |
|
282 |
// new JVM_GetVersionInfo is added. |
|
283 |
// valid format of the version string is: |
|
284 |
// n.n.n[_uu[c]][-<identifer>]-bxx |
|
285 |
CharSequence cs = System.getProperty("java.vm.version"); |
|
286 |
if (cs.length() >= 5 && |
|
287 |
Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' && |
|
288 |
Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' && |
|
289 |
Character.isDigit(cs.charAt(4))) { |
|
290 |
jvm_major_version = Character.digit(cs.charAt(0), 10); |
|
291 |
jvm_minor_version = Character.digit(cs.charAt(2), 10); |
|
292 |
jvm_micro_version = Character.digit(cs.charAt(4), 10); |
|
293 |
cs = cs.subSequence(5, cs.length()); |
|
294 |
if (cs.charAt(0) == '_' && cs.length() >= 3 && |
|
295 |
Character.isDigit(cs.charAt(1)) && |
|
296 |
Character.isDigit(cs.charAt(2))) { |
|
297 |
int nextChar = 3; |
|
298 |
try { |
|
299 |
String uu = cs.subSequence(1, 3).toString(); |
|
300 |
jvm_update_version = Integer.valueOf(uu).intValue(); |
|
301 |
if (cs.length() >= 4) { |
|
302 |
char c = cs.charAt(3); |
|
303 |
if (c >= 'a' && c <= 'z') { |
|
304 |
jvm_special_version = Character.toString(c); |
|
305 |
nextChar++; |
|
306 |
} |
|
307 |
} |
|
308 |
} catch (NumberFormatException e) { |
|
309 |
// not conforming to the naming convention |
|
310 |
return; |
|
311 |
} |
|
312 |
cs = cs.subSequence(nextChar, cs.length()); |
|
313 |
} |
|
314 |
if (cs.charAt(0) == '-') { |
|
315 |
// skip the first character |
|
316 |
// valid format: <identifier>-bxx or bxx |
|
317 |
// non-product VM will have -debug|-release appended |
|
318 |
cs = cs.subSequence(1, cs.length()); |
|
319 |
String[] res = cs.toString().split("-"); |
|
320 |
for (String s : res) { |
|
321 |
if (s.charAt(0) == 'b' && s.length() == 3 && |
|
322 |
Character.isDigit(s.charAt(1)) && |
|
323 |
Character.isDigit(s.charAt(2))) { |
|
324 |
jvm_build_number = |
|
325 |
Integer.valueOf(s.substring(1, 3)).intValue(); |
|
326 |
break; |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
} |
|
332 |
getJdkVersionInfo(); |
|
333 |
versionsInitialized = true; |
|
334 |
} |
|
335 |
||
336 |
// Gets the JVM version info if available and sets the jvm_*_version fields |
|
337 |
// and its capabilities. |
|
338 |
// |
|
339 |
// Return false if not available which implies an old VM (Tiger or before). |
|
340 |
private static native boolean getJvmVersionInfo(); |
|
341 |
private static native void getJdkVersionInfo(); |
|
342 |
} |
|
343 |
||
344 |
// Help Emacs a little because this file doesn't end in .java. |
|
345 |
// |
|
346 |
// Local Variables: *** |
|
347 |
// mode: java *** |
|
348 |
// End: *** |