Add IS_OS_UNIX to SystemUtils

from Rafal Krupinski


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-10-07 20:59:46 +00:00
parent 77f44ba271
commit 0ae8741d3b
3 changed files with 42 additions and 8 deletions

View File

@ -266,6 +266,14 @@
<role>Java Developer</role> <role>Java Developer</role>
</roles> </roles>
</contributor> </contributor>
<contributor>
<name>Rafal Krupinski</name>
<email></email>
<organization></organization>
<roles>
<role>Java Developer</role>
</roles>
</contributor>
<contributor> <contributor>
<name>Rafal Krzewski</name> <name>Rafal Krzewski</name>
<email></email> <email></email>

View File

@ -67,8 +67,9 @@
* @author Gary Gregory * @author Gary Gregory
* @author Michael Becke * @author Michael Becke
* @author Tetsuya Kaneuchi * @author Tetsuya Kaneuchi
* @author Rafal Krupinski
* @since 1.0 * @since 1.0
* @version $Id: SystemUtils.java,v 1.23 2003/08/22 16:34:06 ggregory Exp $ * @version $Id: SystemUtils.java,v 1.24 2003/10/07 20:59:46 scolebourne Exp $
*/ */
public class SystemUtils { public class SystemUtils {
@ -626,6 +627,19 @@ public class SystemUtils {
*/ */
public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS");
/**
* <p>Is <code>true</code> if this is POSIX compilant system,
* ie. any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.</p>
*
* <p>The field will return <code>false</code> if <code>OS_NAME</code> is
* <code>null</code>.</p>
*
* @since 2.1
*/
public static final boolean IS_OS_UNIX =
IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX ||
IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS;
/** /**
* <p>Is <code>true</code> if this is Windows.</p> * <p>Is <code>true</code> if this is Windows.</p>
* *

View File

@ -68,7 +68,7 @@
* *
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Tetsuya Kaneuchi * @author Tetsuya Kaneuchi
* @version $Id: SystemUtilsTest.java,v 1.6 2003/08/18 02:22:25 bayard Exp $ * @version $Id: SystemUtilsTest.java,v 1.7 2003/10/07 20:59:46 scolebourne Exp $
*/ */
public class SystemUtilsTest extends TestCase { public class SystemUtilsTest extends TestCase {
@ -363,21 +363,33 @@ public void testIS_OS() {
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
if (osName == null) { if (osName == null) {
assertEquals(false, SystemUtils.IS_OS_WINDOWS); assertEquals(false, SystemUtils.IS_OS_WINDOWS);
assertEquals(false, SystemUtils.IS_OS_UNIX);
assertEquals(false, SystemUtils.IS_OS_SOLARIS); assertEquals(false, SystemUtils.IS_OS_SOLARIS);
assertEquals(false, SystemUtils.IS_OS_LINUX); assertEquals(false, SystemUtils.IS_OS_LINUX);
assertEquals(false, SystemUtils.IS_OS_MAC_OSX); assertEquals(false, SystemUtils.IS_OS_MAC_OSX);
} else if (osName.startsWith("Windows")) { } else if (osName.startsWith("Windows")) {
assertTrue(SystemUtils.IS_OS_WINDOWS); assertEquals(false, SystemUtils.IS_OS_UNIX);
assertEquals(true, SystemUtils.IS_OS_WINDOWS);
} else if (osName.startsWith("Solaris")) { } else if (osName.startsWith("Solaris")) {
assertTrue(SystemUtils.IS_OS_SOLARIS); assertEquals(true, SystemUtils.IS_OS_SOLARIS);
assertEquals(true, SystemUtils.IS_OS_UNIX);
assertEquals(false, SystemUtils.IS_OS_WINDOWS);
} else if (osName.toLowerCase().startsWith("linux")) { } else if (osName.toLowerCase().startsWith("linux")) {
assertTrue(SystemUtils.IS_OS_LINUX); assertEquals(true, SystemUtils.IS_OS_LINUX);
assertEquals(true, SystemUtils.IS_OS_UNIX);
assertEquals(false, SystemUtils.IS_OS_WINDOWS);
} else if (osName.startsWith("Mac OS X")) { } else if (osName.startsWith("Mac OS X")) {
assertTrue(SystemUtils.IS_OS_MAC_OSX); assertEquals(true, SystemUtils.IS_OS_MAC_OSX);
assertEquals(true, SystemUtils.IS_OS_UNIX);
assertEquals(false, SystemUtils.IS_OS_WINDOWS);
} else if (osName.startsWith("OS/2")) { } else if (osName.startsWith("OS/2")) {
assertTrue(SystemUtils.IS_OS_OS2); assertEquals(true, SystemUtils.IS_OS_OS2);
assertEquals(false, SystemUtils.IS_OS_UNIX);
assertEquals(false, SystemUtils.IS_OS_WINDOWS);
} else if (osName.startsWith("SunOS")) { } else if (osName.startsWith("SunOS")) {
assertTrue(SystemUtils.IS_OS_SUN_OS); assertEquals(true, SystemUtils.IS_OS_SUN_OS);
assertEquals(true, SystemUtils.IS_OS_UNIX);
assertEquals(false, SystemUtils.IS_OS_WINDOWS);
} else { } else {
System.out.println("Can't test IS_OS value"); System.out.println("Can't test IS_OS value");
} }