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