01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.util;
18:
19: /**
20: * Helper class used to find the current Java/JDK version.
21: * Usually we want to find if we're in a 1.4 or higher JVM.
22: * (Spring does not support 1.2 JVMs.)
23: *
24: * @author kimchy
25: */
26: public class JdkVersion {
27:
28: public static final int JAVA_13 = 0;
29: public static final int JAVA_14 = 1;
30: public static final int JAVA_15 = 2;
31: public static final int JAVA_16 = 3;
32: public static final int JAVA_17 = 4;
33:
34: private static final String javaVersion;
35:
36: private static final int majorJavaVersion;
37:
38: static {
39: javaVersion = System.getProperty("java.version");
40: // Version String should look like "1.4.1_02"
41: if (javaVersion.indexOf("1.7.") != -1) {
42: majorJavaVersion = JAVA_17;
43: } else if (javaVersion.indexOf("1.6.") != -1) {
44: majorJavaVersion = JAVA_16;
45: } else if (javaVersion.indexOf("1.5.") != -1) {
46: majorJavaVersion = JAVA_15;
47: } else if (javaVersion.indexOf("1.4.") != -1) {
48: majorJavaVersion = JAVA_14;
49: } else {
50: // Else leave 1.3 as default (it's either 1.3 or unknown).
51: majorJavaVersion = JAVA_13;
52: }
53: }
54:
55: /**
56: * Return the full Java version string, as returned by
57: * <code>System.getProperty("java.version")</code>.
58: */
59: public static String getJavaVersion() {
60: return javaVersion;
61: }
62:
63: /**
64: * Get the major version code. This means we can do things like
65: * <code>if (getMajorJavaVersion() < JAVA_14)</code>.
66: *
67: * @return a code comparable to the JAVA_XX codes in this class
68: * @see #JAVA_13
69: * @see #JAVA_14
70: * @see #JAVA_15
71: */
72: public static int getMajorJavaVersion() {
73: return majorJavaVersion;
74: }
75:
76: }
|