1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.log.LogUtil;
20  
21  /**
22   * <a href="JavaProps.java.html"><b><i>View Source</i></b></a>
23   *
24   * @author Brian Wing Shun Chan
25   */
26  public class JavaProps {
27  
28      public static final double JAVA_CLASS_VERSION_JDK_4 = 48.0;
29  
30      public static final double JAVA_CLASS_VERSION_JDK_5 = 49.0;
31  
32      public static final double JAVA_CLASS_VERSION_JDK_6 = 50.0;
33  
34      public static final double JAVA_CLASS_VERSION_JDK_7 = 51.0;
35  
36      public static String getJavaClassPath() {
37          return _instance._javaClassPath;
38      }
39  
40      public static double getJavaClassVersion() {
41          return _instance._javaClassVersion;
42      }
43  
44      public static String getJavaRuntimeVersion() {
45          return _instance._javaRuntimeVersion;
46      }
47  
48      public static double getJavaSpecificationVersion() {
49          return _instance._javaSpecificationVersion;
50      }
51  
52      public static String getJavaVendor() {
53          return _instance._javaVendor;
54      }
55  
56      public static String getJavaVersion() {
57          return _instance._javaVersion;
58      }
59  
60      public static String getJavaVmVersion() {
61          return _instance._javaVmVersion;
62      }
63  
64      public static boolean is64bit() {
65          return _instance._64bit;
66      }
67  
68      public static boolean isIBM() {
69          return _instance._ibm;
70      }
71  
72      public static boolean isJDK4() {
73          if (JavaProps.getJavaClassVersion() >=
74                  JavaProps.JAVA_CLASS_VERSION_JDK_4) {
75  
76              return true;
77          }
78          else {
79              return false;
80          }
81      }
82  
83      public static boolean isJDK5() {
84          if (JavaProps.getJavaClassVersion() >=
85                  JavaProps.JAVA_CLASS_VERSION_JDK_5) {
86  
87              return true;
88          }
89          else {
90              return false;
91          }
92      }
93  
94      public static boolean isJDK6() {
95          if (JavaProps.getJavaClassVersion() >=
96                  JavaProps.JAVA_CLASS_VERSION_JDK_6) {
97  
98              return true;
99          }
100         else {
101             return false;
102         }
103     }
104 
105     public static boolean isJDK7() {
106         if (JavaProps.getJavaClassVersion() >=
107                 JavaProps.JAVA_CLASS_VERSION_JDK_7) {
108 
109             return true;
110         }
111         else {
112             return false;
113         }
114     }
115 
116     private JavaProps() {
117         _javaClassPath = System.getProperty("java.class.path");
118         _javaClassVersion = Double.parseDouble(System.getProperty(
119             "java.class.version"));
120         _javaRuntimeVersion = System.getProperty("java.runtime.version");
121         _javaSpecificationVersion = Double.parseDouble(System.getProperty(
122             "java.specification.version"));
123         _javaVendor = System.getProperty("java.vendor");
124         _javaVersion = System.getProperty("java.version");
125         _javaVmVersion = System.getProperty("java.vm.version");
126 
127         _64bit = Validator.equals(
128             "64", System.getProperty("sun.arch.data.model"));
129 
130         if (_javaVendor != null) {
131             _ibm = _javaVendor.startsWith("IBM");
132         }
133 
134         LogUtil.debug(_log, System.getProperties());
135     }
136 
137     private static Log _log = LogFactoryUtil.getLog(JavaProps.class);
138 
139     private static JavaProps _instance = new JavaProps();
140 
141     private boolean _64bit;
142     private boolean _ibm;
143     private String _javaClassPath;
144     private double _javaClassVersion;
145     private String _javaRuntimeVersion;
146     private double _javaSpecificationVersion;
147     private String _javaVendor;
148     private String _javaVersion;
149     private String _javaVmVersion;
150 
151 }