Add extra system property constants

Add java version methods


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@136992 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2002-08-25 22:17:53 +00:00
parent 54161dd497
commit f56215806c
1 changed files with 353 additions and 116 deletions

View File

@ -60,60 +60,243 @@ package org.apache.commons.lang;
* @author Based on code from Avalon Excalibur
* @author Based on code from Lucene
* @author <a href="mailto:scolebourne@apache.org">Stephen Colebourne</a>
* @version $Id: SystemUtils.java,v 1.1 2002/08/22 22:11:25 scolebourne Exp $
* @author <a href="mailto:sdowney@panix.com">Steve Downey</a>
* @version $Id: SystemUtils.java,v 1.2 2002/08/25 22:17:53 scolebourne Exp $
*/
public class SystemUtils {
/**
* Prevent construction of SystemUtils instances
* SystemUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as <code>SystemUtils.FILE_SEPARATOR</code>.
* This constructor is public to permit tools that require a JavaBean instance
* to operate.
*/
private SystemUtils() {
public SystemUtils() {
}
/** The line separator string from System.getProperty() */
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
/** The path separator string from System.getProperty() */
public static final String PATH_SEPARATOR = System.getProperty("path.separator");
/** The file separator string from System.getProperty() */
/**
* System Property: file.separator
* File separator ("/" on UNIX).
* First in version: 1.1
*/
public static final String FILE_SEPARATOR = System.getProperty("file.separator");
/** The working (user) directory string from System.getProperty() */
public static final String USER_WORKING_DIRECTORY = System.getProperty("user.dir");
/** The user home directory string from System.getProperty() */
public static final String USER_HOME_DIRECTORY = System.getProperty("user.home");
/** The user account name string from System.getProperty() */
public static final String USER_NAME = System.getProperty("user.name");
/** The os name string from System.getProperty() */
public static final String OS_NAME = System.getProperty("os.name");
/** The os architecture string from System.getProperty() */
public static final String OS_ARCHITECTURE = System.getProperty("os.arch");
/** The os version string from System.getProperty() */
public static final String OS_VERSION = System.getProperty("os.version");
/** True iff this is running on Windows */
public static final boolean IS_WINDOWS;
/** True iff this is running on Unix */
public static final boolean IS_UNIX;
/** True iff this is running on Mac */
public static final boolean IS_MAC;
/** True iff this is running on OS2 */
public static final boolean IS_OS2;
/** True iff this is running on Linux */
public static final boolean IS_LINUX;
/** The Java vendor string from System.getProperty() */
public static final String JAVA_VENDOR = System.getProperty("java.vendor");
/** The Java vendor url string from System.getProperty() */
public static final String JAVA_VENDOR_URL = System.getProperty("java.vendor.url");
/** The Java installation directory string from System.getProperty() */
public static final String JAVA_HOME = System.getProperty("java.home");
/** The Java class version number string from System.getProperty() */
public static final String JAVA_CLASS_VERSION = System.getProperty("java.class.version");
/** The Java classpath string from System.getProperty() */
/**
* System Property: java.class.path
* Java class path.
* First in version: 1.1
*/
public static final String JAVA_CLASS_PATH = System.getProperty("java.class.path");
/** The Java version string from System.getProperty() */
/**
* System Property: java.class.version
* Java class format version number.
* First in version: 1.1
*/
public static final String JAVA_CLASS_VERSION = System.getProperty("java.class.version");
/**
* System Property: java.compiler
* Name of JIT compiler to use.
* First in version: 1.4
*/
public static final String JAVA_COMPILER = System.getProperty("java.compiler");
/**
* System Property: java.ext.dirs
* Path of extension directory or directories.
* First in version: 1.3
*/
public static final String JAVA_EXT_DIRS = System.getProperty("java.ext.dirs");
/**
* System Property: java.home
* Java installation directory.
* First in version: 1.1
*/
public static final String JAVA_HOME = System.getProperty("java.home");
/**
* System Property: java.io.tmpdir
* Default temp file path.
* First in version: 1.4
*/
public static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir");
/**
* System Property: java.library.path
* List of paths to search when loading libraries.
* First in version: 1.4
*/
public static final String JAVA_LIBRARY_PATH = System.getProperty("java.library.path");
/**
* System Property: java.specification.name
* Java Runtime Environment specification name.
* First in version: 1.2
*/
public static final String JAVA_SPECIFICATION_NAME = System.getProperty("java.specification.name");
/**
* System Property: java.specification.vendor
* Java Runtime Environment specification vendor.
* First in version: 1.2
*/
public static final String JAVA_SPECIFICATION_VENDOR = System.getProperty("java.specification.vendor");
/**
* System Property: java.specification.version
* Java Runtime Environment specification version.
* First in version: 1.2
*/
public static final String JAVA_SPECIFICATION_VERSION = System.getProperty("java.specification.version");
/**
* System Property: java.vendor
* Java vendor-specific string.
* First in version: 1.1
*/
public static final String JAVA_VENDOR = System.getProperty("java.vendor");
/**
* System Property: java.vendor.url
* Java vendor URL.
* First in version: 1.1
*/
public static final String JAVA_VENDOR_URL = System.getProperty("java.vendor.url");
/**
* System Property: java.version
* Java version number.
* First in version: 1.1
*/
public static final String JAVA_VERSION = System.getProperty("java.version");
/**
* System Property: java.vm.name
* Java Virtual Machine implementation name.
* First in version: 1.2
*/
public static final String JAVA_VM_NAME = System.getProperty("java.vm.name");
/**
* System Property: java.vm.specification.name
* Java Virtual Machine specification name.
* First in version: 1.2
*/
public static final String JAVA_VM_SPECIFICATION_NAME = System.getProperty("java.vm.specification.name");
/**
* System Property: java.vm.specification.vendor
* Java Virtual Machine specification vendor.
* First in version: 1.2
*/
public static final String JAVA_VM_SPECIFICATION_VENDOR = System.getProperty("java.vm.specification.vendor");
/**
* System Property: java.vm.specification.version
* Java Virtual Machine specification version.
* First in version: 1.2
*/
public static final String JAVA_VM_SPECIFICATION_VERSION = System.getProperty("java.vm.specification.version");
/**
* System Property: java.vm.vendor
* Java Virtual Machine implementation vendor.
* First in version: 1.2
*/
public static final String JAVA_VM_VENDOR = System.getProperty("java.vm.vendor");
/**
* System Property: java.vm.version
* Java Virtual Machine implementation version.
* First in version: 1.2
*/
public static final String JAVA_VM_VERSION = System.getProperty("java.vm.version");
/**
* System Property: line.separator
* Line separator ("\n" on UNIX).
* First in version: 1.1
*/
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
/**
* System Property: os.arch
* Operating system architecture.
* First in version: 1.1
*/
public static final String OS_ARCH = System.getProperty("os.arch");
/**
* System Property: os.name
* Operating system name.
* First in version: 1.1
*/
public static final String OS_NAME = System.getProperty("os.name");
/**
* System Property: os.version
* Operating system version.
* First in version: 1.1
*/
public static final String OS_VERSION = System.getProperty("os.version");
/**
* System Property: path.separator
* Path separator (":" on UNIX).
* First in version: 1.1
*/
public static final String PATH_SEPARATOR = System.getProperty("path.separator");
/**
* System Property: user.dir
* User's current working directory.
* First in version: 1.1
*/
public static final String USER_DIR = System.getProperty("user.dir");
/**
* System Property: user.home
* User's home directory.
* First in version: 1.1
*/
public static final String USER_HOME = System.getProperty("user.home");
/**
* System Property: user.name
* User's account name.
* First in version: 1.1
*/
public static final String USER_NAME = System.getProperty("user.name");
/** True iff this is Java version 1.1. */
public static final boolean IS_JAVA_1_1 = JAVA_VERSION.startsWith("1.1.");
/** True iff this is Java version 1.2. */
@ -125,79 +308,133 @@ public class SystemUtils {
/** True iff this is Java version 1.3. */
public static final boolean IS_JAVA_1_5 = JAVA_VERSION.startsWith("1.5.");
/*
* The JLS doesn't seem to specify an exact naming convention for the
* os.name. We ensure a uniform naming here.
*/
static {
// from http://www.geocities.com/vamp201/os.html
if (OS_NAME.startsWith("Windows")) {
IS_WINDOWS = true;
IS_UNIX = false;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("SunOS")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("Solaris")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("Linux")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = true;
} else if (OS_NAME.startsWith("HP-UX")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("AIX")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("Irix")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("Digital Unix")) {
IS_WINDOWS = false;
IS_UNIX = true;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
} else if (OS_NAME.startsWith("OS/2")) {
IS_WINDOWS = false;
IS_UNIX = false;
IS_MAC = false;
IS_OS2 = true;
IS_LINUX = false;
} else if (OS_NAME.startsWith("Mac")) {
IS_WINDOWS = false;
IS_UNIX = false;
IS_MAC = true;
IS_OS2 = false;
IS_LINUX = false;
} else {
IS_WINDOWS = false;
IS_UNIX = false;
IS_MAC = false;
IS_OS2 = false;
IS_LINUX = false;
}
}
// Parsing operating system may stay here, or it may be moved somewhere else entirely
// /** True iff this is running on Windows */
// public static final boolean IS_WINDOWS;
// /** True iff this is running on Unix */
// public static final boolean IS_UNIX;
// /** True iff this is running on Mac */
// public static final boolean IS_MAC;
// /** True iff this is running on OS2 */
// public static final boolean IS_OS2;
// /** True iff this is running on Linux */
// public static final boolean IS_LINUX;
//
// /*
// * The JLS doesn't seem to specify an exact naming convention for the
// * os.name. We ensure a uniform naming here.
// */
// static {
// // from http://www.geocities.com/vamp201/os.html
// if (OS_NAME.startsWith("Windows")) {
// IS_WINDOWS = true;
// IS_UNIX = false;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("SunOS")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("Solaris")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("Linux")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = true;
// } else if (OS_NAME.startsWith("HP-UX")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("AIX")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("Irix")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("Digital Unix")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("OS/400")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("OS/2")) {
// IS_WINDOWS = false;
// IS_UNIX = false;
// IS_MAC = false;
// IS_OS2 = true;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("Mac OS X")) {
// IS_WINDOWS = false;
// IS_UNIX = true;
// IS_MAC = true;
// IS_OS2 = false;
// IS_LINUX = false;
// } else if (OS_NAME.startsWith("Mac")) {
// IS_WINDOWS = false;
// IS_UNIX = false;
// IS_MAC = true;
// IS_OS2 = false;
// IS_LINUX = false;
// } else {
// IS_WINDOWS = false;
// IS_UNIX = false;
// IS_MAC = false;
// IS_OS2 = false;
// IS_LINUX = false;
// }
// }
/**
* Get the Java version number as a float.
* Example output:<br>
* 1.2f for JDK 1.2<br>
* 1.31f for JDK 1.3.1<br>
*
* @return the version, for example 1.31f for JDK 1.3.1
*/
public static float getJavaVersion() {
String str = JAVA_VERSION.substring(0, 3);
if (JAVA_VERSION.length() >= 5) {
str = str + JAVA_VERSION.substring(4, 5);
}
return Float.parseFloat(str);
}
/**
* Is the Java version at the the requested version.
* Example input:<br>
* 1.2f for JDK 1.2<br>
* 1.31f for JDK 1.3.1<br>
*
* @param requiredVersion the required version, for example 1.31f
* @return true if the actual version is equal or greater than the required version
*/
public boolean isJavaVersionAtLeast(float requiredVersion) {
return (getJavaVersion() >= requiredVersion);
}
}