~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/misc/Version.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

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