1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.util;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.log.LogUtil;
28  
29  /**
30   * <a href="JavaProps.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class JavaProps {
35  
36      public static final double JAVA_CLASS_VERSION_JDK_4 = 48.0;
37  
38      public static final double JAVA_CLASS_VERSION_JDK_5 = 49.0;
39  
40      public static final double JAVA_CLASS_VERSION_JDK_6 = 50.0;
41  
42      public static final double JAVA_CLASS_VERSION_JDK_7 = 51.0;
43  
44      public static String getJavaClassPath() {
45          return _instance._javaClassPath;
46      }
47  
48      public static double getJavaClassVersion() {
49          return _instance._javaClassVersion;
50      }
51  
52      public static String getJavaRuntimeVersion() {
53          return _instance._javaRuntimeVersion;
54      }
55  
56      public static double getJavaSpecificationVersion() {
57          return _instance._javaSpecificationVersion;
58      }
59  
60      public static String getJavaVersion() {
61          return _instance._javaVersion;
62      }
63  
64      public static String getJavaVmVersion() {
65          return _instance._javaVmVersion;
66      }
67  
68      public static boolean isJDK4() {
69          if (JavaProps.getJavaClassVersion() >=
70                  JavaProps.JAVA_CLASS_VERSION_JDK_4) {
71  
72              return true;
73          }
74          else {
75              return false;
76          }
77      }
78  
79      public static boolean isJDK5() {
80          if (JavaProps.getJavaClassVersion() >=
81                  JavaProps.JAVA_CLASS_VERSION_JDK_5) {
82  
83              return true;
84          }
85          else {
86              return false;
87          }
88      }
89  
90      public static boolean isJDK6() {
91          if (JavaProps.getJavaClassVersion() >=
92                  JavaProps.JAVA_CLASS_VERSION_JDK_6) {
93  
94              return true;
95          }
96          else {
97              return false;
98          }
99      }
100 
101     public static boolean isJDK7() {
102         if (JavaProps.getJavaClassVersion() >=
103                 JavaProps.JAVA_CLASS_VERSION_JDK_7) {
104 
105             return true;
106         }
107         else {
108             return false;
109         }
110     }
111 
112     private JavaProps() {
113         _javaClassPath = System.getProperty("java.class.path");
114         _javaClassVersion = Double.parseDouble(System.getProperty(
115             "java.class.version"));
116         _javaRuntimeVersion = System.getProperty("java.runtime.version");
117         _javaSpecificationVersion = Double.parseDouble(System.getProperty(
118             "java.specification.version"));
119         _javaVersion = System.getProperty("java.version");
120         _javaVmVersion = System.getProperty("java.vm.version");
121 
122         LogUtil.debug(_log, System.getProperties());
123     }
124 
125     private static Log _log = LogFactoryUtil.getLog(JavaProps.class);
126 
127     private static JavaProps _instance = new JavaProps();
128 
129     private String _javaClassPath;
130     private double _javaClassVersion;
131     private String _javaRuntimeVersion;
132     private double _javaSpecificationVersion;
133     private String _javaVersion;
134     private String _javaVmVersion;
135 
136 }