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 java.lang;
27
28 import java.io.PrintStream;
29
30 class VersionProps {
31
32
33 private static final String launcher_name =
34 "@@LAUNCHER_NAME@@";
35
36 private static final String java_version =
37 "@@VERSION_SHORT@@";
38
39 private static final String java_runtime_name =
40 "@@RUNTIME_NAME@@";
41
42 private static final String java_runtime_version =
43 "@@VERSION_STRING@@";
44
45 static {
46 init();
47 }
48
49 public static void init() {
50 System.setProperty("java.version", java_version);
51 System.setProperty("java.runtime.version", java_runtime_version);
52 System.setProperty("java.runtime.name", java_runtime_name);
53 }
54
55 /**
56 * In case you were wondering this method is called by java -version.
57 * Sad that it prints to stderr; would be nicer if default printed on
58 * stdout.
59 */
60 public static void print() {
61 print(System.err);
62 }
63
64 /**
65 * This is the same as print except that it adds an extra line-feed
66 * at the end, typically used by the -showversion in the launcher
67 */
68 public static void println() {
69 print(System.err);
70 System.err.println();
71 }
72
73 /**
74 * Give a stream, it will print version info on it.
|
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 java.lang;
27
28 import java.io.PrintStream;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Optional;
32
33 class VersionProps {
34
35
36 private static final String launcher_name =
37 "@@LAUNCHER_NAME@@";
38
39 private static final String java_version =
40 "@@VERSION_SHORT@@";
41
42 private static final String java_runtime_name =
43 "@@RUNTIME_NAME@@";
44
45 private static final String java_runtime_version =
46 "@@VERSION_STRING@@";
47
48 private static final String VERSION_NUMBER =
49 "@@VERSION_NUMBER@@";
50
51 private static final String VERSION_BUILD =
52 "@@VERSION_BUILD@@";
53
54 private static final String VERSION_PRE =
55 "@@VERSION_PRE@@";
56
57 private static final String VERSION_OPT =
58 "@@VERSION_OPT@@";
59
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
70 static List<Integer> versionNumbers() {
71 List<Integer> versionNumbers = new ArrayList<>(4);
72 int prevIndex = 0;
73 int index = VERSION_NUMBER.indexOf('.');
74 while (index > 0) {
75 versionNumbers.add(
76 Integer.parseInt(VERSION_NUMBER, prevIndex, index, 10));
77 prevIndex = index + 1;
78 index = VERSION_NUMBER.indexOf('.', prevIndex);
79 }
80 versionNumbers.add(Integer.parseInt(VERSION_NUMBER,
81 prevIndex, VERSION_NUMBER.length(), 10));
82 return versionNumbers;
83 }
84
85 static Optional<String> pre() {
86 return optionalOf(VERSION_PRE);
87 }
88
89 static Optional<Integer> build() {
90 Optional<String> build = optionalOf(VERSION_BUILD);
91 Optional<Integer> buildNumber = build.isPresent() ?
92 Optional.of(Integer.parseInt(build.get())) :
93 Optional.empty();
94 return buildNumber;
95 }
96
97 static Optional<String> optional() {
98 return optionalOf(VERSION_OPT);
99 }
100
101 // Treat empty strings as value not being present
102 private static Optional<String> optionalOf(String value) {
103 if (!value.isEmpty()) {
104 return Optional.of(value);
105 } else {
106 return Optional.empty();
107 }
108 }
109
110 /**
111 * In case you were wondering this method is called by java -version.
112 * Sad that it prints to stderr; would be nicer if default printed on
113 * stdout.
114 */
115 public static void print() {
116 print(System.err);
117 }
118
119 /**
120 * This is the same as print except that it adds an extra line-feed
121 * at the end, typically used by the -showversion in the launcher
122 */
123 public static void println() {
124 print(System.err);
125 System.err.println();
126 }
127
128 /**
129 * Give a stream, it will print version info on it.
|