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 String getJavaClassPath() {
027 return _instance._javaClassPath;
028 }
029
030 public static double getJavaClassVersion() {
031 return _instance._javaClassVersion;
032 }
033
034 public static String getJavaRuntimeName() {
035 return _instance._javaRuntimeName;
036 }
037
038 public static String getJavaRuntimeVersion() {
039 return _instance._javaRuntimeVersion;
040 }
041
042 public static double getJavaSpecificationVersion() {
043 return _instance._javaSpecificationVersion;
044 }
045
046 public static String getJavaVendor() {
047 return _instance._javaVendor;
048 }
049
050 public static String getJavaVersion() {
051 return _instance._javaVersion;
052 }
053
054 public static String getJavaVmVersion() {
055 return _instance._javaVmVersion;
056 }
057
058 public static boolean is64bit() {
059 return _instance._64bit;
060 }
061
062 public static boolean isIBM() {
063 return _instance._ibm;
064 }
065
066 public static boolean isJDK7() {
067 String javaVersion = getJavaVersion();
068
069 if (javaVersion.startsWith(_JAVA_VERSION_JDK_7)) {
070 return true;
071 }
072 else {
073 return false;
074 }
075 }
076
077 public static boolean isOpenJDK() {
078 return _instance._openJDK;
079 }
080
081 public static boolean isOracle() {
082 return _instance._oracle;
083 }
084
085 protected JavaDetector() {
086 _javaClassPath = System.getProperty("java.class.path");
087 _javaClassVersion = GetterUtil.getDouble(
088 System.getProperty("java.class.version"));
089 _javaRuntimeName = System.getProperty("java.runtime.name");
090 _javaRuntimeVersion = System.getProperty("java.runtime.version");
091 _javaSpecificationVersion = GetterUtil.getDouble(
092 System.getProperty("java.specification.version"));
093 _javaVendor = System.getProperty("java.vendor");
094 _javaVersion = System.getProperty("java.version");
095 _javaVmVersion = System.getProperty("java.vm.version");
096
097 _64bit = Validator.equals(
098 "64", System.getProperty("sun.arch.data.model"));
099
100 boolean oracle = false;
101
102 if (_javaVendor != null) {
103 _ibm = _javaVendor.startsWith("IBM");
104
105 if (_javaVendor.startsWith("Oracle") ||
106 _javaVendor.startsWith("Sun")) {
107
108 oracle = true;
109 }
110 }
111 else {
112 _ibm = false;
113 }
114
115 _oracle = oracle;
116
117 if (_javaRuntimeName != null) {
118 _openJDK = _javaRuntimeName.contains("OpenJDK");
119 }
120 else {
121 _openJDK = false;
122 }
123
124 if (_log.isDebugEnabled()) {
125 LogUtil.debug(_log, new SortedProperties(System.getProperties()));
126 }
127 }
128
129 private static final String _JAVA_VERSION_JDK_7 = "1.7.";
130
131 private static final Log _log = LogFactoryUtil.getLog(JavaDetector.class);
132
133 private static final JavaDetector _instance = new JavaDetector();
134
135 private final boolean _64bit;
136 private final boolean _ibm;
137 private final String _javaClassPath;
138 private final double _javaClassVersion;
139 private final String _javaRuntimeName;
140 private final String _javaRuntimeVersion;
141 private final double _javaSpecificationVersion;
142 private final String _javaVendor;
143 private final String _javaVersion;
144 private final String _javaVmVersion;
145 private final boolean _openJDK;
146 private final boolean _oracle;
147
148 }