You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sg...@apache.org on 2016/01/11 18:59:34 UTC

svn commit: r1724101 - in /commons/proper/exec/trunk/src: changes/changes.xml main/java/org/apache/commons/exec/OS.java

Author: sgoeschl
Date: Mon Jan 11 17:59:34 2016
New Revision: 1724101

URL: http://svn.apache.org/viewvc?rev=1724101&view=rev
Log:
[EXEC-100] Sync org.apache.commons.exec.OS with the newest Ant source file

Modified:
    commons/proper/exec/trunk/src/changes/changes.xml
    commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/OS.java

Modified: commons/proper/exec/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/changes/changes.xml?rev=1724101&r1=1724100&r2=1724101&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/changes/changes.xml (original)
+++ commons/proper/exec/trunk/src/changes/changes.xml Mon Jan 11 17:59:34 2016
@@ -24,6 +24,9 @@
     </properties>
     <body>
         <release version="1.4" date="" description="Maintenance and feature Release">
+            <action issue="EXEC-100" dev="sgoeschl" type="update" date="2016-01-11">
+                Sync org.apache.commons.exec.OS with the newest Ant source file
+            </action>
             <action issue="EXEC-64" dev="sebb" type="update" due-to=" Michael Vorburger">
                 DefaultExecutor swallows IOException cause instead of propagating it
                 (work-round for Java 1.5)

Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/OS.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/OS.java?rev=1724101&r1=1724100&r2=1724101&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/OS.java (original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/OS.java Mon Jan 11 17:59:34 2016
@@ -1,21 +1,19 @@
-/* 
+/*
  * 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
+ * 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.
+ *     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.exec;
 
 import java.util.Locale;
@@ -23,40 +21,65 @@ import java.util.Locale;
 /**
  * Condition that tests the OS type.
  *
+ * Copied and adapted from Apache Ant 1.9.6 from org.apache.tools.ant.taskdefs.condition.OS.
  * @version $Id$
  */
 public final class OS {
-    private static final String FAMILY_OS_400 = "os/400";
-
-    private static final String FAMILY_Z_OS = "z/os";
-
-    private static final String FAMILY_WIN9X = "win9x";
-
-    private static final String FAMILY_OPENVMS = "openvms";
-
-    private static final String FAMILY_UNIX = "unix";
-
-    private static final String FAMILY_TANDEM = "tandem";
-
-    private static final String FAMILY_MAC = "mac";
-
-    private static final String FAMILY_DOS = "dos";
-
-    private static final String FAMILY_NETWARE = "netware";
 
-    private static final String FAMILY_OS_2 = "os/2";
-
-    private static final String FAMILY_WINDOWS = "windows";
-
-    private static final String OS_NAME = System.getProperty("os.name")
-            .toLowerCase(Locale.US);
-
-    private static final String OS_ARCH = System.getProperty("os.arch")
-            .toLowerCase(Locale.US);
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_9X = "win9x";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_DOS = "dos";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_MAC = "mac";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_NETWARE = "netware";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_NT = "winnt";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_OS2 = "os/2";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_OS400 = "os/400";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_TANDEM = "tandem";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_UNIX = "unix";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_VMS = "openvms";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_WINDOWS = "windows";
+    /**
+     * OS family that can be tested for. {@value}
+     */
+    public static final String FAMILY_ZOS = "z/os";
 
-    private static final String OS_VERSION = System.getProperty("os.version")
-            .toLowerCase(Locale.US);
+    private static final String DARWIN = "darwin";
 
+    private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
+    private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
+    private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.ENGLISH);
     private static final String PATH_SEP = System.getProperty("path.separator");
 
     /**
@@ -66,23 +89,10 @@ public final class OS {
     }
 
     /**
-     * Determines if the OS on which Ant is executing matches the given OS
-     * family. * Possible values:<br />
-     * <ul>
-     * <li>dos</li>
-     * <li>mac</li>
-     * <li>netware</li>
-     * <li>os/2</li>
-     * <li>tandem</li>
-     * <li>unix</li>
-     * <li>windows</li>
-     * <li>win9x</li>
-     * <li>z/os</li>
-     * <li>os/400</li>
-     * </ul>
-     * 
-     * @param family
-     *            the family to check for
+     * Determines if the OS on which commons-exec is executing matches the
+     * given OS family.
+     *
+     * @param family the family to check for
      * @return true if the OS matches
      */
     private static boolean isFamily(final String family) {
@@ -102,7 +112,7 @@ public final class OS {
     }
 
     public static boolean isFamilyOS2() {
-        return isFamily(FAMILY_OS_2);
+        return isFamily(FAMILY_OS2);
     }
 
     public static boolean isFamilyTandem() {
@@ -118,26 +128,30 @@ public final class OS {
     }
 
     public static boolean isFamilyWin9x() {
-        return isFamily(FAMILY_WIN9X);
+        return isFamily(FAMILY_9X);
+    }
+
+    public static boolean isFamilyWinNT() {
+        return isFamily(FAMILY_NT);
     }
 
     public static boolean isFamilyZOS() {
-        return isFamily(FAMILY_Z_OS);
+        return isFamily(FAMILY_ZOS);
     }
 
     public static boolean isFamilyOS400() {
-        return isFamily(FAMILY_OS_400);
+        return isFamily(FAMILY_OS400);
     }
 
     public static boolean isFamilyOpenVms() {
-        return isFamily(FAMILY_OPENVMS);
+        return isFamily(FAMILY_VMS);
     }
 
     /**
-     * Determines if the OS on which Ant is executing matches the given OS name.
-     * 
-     * @param name
-     *            the OS name to check for
+     * Determines if the OS on which commons-exec is executing matches
+     * the given OS name.
+     *
+     * @param name the OS name to check for
      * @return true if the OS matches
      */
     public static boolean isName(final String name) {
@@ -145,11 +159,10 @@ public final class OS {
     }
 
     /**
-     * Determines if the OS on which Ant is executing matches the given OS
-     * architecture.
-     * 
-     * @param arch
-     *            the OS architecture to check for
+     * Determines if the OS on which commons-exec is executing matches
+     * the given OS architecture.
+     *
+     * @param arch the OS architecture to check for
      * @return true if the OS matches
      */
     public static boolean isArch(final String arch) {
@@ -157,11 +170,10 @@ public final class OS {
     }
 
     /**
-     * Determines if the OS on which Ant is executing matches the given OS
-     * version.
-     * 
-     * @param version
-     *            the OS version to check for
+     * Determines if the OS on which commonss-exec is executing matches
+     * the given OS version.
+     *
+     * @param version the OS version to check for
      * @return true if the OS matches
      */
     public static boolean isVersion(final String version) {
@@ -169,21 +181,17 @@ public final class OS {
     }
 
     /**
-     * Determines if the OS on which Ant is executing matches the given OS
-     * family, name, architecture and version
-     * 
-     * @param family
-     *            The OS family
-     * @param name
-     *            The OS name
-     * @param arch
-     *            The OS architecture
-     * @param version
-     *            The OS version
+     * Determines if the OS on which commons-exec is executing matches the
+     * given OS family, name, architecture and version.
+     *
+     * @param family  The OS family
+     * @param name    The OS name
+     * @param arch    The OS architecture
+     * @param version The OS version
      * @return true if the OS matches
      */
     public static boolean isOs(final String family, final String name,
-            final String arch, final String version) {
+                               final String arch, final String version) {
         boolean retValue = false;
 
         if (family != null || name != null || arch != null || version != null) {
@@ -194,40 +202,54 @@ public final class OS {
             boolean isVersion = true;
 
             if (family != null) {
+                //windows probing logic relies on the word 'windows' in
+                //the OS
+                boolean isWindows = OS_NAME.contains(FAMILY_WINDOWS);
+                boolean is9x = false;
+                boolean isNT = false;
+                if (isWindows) {
+                    //there are only four 9x platforms that we look for
+                    is9x = (OS_NAME.contains("95")
+                            || OS_NAME.contains("98")
+                            || OS_NAME.contains("me")
+                            //wince isn't really 9x, but crippled enough to
+                            //be a muchness. Ant doesn't run on CE, anyway.
+                            || OS_NAME.contains("ce"));
+                    isNT = !is9x;
+                }
                 if (family.equals(FAMILY_WINDOWS)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_WINDOWS) > -1;
-                } else if (family.equals(FAMILY_OS_2)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_OS_2) > -1;
+                    isFamily = isWindows;
+                } else if (family.equals(FAMILY_9X)) {
+                    isFamily = isWindows && is9x;
+                } else if (family.equals(FAMILY_NT)) {
+                    isFamily = isWindows && isNT;
+                } else if (family.equals(FAMILY_OS2)) {
+                    isFamily = OS_NAME.contains(FAMILY_OS2);
                 } else if (family.equals(FAMILY_NETWARE)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_NETWARE) > -1;
+                    isFamily = OS_NAME.contains(FAMILY_NETWARE);
                 } else if (family.equals(FAMILY_DOS)) {
-                    isFamily = PATH_SEP.equals(";")
-                            && !isFamily(FAMILY_NETWARE);
+                    isFamily = PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE);
                 } else if (family.equals(FAMILY_MAC)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_MAC) > -1;
+                    isFamily = OS_NAME.contains(FAMILY_MAC)
+                            || OS_NAME.contains(DARWIN);
                 } else if (family.equals(FAMILY_TANDEM)) {
-                    isFamily = OS_NAME.indexOf("nonstop_kernel") > -1;
+                    isFamily = OS_NAME.contains("nonstop_kernel");
                 } else if (family.equals(FAMILY_UNIX)) {
                     isFamily = PATH_SEP.equals(":")
-                            && !isFamily(FAMILY_OPENVMS)
-                            && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x"));
-                } else if (family.equals(FAMILY_WIN9X)) {
-                    isFamily = isFamily(FAMILY_WINDOWS)
-                            && (OS_NAME.indexOf("95") >= 0
-                                    || OS_NAME.indexOf("98") >= 0
-                                    || OS_NAME.indexOf("me") >= 0 || OS_NAME
-                                    .indexOf("ce") >= 0);
-                } else if (family.equals(FAMILY_Z_OS)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_Z_OS) > -1
-                            || OS_NAME.indexOf("os/390") > -1;
-                } else if (family.equals(FAMILY_OS_400)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_OS_400) > -1;
-                } else if (family.equals(FAMILY_OPENVMS)) {
-                    isFamily = OS_NAME.indexOf(FAMILY_OPENVMS) > -1;
+                            && !isFamily(FAMILY_VMS)
+                            && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x")
+                            || OS_NAME.contains(DARWIN));
+                } else if (family.equals(FAMILY_ZOS)) {
+                    isFamily = OS_NAME.contains(FAMILY_ZOS)
+                            || OS_NAME.contains("os/390");
+                } else if (family.equals(FAMILY_OS400)) {
+                    isFamily = OS_NAME.contains(FAMILY_OS400);
+                } else if (family.equals(FAMILY_VMS)) {
+                    isFamily = OS_NAME.contains(FAMILY_VMS);
                 } else {
-                    throw new IllegalArgumentException(
-                            "Don\'t know how to detect os family \"" + family
-                                    + "\"");
+                    throw new RuntimeException(
+                            "Don\'t know how to detect os family \""
+                                    + family + "\"");
                 }
             }
             if (name != null) {