Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 20767 invoked from network); 21 Jul 2003 22:57:55 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 21 Jul 2003 22:57:55 -0000 Received: (qmail 5223 invoked by uid 97); 21 Jul 2003 23:00:32 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 5216 invoked from network); 21 Jul 2003 23:00:31 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 21 Jul 2003 23:00:31 -0000 Received: (qmail 20486 invoked by uid 500); 21 Jul 2003 22:57:52 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 20475 invoked by uid 500); 21 Jul 2003 22:57:52 -0000 Received: (qmail 20426 invoked from network); 21 Jul 2003 22:57:51 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 21 Jul 2003 22:57:51 -0000 Received: (qmail 65741 invoked by uid 1529); 21 Jul 2003 22:57:51 -0000 Date: 21 Jul 2003 22:57:51 -0000 Message-ID: <20030721225751.65740.qmail@icarus.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang SystemUtilsTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N scolebourne 2003/07/21 15:57:51 Modified: lang/src/java/org/apache/commons/lang SystemUtils.java lang/src/test/org/apache/commons/lang SystemUtilsTest.java Log: Fix class so IS_JAVA_* and IS_OS_* constants work correctly. bug 21767, from Tetsuya Kaneuchi Revision Changes Path 1.19 +235 -219 jakarta-commons/lang/src/java/org/apache/commons/lang/SystemUtils.java Index: SystemUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/SystemUtils.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- SystemUtils.java 18 Jul 2003 16:48:25 -0000 1.18 +++ SystemUtils.java 21 Jul 2003 22:57:50 -0000 1.19 @@ -66,12 +66,16 @@ * @author Steve Downey * @author Gary Gregory * @author Michael Becke + * @author Tetsuya Kaneuchi * @since 1.0 * @version $Id$ */ public class SystemUtils { + // System property constants //----------------------------------------------------------------------- + // These MUST be declared first. Other constants depend on this. + /** *

The file.encoding System Property.

*

File encoding, such as Cp1252.

@@ -94,185 +98,6 @@ */ public static final String FILE_SEPARATOR = getSystemProperty("file.separator"); - //----------------------------------------------------------------------- - /** - *

Is true if this is Java version 1.1 (also 1.1.x versions).

- * - *

The field will return false if {@link #JAVA_VERSION} is - * null.

- */ - public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1"); - - /** - *

Is true if this is Java version 1.2 (also 1.2.x versions).

- * - *

The field will return false if {@link #JAVA_VERSION} is - * null.

- */ - public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2"); - - /** - *

Is true if this is Java version 1.3 (also 1.3.x versions).

- * - *

The field will return false if {@link #JAVA_VERSION} is - * null.

- */ - public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3"); - - /** - *

Is true if this is Java version 1.4 (also 1.4.x versions).

- * - *

The field will false false if {@link #JAVA_VERSION} is - * null.

- */ - public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4"); - - /** - *

Is true if this is Java version 1.5 (also 1.5.x versions).

- * - *

The field will return false if {@link #JAVA_VERSION} is - * null.

- */ - public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5"); - - /** - *

Is true if this is AIX.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_AIX = getOSMatches("AIX"); - - /** - *

Is true if this is HP-UX.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX"); - - /** - *

Is true if this is Irix.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_IRIX = getOSMatches("Irix"); - - /** - *

Is true if this is Linux.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX"); - // Windows XP returns 'Windows 2000' just for fun... - - /** - *

Is true if this is Mac.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_MAC = getOSMatches("Mac"); - - /** - *

Is true if this is Mac.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X"); - - /** - *

Is true if this is OS/2.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_OS2 = getOSMatches("OS/2"); - - /** - *

Is true if this is Solaris.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris"); - - /** - *

Is true if this is SunOS.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); - - //----------------------------------------------------------------------- - // OS names from http://www.vamphq.com/os.html - // Selected ones included - please advise commons-dev@jakarta.apache.org - // if you want another added or a mistake corrected - - /** - *

Is true if this is Windows.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS = getOSMatches("Windows"); - - /** - *

Is true if this is Windows 2000.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS_2000 = getOSMatches("Windows", "5.0"); - - /** - *

Is true if this is Windows 95.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS_95 = getOSMatches("Windows 9", "4.0"); - // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above - - /** - *

Is true if this is Windows 98.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS_98 = getOSMatches("Windows 9", "4.1"); - // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above - - /** - *

Is true if this is Windows ME.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS_ME = getOSMatches("Windows", "4.9"); - // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above - - /** - *

Is true if this is Windows NT.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS_NT = getOSMatches("Windows NT"); - // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem - - /** - *

Is true if this is Windows XP.

- * - *

The field will return false if OS_NAME is - * null.

- */ - public static final boolean IS_OS_WINDOWS_XP = getOSMatches("Windows", "5.1"); - /** *

The java.class.path System Property. Java class path.

* @@ -432,33 +257,6 @@ */ public static final String JAVA_VERSION = getSystemProperty("java.version"); - //----------------------------------------------------------------------- - /** - *

Gets the Java version as a float.

- * - *

Example return values:

- *
    - *
  • 1.2f for JDK 1.2 - *
  • 1.31f for JDK 1.3.1 - *
- * - *

The field will return zero if {@link #JAVA_VERSION} is null.

- */ - public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); - - /** - *

Gets the Java version as an int.

- * - *

Example return values:

- *
    - *
  • 120 for JDK 1.2 - *
  • 131 for JDK 1.3.1 - *
- * - *

The field will return zero if {@link #JAVA_VERSION} is null.

- */ - public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); - /** *

The java.vm.info System Property. Java Virtual Machine implementation * info.

@@ -644,6 +442,235 @@ */ public static final String USER_NAME = getSystemProperty("user.name"); + // Java version + //----------------------------------------------------------------------- + // These MUST be declared after those above as they depend on the + // values being set up + + /** + *

Gets the Java version as a float.

+ * + *

Example return values:

+ *
    + *
  • 1.2f for JDK 1.2 + *
  • 1.31f for JDK 1.3.1 + *
+ * + *

The field will return zero if {@link #JAVA_VERSION} is null.

+ */ + public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); + + /** + *

Gets the Java version as an int.

+ * + *

Example return values:

+ *
    + *
  • 120 for JDK 1.2 + *
  • 131 for JDK 1.3.1 + *
+ * + *

The field will return zero if {@link #JAVA_VERSION} is null.

+ */ + public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); + + // Java version checks + //----------------------------------------------------------------------- + // These MUST be declared after those above as they depend on the + // values being set up + + /** + *

Is true if this is Java version 1.1 (also 1.1.x versions).

+ * + *

The field will return false if {@link #JAVA_VERSION} is + * null.

+ */ + public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1"); + + /** + *

Is true if this is Java version 1.2 (also 1.2.x versions).

+ * + *

The field will return false if {@link #JAVA_VERSION} is + * null.

+ */ + public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2"); + + /** + *

Is true if this is Java version 1.3 (also 1.3.x versions).

+ * + *

The field will return false if {@link #JAVA_VERSION} is + * null.

+ */ + public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3"); + + /** + *

Is true if this is Java version 1.4 (also 1.4.x versions).

+ * + *

The field will false false if {@link #JAVA_VERSION} is + * null.

+ */ + public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4"); + + /** + *

Is true if this is Java version 1.5 (also 1.5.x versions).

+ * + *

The field will return false if {@link #JAVA_VERSION} is + * null.

+ */ + public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5"); + + // Operating system checks + //----------------------------------------------------------------------- + // These MUST be declared after those above as they depend on the + // values being set up + // OS names from http://www.vamphq.com/os.html + // Selected ones included - please advise commons-dev@jakarta.apache.org + // if you want another added or a mistake corrected + + /** + *

Is true if this is AIX.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_AIX = getOSMatches("AIX"); + + /** + *

Is true if this is HP-UX.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX"); + + /** + *

Is true if this is Irix.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_IRIX = getOSMatches("Irix"); + + /** + *

Is true if this is Linux.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX"); + + /** + *

Is true if this is Mac.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_MAC = getOSMatches("Mac"); + + /** + *

Is true if this is Mac.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X"); + + /** + *

Is true if this is OS/2.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_OS2 = getOSMatches("OS/2"); + + /** + *

Is true if this is Solaris.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris"); + + /** + *

Is true if this is SunOS.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); + + /** + *

Is true if this is Windows.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS = getOSMatches("Windows"); + + /** + *

Is true if this is Windows 2000.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS_2000 = getOSMatches("Windows", "5.0"); + + /** + *

Is true if this is Windows 95.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS_95 = getOSMatches("Windows 9", "4.0"); + // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above + + /** + *

Is true if this is Windows 98.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS_98 = getOSMatches("Windows 9", "4.1"); + // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above + + /** + *

Is true if this is Windows ME.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS_ME = getOSMatches("Windows", "4.9"); + // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above + + /** + *

Is true if this is Windows NT.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS_NT = getOSMatches("Windows NT"); + // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem + + /** + *

Is true if this is Windows XP.

+ * + *

The field will return false if OS_NAME is + * null.

+ */ + public static final boolean IS_OS_WINDOWS_XP = getOSMatches("Windows", "5.1"); + // Windows XP returns 'Windows 2000' just for fun... + + //----------------------------------------------------------------------- + /** + *

SystemUtils instances should NOT be constructed in standard + * programming. Instead, the class should be used as + * SystemUtils.FILE_SEPARATOR.

+ * + *

This constructor is public to permit tools that require a JavaBean + * instance to operate.

+ */ + public SystemUtils() { + } + //----------------------------------------------------------------------- /** *

Gets the Java version number as a float.

@@ -654,9 +681,9 @@ *
  • 1.31f for JDK 1.3.1 * * + * @return the version, for example 1.31f for JDK 1.3.1 * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead. * Method will be removed in Commons Lang 3.0. - * @return the version, for example 1.31f for JDK 1.3.1 */ public static float getJavaVersion() { return JAVA_VERSION_FLOAT; @@ -811,17 +838,6 @@ */ public static boolean isJavaVersionAtLeast(int requiredVersion) { return (JAVA_VERSION_INT >= requiredVersion); - } - - /** - *

    SystemUtils instances should NOT be constructed in standard - * programming. Instead, the class should be used as - * SystemUtils.FILE_SEPARATOR.

    - * - *

    This constructor is public to permit tools that require a JavaBean - * instance to operate.

    - */ - public SystemUtils() { } } 1.3 +49 -17 jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java Index: SystemUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SystemUtilsTest.java 24 May 2003 14:34:14 -0000 1.2 +++ SystemUtilsTest.java 21 Jul 2003 22:57:51 -0000 1.3 @@ -64,6 +64,7 @@ * Only limited testing can be performed. * * @author Stephen Colebourne + * @author Tetsuya Kaneuchi * @version $Id$ */ public class SystemUtilsTest extends TestCase { @@ -74,22 +75,6 @@ public static void main(String[] args) { TestRunner.run(suite()); -// SystemUtils s = new SystemUtils(); -// System.out.println(s.IS_OS_WINDOWS); -// System.out.println(s.IS_OS_WINDOWS_95); -// System.out.println(s.IS_OS_WINDOWS_98); -// java.util.Properties p = System.getProperties(); -// java.util.Enumeration keys = p.keys(); -// java.util.List list = new java.util.ArrayList(); -// while( keys.hasMoreElements() ) { -// list.add(keys.nextElement()); -// } -// java.util.Collections.sort(list); -// for (java.util.Iterator it = list.iterator(); it.hasNext();) { -// String key = (String) it.next(); -// System.out.println(key + " " + p.getProperty(key)); -// } - } public static Test suite() { @@ -354,6 +339,53 @@ OS_NAME = "OS/2"; OS_VERSION = "4.0"; assertEquals(false, getOSMatches("Windows 9", "4.1")); + } + + public void testIS_OS() { + String osName = System.getProperty("os.name"); + if (osName == null) { + assertEquals(false, SystemUtils.IS_OS_WINDOWS); + assertEquals(false, SystemUtils.IS_OS_SOLARIS); + assertEquals(false, SystemUtils.IS_OS_LINUX); + assertEquals(false, SystemUtils.IS_OS_MAC_OSX); + } else if (osName.startsWith("Windows")) { + assertTrue(SystemUtils.IS_OS_WINDOWS); + } else if (osName.startsWith("Solaris")) { + assertTrue(SystemUtils.IS_OS_SOLARIS); + } else if (osName.toLowerCase().startsWith("linux")) { + assertTrue(SystemUtils.IS_OS_LINUX); + } else if (osName.startsWith("Mac OS X")) { + assertTrue(SystemUtils.IS_OS_MAC_OSX); + } else if (osName.startsWith("OS/2")) { + assertTrue(SystemUtils.IS_OS_OS2); + } else if (osName.startsWith("SunOS")) { + assertTrue(SystemUtils.IS_OS_SUN_OS); + } else { + System.out.println("Can't test IS_OS value"); + } + } + + public void testIS_JAVA() { + String javaVersion = System.getProperty("java.version"); + if (javaVersion == null) { + assertEquals(false, SystemUtils.IS_JAVA_1_1); + assertEquals(false, SystemUtils.IS_JAVA_1_2); + assertEquals(false, SystemUtils.IS_JAVA_1_3); + assertEquals(false, SystemUtils.IS_JAVA_1_4); + assertEquals(false, SystemUtils.IS_JAVA_1_5); + } else if (javaVersion.startsWith("1.1")) { + assertTrue(SystemUtils.IS_JAVA_1_1); + } else if (javaVersion.startsWith("1.2")) { + assertTrue(SystemUtils.IS_JAVA_1_2); + } else if (javaVersion.startsWith("1.3")) { + assertTrue(SystemUtils.IS_JAVA_1_3); + } else if (javaVersion.startsWith("1.4")) { + assertTrue(SystemUtils.IS_JAVA_1_4); + } else if (javaVersion.startsWith("1.5")) { + assertTrue(SystemUtils.IS_JAVA_1_5); + } else { + System.out.println("Can't test IS_JAVA value"); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org