ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition Os.java
Date Sun, 25 Nov 2001 07:54:28 GMT
umagesh     01/11/24 23:54:28

  Modified:    docs/manual credits.html
               docs/manual/CoreTasks condition.html
               src/main/org/apache/tools/ant/taskdefs/condition Os.java
  Log:
  Added name, arch, version as attributes to Os.
  This would let one to, say, run different things on sparc or x86 solaris...
  
  Revision  Changes    Path
  1.7       +2 -1      jakarta-ant/docs/manual/credits.html
  
  Index: credits.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/credits.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- credits.html	2001/10/30 10:05:33	1.6
  +++ credits.html	2001/11/25 07:54:28	1.7
  @@ -29,6 +29,7 @@
     <li>Sam Ruby (<a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>)</li>
     <li>Nico Seessle (<a href="mailto:nico@seessle.de">nico@seessle.de</a>)</li>
     <li>Jon S. Stevens (<a href="mailto:jon@latchkey.com">jon@latchkey.com</a>)</li>
  +  <li>Magesh Umasankar (<a href="mailto:umagesh@apache.org">umagesh@apache.org</a>)</li>
     <li>Roger Vaughn (<a href="mailto:rvaughn@seaconinc.com">rvaughn@seaconinc.com</a>)</li>
     <li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li>
     <li>Phillip Wells (<a href="mailto:philwells@rocketmail.com">philwells@rocketmail.com</a>)</li>
  @@ -36,7 +37,7 @@
   
   <center>
   <p>Version: @VERSION@<br>
  -$Id: credits.html,v 1.6 2001/10/30 10:05:33 bodewig Exp $</p>
  +$Id: credits.html,v 1.7 2001/11/25 07:54:28 umagesh Exp $</p>
   </center>
   <hr>
   <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All
