author | redestad |
Tue, 28 Jun 2016 00:39:26 +0200 | |
changeset 39302 | aa8d0bc2a6d2 |
parent 36225 | 6ae0eebc46e9 |
child 39314 | 779f1d11a746 |
permissions | -rw-r--r-- |
2 | 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 | 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 |
||
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 | 28 |
import java.io.PrintStream; |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
29 |
import java.util.ArrayList; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
30 |
import java.util.List; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
31 |
import java.util.Optional; |
2 | 32 |
|
36225
6ae0eebc46e9
8150162: Move sun.misc.Version to a truly internal package
chegar
parents:
34011
diff
changeset
|
33 |
class VersionProps { |
2 | 34 |
|
35 |
||
36 |
private static final String launcher_name = |
|
33984
2333676816eb
8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents:
27565
diff
changeset
|
37 |
"@@LAUNCHER_NAME@@"; |
2 | 38 |
|
39 |
private static final String java_version = |
|
33984
2333676816eb
8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents:
27565
diff
changeset
|
40 |
"@@VERSION_SHORT@@"; |
2 | 41 |
|
42 |
private static final String java_runtime_name = |
|
33984
2333676816eb
8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents:
27565
diff
changeset
|
43 |
"@@RUNTIME_NAME@@"; |
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
44 |
|
2 | 45 |
private static final String java_runtime_version = |
33984
2333676816eb
8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents:
27565
diff
changeset
|
46 |
"@@VERSION_STRING@@"; |
2 | 47 |
|
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
48 |
private static final String VERSION_NUMBER = |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
49 |
"@@VERSION_NUMBER@@"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
50 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
51 |
private static final String VERSION_BUILD = |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
52 |
"@@VERSION_BUILD@@"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
53 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
54 |
private static final String VERSION_PRE = |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
55 |
"@@VERSION_PRE@@"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
56 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
57 |
private static final String VERSION_OPT = |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
58 |
"@@VERSION_OPT@@"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
59 |
|
2 | 60 |
static { |
61 |
init(); |
|
62 |
} |
|
63 |
||
64 |
public static void init() { |
|
65 |
System.setProperty("java.version", java_version); |
|
66 |
System.setProperty("java.runtime.version", java_runtime_version); |
|
67 |
System.setProperty("java.runtime.name", java_runtime_name); |
|
68 |
} |
|
69 |
||
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
70 |
static List<Integer> versionNumbers() { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
71 |
List<Integer> versionNumbers = new ArrayList<>(4); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
72 |
int prevIndex = 0; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
73 |
int index = VERSION_NUMBER.indexOf('.'); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
74 |
while (index > 0) { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
75 |
versionNumbers.add( |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
76 |
Integer.parseInt(VERSION_NUMBER, prevIndex, index, 10)); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
77 |
prevIndex = index; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
78 |
index = VERSION_NUMBER.indexOf('.', prevIndex); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
79 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
80 |
versionNumbers.add(Integer.parseInt(VERSION_NUMBER, |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
81 |
prevIndex, VERSION_NUMBER.length(), 10)); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
82 |
return versionNumbers; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
83 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
84 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
85 |
static Optional<String> pre() { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
86 |
return optionalOf(VERSION_PRE); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
87 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
88 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
89 |
static Optional<Integer> build() { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
90 |
return VERSION_BUILD.isEmpty() ? |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
91 |
Optional.empty() : |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
92 |
Optional.of(Integer.parseInt(VERSION_BUILD)); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
93 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
94 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
95 |
static Optional<String> optional() { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
96 |
return optionalOf(VERSION_OPT); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
97 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
98 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
99 |
// Treat empty strings as value not being present |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
100 |
private static Optional<String> optionalOf(String value) { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
101 |
if (!value.isEmpty()) { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
102 |
return Optional.of(value); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
103 |
} else { |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
104 |
return Optional.empty(); |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
105 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
106 |
} |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
107 |
|
2 | 108 |
/** |
109 |
* In case you were wondering this method is called by java -version. |
|
110 |
* Sad that it prints to stderr; would be nicer if default printed on |
|
111 |
* stdout. |
|
112 |
*/ |
|
113 |
public static void print() { |
|
114 |
print(System.err); |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* This is the same as print except that it adds an extra line-feed |
|
119 |
* at the end, typically used by the -showversion in the launcher |
|
120 |
*/ |
|
121 |
public static void println() { |
|
122 |
print(System.err); |
|
123 |
System.err.println(); |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* Give a stream, it will print version info on it. |
|
128 |
*/ |
|
129 |
public static void print(PrintStream ps) { |
|
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
130 |
boolean isHeadless = false; |
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
131 |
|
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
132 |
/* 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
|
133 |
String headless = System.getProperty("java.awt.headless"); |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
134 |
if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) { |
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
135 |
isHeadless = true; |
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
136 |
} |
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
137 |
|
2 | 138 |
/* First line: platform version. */ |
139 |
ps.println(launcher_name + " version \"" + java_version + "\""); |
|
140 |
||
141 |
/* Second line: runtime version (ie, libraries). */ |
|
8993
9076d969ffdf
7025066: Build systems changes to support SE Embedded Integration
dholmes
parents:
5506
diff
changeset
|
142 |
|
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
34003
diff
changeset
|
143 |
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
|
144 |
/* 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
|
145 |
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
|
146 |
jdk_debug_level = ""; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
34003
diff
changeset
|
147 |
} else { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
34003
diff
changeset
|
148 |
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
|
149 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
34003
diff
changeset
|
150 |
|
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
34003
diff
changeset
|
151 |
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
|
152 |
|
15683
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
153 |
if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) { |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
154 |
// embedded builds report headless state |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
155 |
ps.print(", headless"); |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
156 |
} |
3acd10709925
8003256: (profiles) Add support for profile identification
alanb
parents:
8993
diff
changeset
|
157 |
ps.println(')'); |
2 | 158 |
|
159 |
/* Third line: JVM information. */ |
|
160 |
String java_vm_name = System.getProperty("java.vm.name"); |
|
161 |
String java_vm_version = System.getProperty("java.vm.version"); |
|
162 |
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
|
163 |
ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " + |
2 | 164 |
java_vm_info + ")"); |
165 |
} |
|
166 |
||
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
36225
diff
changeset
|
167 |
} |