commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r767124 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/os/darwin/ main/native/os/hpux/ main/native/os/linux/ main/native/os/solaris/ main/native/os/win32/ test/org/apache/commons/runtime/
Date Tue, 21 Apr 2009 12:30:32 GMT
Author: mturk
Date: Tue Apr 21 12:30:32 2009
New Revision: 767124

URL: http://svn.apache.org/viewvc?rev=767124&view=rev
Log:
Add OsType Enum instead native is() and IS_XXX static fields

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java   (with
props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OS.java Tue Apr
21 12:30:32 2009
@@ -16,6 +16,8 @@
 
 package org.apache.commons.runtime;
 
+import java.util.EnumSet;
+
 /** Operating system type and version info.
  *
  * @since Runtime 1.0
@@ -28,57 +30,16 @@
         // No class instance
     }
 
-    /* OS Enums */
-    private static final int WINDOWS       = 0x1000;
-    private static final int WIN64         = 0x1001;
-    private static final int WOW64         = 0x1002;
-    private static final int UNIX          = 0x2000;
-    private static final int LINUX         = 0x2001;
-    private static final int SOLARIS       = 0x2002;
-    private static final int DARWIN        = 0x2004;
-    private static final int HPUX          = 0x2008;
-
-    /**
-     * Check for OS type.
+    /*
+     * Get OS type.
      * @param type OS type to test.
      */
-    private static native boolean is(int type);
+    private static native int type();
 
     /**
-     * True if the operating system is unix family
-     * operating system.
-     */
-    public static final boolean IS_UNIX    = is(UNIX);
-    /**
-     * True if the operating system is Microsoft Windows family
-     * operating system.
-     */
-    public static final boolean IS_WINDOWS = is(WINDOWS);
-    /**
-     * True if the operating system is Microsoft Windows 64.
-     */
-    public static final boolean IS_WIN64   = is(WIN64);
-    /**
-     * True if the operating system is Microsoft Windows 64
-     * running 32-bit JVM.
-     */
-    public static final boolean IS_WOW64   = is(WOW64);
-    /**
-     * True if the operating system is Linux.
-     */
-    public static final boolean IS_LINUX   = is(LINUX);
-    /**
-     * True if the operating system is Sun Solaris.
-     */
-    public static final boolean IS_SOLARIS = is(SOLARIS);
-    /**
-     * True if the operating system is Mac OS X.
-     */
-    public static final boolean IS_DARWIN  = is(DARWIN);
-    /**
-     * True if the operating system is HP-UX.
+     * Operating system type {@code EnumSet}.
      */
-    public static final boolean IS_HPUX    = is(HPUX);
+    public static final EnumSet<OsType> TYPE = OsType.valueOf(type());
 
     /**
      * Name of the operating system implementation.

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java?rev=767124&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java Tue
Apr 21 12:30:32 2009
@@ -0,0 +1,120 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import java.util.EnumSet;
+
+/**
+ * Operating system type Enum.
+ */
+public enum OsType
+{
+    /** 
+     * Operating system is Microsoft Windows family
+     * operating system..
+     * <br/>Defined integer value is: {@code 0x1000}
+     */
+    WINDOWS(    0x1000),
+
+    /** 
+     * Operating system is Microsoft Windows 64.
+     * <br/>Defined integer value is: {@code 0x1001}
+     */
+    WIN64(      0x1001),
+
+    /** 
+     * Operating system is Microsoft Windows 64 running 32-bit JVM.
+     * <br/>Defined integer value is: {@code 0x1002}
+     */
+    WOW64(      0x1002),
+
+    /**
+     * Operating system is unix family operating system.
+     * <br/>Defined integer value is: {@code 0x2000}
+     */
+    UNIX(       0x2000),
+
+    /** 
+     * Operating system is Linux.
+     * <br/>Defined integer value is: {@code 0x2001}
+     */
+    LINUX(      0x2001),
+
+    /** 
+     * Operating system is Sun Solaris.
+     * <br/>Defined integer value is: {@code 0x2002}
+     */
+    SOLARIS(    0x2002),
+
+    /** 
+     * Operating system is Apple Mac OS X.
+     * <br/>Defined integer value is: {@code 0x2004}
+     */
+    DARWIN(     0x2004),
+
+    /** 
+     * Operating system is Hewlett Packard HP-UX.
+     * <br/>Defined integer value is: {@code 0x2008}
+     */
+    HPUX(       0x2008);
+
+
+    private int value;
+    private OsType(int v)
+    {
+        value = v;
+    }
+
+    /** 
+     * Integer representing the value of this Enum.
+     */
+    public int valueOf()
+    {
+        return value;
+    }
+
+    /** 
+     * Integer representing the sum of the integer values
+     * of the {@code OsType} enums.
+     * @param set The {@code EnumSet} which values to get.
+     */
+    public static int bitmapOf(EnumSet<OsType> set)
+    {
+        int bitmap = 0;
+        if (set != null) {
+            for (OsType t : set)
+                bitmap += t.valueOf();
+        }
+        return bitmap;
+    }
+
+    /** 
+     * Returns {@code EnumSet} of {@code OsType} enums
+     * from the integer bitmap value.
+     * @param value Integer used to construct the {@code EnumSet}
+     * with {@code OsType} values mathching the value flags.
+     */
+    public static EnumSet<OsType> valueOf(int value)
+    {
+        EnumSet<OsType> set = EnumSet.noneOf(OsType.class);
+        for (OsType e : values()) {
+            if ((e.value & value) == e.value)
+                set.add(e);
+        }
+        return set;
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c Tue Apr 21 12:30:32 2009
@@ -22,17 +22,6 @@
 #define MAXSIZESYSSTRING 256
 static const char unknown[] = "unknown";
 
-ACR_JNI_EXPORT_DECLARE(jboolean, OS, is)(ACR_JNISTDARGS, jint type)
-{
-    UNREFERENCED_STDARGS;
-    if (type == ACR_OS_UNIX)
-        return JNI_TRUE;
-    else if (type == ACR_OS_DARWIN)
-        return JNI_TRUE;
-    else
-        return JNI_FALSE;
-}
-
 ACR_JNI_EXPORT_DECLARE(jint, OS, type)(ACR_JNISTDARGS)
 {
     UNREFERENCED_STDARGS;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c Tue Apr 21 12:30:32 2009
@@ -22,17 +22,6 @@
 #define MAXSIZESYSSTRING 256
 static const char unknown[] = "unknown";
 
-ACR_JNI_EXPORT_DECLARE(jboolean, OS, is)(ACR_JNISTDARGS, jint type)
-{
-    UNREFERENCED_STDARGS;
-    if (type == ACR_OS_UNIX)
-        return JNI_TRUE;
-    else if (type == ACR_OS_HPUX)
-        return JNI_TRUE;
-    else
-        return JNI_FALSE;
-}
-
 ACR_JNI_EXPORT_DECLARE(jint, OS, type)(ACR_JNISTDARGS)
 {
     UNREFERENCED_STDARGS;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c Tue Apr 21 12:30:32 2009
@@ -22,17 +22,6 @@
 #define MAXSIZESYSSTRING 256
 static const char unknown[] = "unknown";
 
-ACR_JNI_EXPORT_DECLARE(jboolean, OS, is)(ACR_JNISTDARGS, jint type)
-{
-    UNREFERENCED_STDARGS;
-    if (type == ACR_OS_UNIX)
-        return JNI_TRUE;
-    else if (type == ACR_OS_LINUX)
-        return JNI_TRUE;
-    else
-        return JNI_FALSE;
-}
-
 ACR_JNI_EXPORT_DECLARE(jint, OS, type)(ACR_JNISTDARGS)
 {
     UNREFERENCED_STDARGS;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c Tue Apr 21 12:30:32 2009
@@ -22,17 +22,6 @@
 #define MAXSIZESYSSTRING 256
 static const char unknown[] = "unknown";
 
-ACR_JNI_EXPORT_DECLARE(jboolean, OS, is)(ACR_JNISTDARGS, jint type)
-{
-    UNREFERENCED_STDARGS;
-    if (type == ACR_OS_UNIX)
-        return JNI_TRUE;
-    else if (type == ACR_OS_SOLARIS)
-        return JNI_TRUE;
-    else
-        return JNI_FALSE;
-}
-
 ACR_JNI_EXPORT_DECLARE(jint, OS, type)(ACR_JNISTDARGS)
 {
     UNREFERENCED_STDARGS;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c Tue Apr 21 12:30:32 2009
@@ -25,32 +25,20 @@
 
 static const char unknown[] = "unknown";
 
-ACR_JNI_EXPORT_DECLARE(jboolean, OS, is)(ACR_JNISTDARGS, jint type)
-{
-    UNREFERENCED_STDARGS;
-#ifdef _WIN64
-    if (type == ACR_OS_WIN64)
-        return JNI_TRUE;
-    else
-#endif
-    if (type == ACR_OS_WINDOWS)
-        return JNI_TRUE;
-    else if (type == ACR_OS_WOW64) {
-        BOOL is = FALSE;
-        IsWow64Process(GetCurrentProcess(), &is);
-        return V2Z(is);
-    }
-    else
-        return JNI_FALSE;
-}
-
 ACR_JNI_EXPORT_DECLARE(jint, OS, type)(ACR_JNISTDARGS)
 {
-    UNREFERENCED_STDARGS;
 #ifdef _WIN64
+    UNREFERENCED_STDARGS;
     return ACR_OS_WIN64;
 #else
-    return ACR_OS_WINDOWS;
+    BOOL isWow64 = FALSE;
+
+    UNREFERENCED_STDARGS;
+    IsWow64Process(GetCurrentProcess(), &isWow64);
+    if (isWow64)
+        return ACR_WOW64;
+    else
+        return ACR_OS_WINDOWS;
 #endif
 }
 

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Tue Apr
21 12:30:32 2009
@@ -51,13 +51,13 @@
         throws Exception
     {
         File f;
-        if (OS.IS_UNIX)
+        if (OS.TYPE.contains(OsType.UNIX))
             f = new File("/etc/hosts");
         else
             f = new File("C:\\Windows\\win.ini");
 
         FileType t = f.getFileType();
-        if (OS.IS_SOLARIS)
+        if (OS.TYPE.contains(OsType.SOLARIS))
             assertEquals("Type", FileType.LNK, t);
         else
             assertEquals("Type", FileType.REG, t);

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java Tue Apr
21 12:30:32 2009
@@ -40,8 +40,8 @@
     public void testOS()
         throws Exception
     {
-        boolean win = OS.IS_WINDOWS;
-        boolean unx = OS.IS_UNIX;
+        boolean win = OS.TYPE.contains(OsType.WINDOWS);
+        boolean unx = OS.TYPE.contains(OsType.UNIX);
         assertTrue("Unix or Windows not defined", win | unx);
         assertFalse("Unix and Windows defined", win & unx);
         assertNotNull("Sysname " + OS.getSysname());
@@ -49,6 +49,7 @@
         /* The following are just for display purpose */
         System.out.println("");
         System.out.println("Name       " + OS.getSysname());
+        System.out.println("Type       " + OS.TYPE);
         System.out.println("Node       " + OS.getNodename());
         System.out.println("Release    " + OS.getRelease());
         System.out.println("Version    " + OS.getVersion());

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=767124&r1=767123&r2=767124&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Tue
Apr 21 12:30:32 2009
@@ -536,7 +536,7 @@
         throws Throwable
     {
         File f = test029(0);
-        if (OS.IS_UNIX)
+        if (OS.TYPE.contains(OsType.UNIX))
             assertEquals("Pathname", "/tmp/foo", f.getPath());
         else
             assertEquals("Pathname", "\\tmp\\foo", f.getPath());



Mime
View raw message