001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class JavaProps {
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 getJavaRuntimeVersion() {
043                    return _instance._javaRuntimeVersion;
044            }
045    
046            public static double getJavaSpecificationVersion() {
047                    return _instance._javaSpecificationVersion;
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 isJDK4() {
059                    if (JavaProps.getJavaClassVersion() >=
060                                    JavaProps.JAVA_CLASS_VERSION_JDK_4) {
061    
062                            return true;
063                    }
064                    else {
065                            return false;
066                    }
067            }
068    
069            public static boolean isJDK5() {
070                    if (JavaProps.getJavaClassVersion() >=
071                                    JavaProps.JAVA_CLASS_VERSION_JDK_5) {
072    
073                            return true;
074                    }
075                    else {
076                            return false;
077                    }
078            }
079    
080            public static boolean isJDK6() {
081                    if (JavaProps.getJavaClassVersion() >=
082                                    JavaProps.JAVA_CLASS_VERSION_JDK_6) {
083    
084                            return true;
085                    }
086                    else {
087                            return false;
088                    }
089            }
090    
091            public static boolean isJDK7() {
092                    if (JavaProps.getJavaClassVersion() >=
093                                    JavaProps.JAVA_CLASS_VERSION_JDK_7) {
094    
095                            return true;
096                    }
097                    else {
098                            return false;
099                    }
100            }
101    
102            private JavaProps() {
103                    _javaClassPath = System.getProperty("java.class.path");
104                    _javaClassVersion = Double.parseDouble(System.getProperty(
105                            "java.class.version"));
106                    _javaRuntimeVersion = System.getProperty("java.runtime.version");
107                    _javaSpecificationVersion = Double.parseDouble(System.getProperty(
108                            "java.specification.version"));
109                    _javaVersion = System.getProperty("java.version");
110                    _javaVmVersion = System.getProperty("java.vm.version");
111    
112                    LogUtil.debug(_log, System.getProperties());
113            }
114    
115            private static Log _log = LogFactoryUtil.getLog(JavaProps.class);
116    
117            private static JavaProps _instance = new JavaProps();
118    
119            private String _javaClassPath;
120            private double _javaClassVersion;
121            private String _javaRuntimeVersion;
122            private double _javaSpecificationVersion;
123            private String _javaVersion;
124            private String _javaVmVersion;
125    
126    }