001
014
015 package com.liferay.portal.kernel.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.log.LogUtil;
020
021
024 public class JavaDetector {
025
026 public static final double JAVA_CLASS_VERSION_JDK_4 = 48.0;
027
028 public static final double JAVA_CLASS_VERSION_JDK_5 = 49.0;
029
030 public static final double JAVA_CLASS_VERSION_JDK_6 = 50.0;
031
032 public static final double JAVA_CLASS_VERSION_JDK_7 = 51.0;
033
034 public static String getJavaClassPath() {
035 return _instance._javaClassPath;
036 }
037
038 public static double getJavaClassVersion() {
039 return _instance._javaClassVersion;
040 }
041
042 public static String getJavaRuntimeName() {
043 return _instance._javaRuntimeName;
044 }
045
046 public static String getJavaRuntimeVersion() {
047 return _instance._javaRuntimeVersion;
048 }
049
050 public static double getJavaSpecificationVersion() {
051 return _instance._javaSpecificationVersion;
052 }
053
054 public static String getJavaVendor() {
055 return _instance._javaVendor;
056 }
057
058 public static String getJavaVersion() {
059 return _instance._javaVersion;
060 }
061
062 public static String getJavaVmVersion() {
063 return _instance._javaVmVersion;
064 }
065
066 public static boolean is64bit() {
067 return _instance._64bit;
068 }
069
070 public static boolean isIBM() {
071 return _instance._ibm;
072 }
073
074 public static boolean isJDK4() {
075 if (getJavaClassVersion() >= JAVA_CLASS_VERSION_JDK_4) {
076 return true;
077 }
078 else {
079 return false;
080 }
081 }
082
083 public static boolean isJDK5() {
084 if (getJavaClassVersion() >= JavaDetector.JAVA_CLASS_VERSION_JDK_5) {
085 return true;
086 }
087 else {
088 return false;
089 }
090 }
091
092 public static boolean isJDK6() {
093 if (getJavaClassVersion() >= JavaDetector.JAVA_CLASS_VERSION_JDK_6) {
094 return true;
095 }
096 else {
097 return false;
098 }
099 }
100
101 public static boolean isJDK7() {
102 if (getJavaClassVersion() >= JavaDetector.JAVA_CLASS_VERSION_JDK_7) {
103 return true;
104 }
105 else {
106 return false;
107 }
108 }
109
110 public static boolean isOpenJDK() {
111 return _instance._openJDK;
112 }
113
114 protected JavaDetector() {
115 _javaClassPath = System.getProperty("java.class.path");
116 _javaClassVersion = GetterUtil.getDouble(
117 System.getProperty("java.class.version"));
118 _javaRuntimeName = System.getProperty("java.runtime.name");
119 _javaRuntimeVersion = System.getProperty("java.runtime.version");
120 _javaSpecificationVersion = GetterUtil.getDouble(
121 System.getProperty("java.specification.version"));
122 _javaVendor = System.getProperty("java.vendor");
123 _javaVersion = System.getProperty("java.version");
124 _javaVmVersion = System.getProperty("java.vm.version");
125
126 _64bit = Validator.equals(
127 "64", System.getProperty("sun.arch.data.model"));
128
129 if (_javaVendor != null) {
130 _ibm = _javaVendor.startsWith("IBM");
131 }
132
133 if (_javaRuntimeName != null) {
134 _openJDK = _javaRuntimeName.contains("OpenJDK");
135 }
136
137 if (_log.isDebugEnabled()) {
138 LogUtil.debug(_log, new SortedProperties(System.getProperties()));
139 }
140 }
141
142 private static Log _log = LogFactoryUtil.getLog(JavaDetector.class);
143
144 private static JavaDetector _instance = new JavaDetector();
145
146 private boolean _64bit;
147 private boolean _ibm;
148 private String _javaClassPath;
149 private double _javaClassVersion;
150 private String _javaRuntimeName;
151 private String _javaRuntimeVersion;
152 private double _javaSpecificationVersion;
153 private String _javaVendor;
154 private String _javaVersion;
155 private String _javaVmVersion;
156 private boolean _openJDK;
157
158 }