1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
35  public class JavaProps {
36  
37      public static final double JAVA_CLASS_VERSION_JDK_4 = 48.0;
38  
39      public static final double JAVA_CLASS_VERSION_JDK_5 = 49.0;
40  
41      public static final double JAVA_CLASS_VERSION_JDK_6 = 50.0;
42  
43      public static final double JAVA_CLASS_VERSION_JDK_7 = 51.0;
44  
45      public static String getJavaClassPath() {
46          return _instance._javaClassPath;
47      }
48  
49      public static double getJavaClassVersion() {
50          return _instance._javaClassVersion;
51      }
52  
53      public static String getJavaRuntimeVersion() {
54          return _instance._javaRuntimeVersion;
55      }
56  
57      public static double getJavaSpecificationVersion() {
58          return _instance._javaSpecificationVersion;
59      }
60  
61      public static String getJavaVersion() {
62          return _instance._javaVersion;
63      }
64  
65      public static String getJavaVmVersion() {
66          return _instance._javaVmVersion;
67      }
68  
69      public static boolean isJDK4() {
70          if (JavaProps.getJavaClassVersion() >=
71                  JavaProps.JAVA_CLASS_VERSION_JDK_4) {
72  
73              return true;
74          }
75          else {
76              return false;
77          }
78      }
79  
80      public static boolean isJDK5() {
81          if (JavaProps.getJavaClassVersion() >=
82                  JavaProps.JAVA_CLASS_VERSION_JDK_5) {
83  
84              return true;
85          }
86          else {
87              return false;
88          }
89      }
90  
91      public static boolean isJDK6() {
92          if (JavaProps.getJavaClassVersion() >=
93                  JavaProps.JAVA_CLASS_VERSION_JDK_6) {
94  
95              return true;
96          }
97          else {
98              return false;
99          }
100     }
101 
102     public static boolean isJDK7() {
103         if (JavaProps.getJavaClassVersion() >=
104                 JavaProps.JAVA_CLASS_VERSION_JDK_7) {
105 
106             return true;
107         }
108         else {
109             return false;
110         }
111     }
112 
113     private JavaProps() {
114         _javaClassPath = System.getProperty("java.class.path");
115         _javaClassVersion = Double.parseDouble(System.getProperty(
116             "java.class.version"));
117         _javaRuntimeVersion = System.getProperty("java.runtime.version");
118         _javaSpecificationVersion = Double.parseDouble(System.getProperty(
119             "java.specification.version"));
120         _javaVersion = System.getProperty("java.version");
121         _javaVmVersion = System.getProperty("java.vm.version");
122 
123         LogUtil.debug(_log, System.getProperties());
124     }
125 
126     private static Log _log = LogFactoryUtil.getLog(JavaProps.class);
127 
128     private static JavaProps _instance = new JavaProps();
129 
130     private String _javaClassPath;
131     private double _javaClassVersion;
132     private String _javaRuntimeVersion;
133     private double _javaSpecificationVersion;
134     private String _javaVersion;
135     private String _javaVmVersion;
136 
137 }