rights
  
  
  
  1.8       +24 -1     jakarta-ant/docs/manual/CoreTasks/condition.html
  
  Index: condition.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/condition.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- condition.html	2001/11/16 12:30:58	1.7
  +++ condition.html	2001/11/25 07:54:28	1.8
  @@ -91,6 +91,21 @@
       <td valign="top">The name of the operating system family to expect.</td>
       <td valign="top" align="center">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">name</td>
  +    <td valign="top">The name of the operating system to expect.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">arch</td>
  +    <td valign="top">The architecture of the operating system to expect.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">version</td>
  +    <td valign="top">The version of the operating system to expect.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
   </table>
   <p>Supported values for the family attribute are:
   <ul>
  @@ -138,7 +153,7 @@
     </tr>
   </table>
   
  -<h4>checksum</h4> 
  +<h4>checksum</h4>
   
   <p>This condition is identical to the <a
   href="checksum.html">Checksum</a> task, all attributes and nested
  @@ -171,6 +186,14 @@
   <p>sets the property <code>isMacOsButNotMacOsX</code> if the current
   operating system is MacOS, but not MacOS X - which Ant considers to be
   in the Unix family as well.</p>
  +
  +<pre>
  +  &lt;condition property=&quot;isSparc&quot;&gt;
  +    &lt;os arch=&quot;sparc&quot; />
  +  &lt;/condition&gt;
  +</pre>
  +<p>sets the property <code>isSparc</code> if the current
  +operating system is running on a sparc architecture.</p>
   
   <hr>
   <p align="center">Copyright &copy; 2001 Apache Software
  
  
  
  1.7       +125 -22   jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Os.java
  
  Index: Os.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Os.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Os.java	2001/11/22 08:45:03	1.6
  +++ Os.java	2001/11/25 07:54:28	1.7
  @@ -62,14 +62,22 @@
    * Condition that tests the OS type.
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  - * @version $Revision: 1.6 $
  + * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
  + * @version $Revision: 1.7 $
    */
   public class Os implements Condition {
       private static final String osName =
           System.getProperty("os.name").toLowerCase(Locale.US);
  +    private static final String osArch =
  +        System.getProperty("os.arch").toLowerCase(Locale.US);
  +    private static final String osVersion =
  +        System.getProperty("os.version").toLowerCase(Locale.US);
       private static final String pathSep = System.getProperty("path.separator");
   
       private String family;
  +    private String name;
  +    private String version;
  +    private String arch;
   
       public Os() {}
   
  @@ -79,7 +87,7 @@
   
       /**
        * Sets the desired OS family type
  -     * 
  +     *
        * @param f      The OS family type desired<br />
        *               Possible values:<br />
        *               <ul><li>dos</li>
  @@ -91,13 +99,40 @@
        */
       public void setFamily(String f) {family = f.toLowerCase(Locale.US);}
   
  +    /**
  +     * Sets the desired OS name
  +     *
  +     * @param name   The OS name
  +     */
  +    public void setName(String name) {
  +        this.name = name.toLowerCase(Locale.US);
  +    }
  +
       /**
  -     * Determines if the OS on which Ant is executing matches the type of 
  +     * Sets the desired OS architecture
  +     *
  +     * @param arch   The OS architecture
  +     */
  +    public void setArch(String arch) {
  +        this.arch = arch.toLowerCase(Locale.US);
  +    }
  +
  +    /**
  +     * Sets the desired OS version
  +     *
  +     * @param version   The OS version
  +     */
  +    public void setVersion(String version) {
  +        this.version = version.toLowerCase(Locale.US);
  +    }
  +
  +    /**
  +     * Determines if the OS on which Ant is executing matches the type of
        * that set in setFamily.
        * @see Os#setFamily(String)
        */
       public boolean eval() throws BuildException {
  -        return isFamily(family);
  +        return isOs(family, name, arch, version);
       }
   
       /**
  @@ -107,25 +142,93 @@
        * @since 1.5
        */
       public static boolean isFamily(String family) {
  -        if (family != null) {
  -            if (family.equals("windows")) {
  -                return osName.indexOf("windows") > -1;
  -            } else if (family.equals("os/2")) {
  -                return osName.indexOf("os/2") > -1;
  -            } else if (family.equals("netware")) {
  -                return osName.indexOf("netware") > -1;
  -            } else if (family.equals("dos")) {
  -                return pathSep.equals(";") && !isFamily("netware");
  -            } else if (family.equals("mac")) {
  -                return osName.indexOf("mac") > -1;
  -            } else if (family.equals("unix")) {
  -                return pathSep.equals(":")
  -                    && (!isFamily("mac") || osName.endsWith("x"));
  +        return isOs(family, null, null, null);
  +    }
  +
  +    /**
  +     * Determines if the OS on which Ant is executing matches the
  +     * given OS name.
  +     *
  +     * @since 1.7
  +     */
  +    public static boolean isName(String name) {
  +        return isOs(null, name, null, null);
  +    }
  +
  +    /**
  +     * Determines if the OS on which Ant is executing matches the
  +     * given OS architecture.
  +     *
  +     * @since 1.7
  +     */
  +    public static boolean isArch(String arch) {
  +        return isOs(null, null, arch, null);
  +    }
  +
  +    /**
  +     * Determines if the OS on which Ant is executing matches the
  +     * given OS version.
  +     *
  +     * @since 1.7
  +     */
  +    public static boolean isVersion(String version) {
  +        return isOs(null, null, null, version);
  +    }
  +
  +    /**
  +     * 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
  +     *
  +     * @since 1.7
  +     */
  +    public static boolean isOs(String family, String name, String arch,
  +                               String version) {
  +        boolean retValue = false;
  +
  +        if (family != null || name != null || arch != null
  +            || version != null) {
  +
  +            boolean isFamily = true;
  +            boolean isName = true;
  +            boolean isArch = true;
  +            boolean isVersion = true;
  +
  +            if (family != null) {
  +                if (family.equals("windows")) {
  +                    isFamily = osName.indexOf("windows") > -1;
  +                } else if (family.equals("os/2")) {
  +                    isFamily = osName.indexOf("os/2") > -1;
  +                } else if (family.equals("netware")) {
  +                    isFamily = osName.indexOf("netware") > -1;
  +                } else if (family.equals("dos")) {
  +                    isFamily = pathSep.equals(";") && !isFamily("netware");
  +                } else if (family.equals("mac")) {
  +                    isFamily = osName.indexOf("mac") > -1;
  +                } else if (family.equals("unix")) {
  +                    isFamily = pathSep.equals(":")
  +                        && (!isFamily("mac") || osName.endsWith("x"));
  +                } else {
  +                    throw new BuildException(
  +                        "Don\'t know how to detect os family \""
  +                        + family + "\"");
  +                }
  +            }
  +            if (name != null) {
  +                isName = name.equals(osName);
  +            }
  +            if (arch != null) {
  +                isArch = arch.equals(osArch);
               }
  -            throw new BuildException("Don\'t know how to detect os family \""
  -                                     + family + "\"");
  +            if (version != null) {
  +                isVersion = version.equals(osVersion);
  +            }
  +            retValue = isFamily && isName && isArch && isVersion;
           }
  -        return false;
  +        return retValue;
       }
  -
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message