Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 264   Methods: 12
NCLOC: 100   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Os.java 83.3% 73.9% 25% 70.5%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.taskdefs.condition;
 56   
 
 57   
 import java.util.Locale;
 58   
 import org.apache.tools.ant.BuildException;
 59   
 
 60   
 /**
 61   
  * Condition that tests the OS type.
 62   
  *
 63   
  * @author Stefan Bodewig
 64   
  * @author Magesh Umasankar
 65   
  * @since Ant 1.4
 66   
  * @version $Revision: 1.24 $
 67   
  */
 68   
 public class Os implements Condition {
 69   
     private static final String osName =
 70   
         System.getProperty("os.name").toLowerCase(Locale.US);
 71   
     private static final String osArch =
 72   
         System.getProperty("os.arch").toLowerCase(Locale.US);
 73   
     private static final String osVersion =
 74   
         System.getProperty("os.version").toLowerCase(Locale.US);
 75   
     private static final String pathSep = System.getProperty("path.separator");
 76   
 
 77   
     private String family;
 78   
     private String name;
 79   
     private String version;
 80   
     private String arch;
 81   
 
 82  0
     public Os() {}
 83   
 
 84  0
     public Os(String family) {
 85  0
         setFamily(family);
 86   
     }
 87   
 
 88   
     /**
 89   
      * Sets the desired OS family type
 90   
      *
 91   
      * @param f      The OS family type desired<br />
 92   
      *               Possible values:<br />
 93   
      *               <ul>
 94   
      *               <li>dos</li>
 95   
      *               <li>mac</li>
 96   
      *               <li>netware</li>
 97   
      *               <li>os/2</li>
 98   
      *               <li>tandem</li>
 99   
      *               <li>unix</li>
 100   
      *               <li>windows</li>
 101   
      *               <li>win9x</li>
 102   
      *               <li>z/os</li>
 103   
      *               <li>os/400</li>
 104   
      *               </ul>
 105   
      */
 106  0
     public void setFamily(String f) {family = f.toLowerCase(Locale.US);}
 107   
 
 108   
     /**
 109   
      * Sets the desired OS name
 110   
      *
 111   
      * @param name   The OS name
 112   
      */
 113  0
     public void setName(String name) {
 114  0
         this.name = name.toLowerCase(Locale.US);
 115   
     }
 116   
 
 117   
     /**
 118   
      * Sets the desired OS architecture
 119   
      *
 120   
      * @param arch   The OS architecture
 121   
      */
 122  0
     public void setArch(String arch) {
 123  0
         this.arch = arch.toLowerCase(Locale.US);
 124   
     }
 125   
 
 126   
     /**
 127   
      * Sets the desired OS version
 128   
      *
 129   
      * @param version   The OS version
 130   
      */
 131  0
     public void setVersion(String version) {
 132  0
         this.version = version.toLowerCase(Locale.US);
 133   
     }
 134   
 
 135   
     /**
 136   
      * Determines if the OS on which Ant is executing matches the type of
 137   
      * that set in setFamily.
 138   
      * @see Os#setFamily(String)
 139   
      */
 140  0
     public boolean eval() throws BuildException {
 141  0
         return isOs(family, name, arch, version);
 142   
     }
 143   
 
 144   
     /**
 145   
      * Determines if the OS on which Ant is executing matches the
 146   
      * given OS family.
 147   
      *
 148   
      * @since 1.5
 149   
      */
 150  46223
     public static boolean isFamily(String family) {
 151  46223
         return isOs(family, null, null, null);
 152   
     }
 153   
 
 154   
     /**
 155   
      * Determines if the OS on which Ant is executing matches the
 156   
      * given OS name.
 157   
      *
 158   
      * @since 1.7
 159   
      */
 160  4
     public static boolean isName(String name) {
 161  4
         return isOs(null, name, null, null);
 162   
     }
 163   
 
 164   
     /**
 165   
      * Determines if the OS on which Ant is executing matches the
 166   
      * given OS architecture.
 167   
      *
 168   
      * @since 1.7
 169   
      */
 170  0
     public static boolean isArch(String arch) {
 171  0
         return isOs(null, null, arch, null);
 172   
     }
 173   
 
 174   
     /**
 175   
      * Determines if the OS on which Ant is executing matches the
 176   
      * given OS version.
 177   
      *
 178   
      * @since 1.7
 179   
      */
 180  0
     public static boolean isVersion(String version) {
 181  0
         return isOs(null, null, null, version);
 182   
     }
 183   
 
 184   
     /**
 185   
      * Determines if the OS on which Ant is executing matches the
 186   
      * given OS family, name, architecture and version
 187   
      *
 188   
      * @param family   The OS family
 189   
      * @param name   The OS name
 190   
      * @param arch   The OS architecture
 191   
      * @param version   The OS version
 192   
      *
 193   
      * @since 1.7
 194   
      */
 195  46227
     public static boolean isOs(String family, String name, String arch,
 196   
                                String version) {
 197  46227
         boolean retValue = false;
 198   
 
 199  46227
         if (family != null || name != null || arch != null
 200   
             || version != null) {
 201   
 
 202  46227
             boolean isFamily = true;
 203  46227
             boolean isName = true;
 204  46227
             boolean isArch = true;
 205  46227
             boolean isVersion = true;
 206   
 
 207  46227
             if (family != null) {
 208  46223
                 if (family.equals("windows")) {
 209  102
                     isFamily = osName.indexOf("windows") > -1;
 210  46121
                 } else if (family.equals("os/2")) {
 211  2
                     isFamily = osName.indexOf("os/2") > -1;
 212  46119
                 } else if (family.equals("netware")) {
 213  23905
                     isFamily = osName.indexOf("netware") > -1;
 214  22214
                 } else if (family.equals("dos")) {
 215  22165
                     isFamily = pathSep.equals(";") && !isFamily("netware");
 216  49
                 } else if (family.equals("mac")) {
 217  36
                     isFamily = osName.indexOf("mac") > -1;
 218  13
                 } else if (family.equals("tandem")) {
 219  1
                     isFamily = osName.indexOf("nonstop_kernel") > -1;
 220  12
                 } else if (family.equals("unix")) {
 221  9
                     isFamily = pathSep.equals(":")
 222   
                         && (!isFamily("mac") || osName.endsWith("x"));
 223  3
                 } else if (family.equals("win9x")) {
 224  0
                     isFamily = isFamily("windows") &&
 225   
                         /*
 226   
                          * FIXME
 227   
                          *
 228   
                          * Need a better way to know which one runs CMD.EXE
 229   
                          * and wich COMMAND.COM.
 230   
                          *
 231   
                          * If we use a fixed list of names, we should rather
 232   
                          * use one for all win9x flavors as it is supposed to
 233   
                          * be a final list.
 234   
                          */
 235   
                         !(osName.indexOf("nt") >= 0 ||
 236   
                           osName.indexOf("2000") >= 0 ||
 237   
                           osName.indexOf("2003") >= 0 ||
 238   
                           osName.indexOf("xp") >= 0);
 239  3
                 } else if (family.equals("z/os")) {
 240  2
                     isFamily = osName.indexOf("z/os") > -1
 241   
                         || osName.indexOf("os/390") > -1;
 242  1
                 } else if (family.equals("os/400")) {
 243  1
                     isFamily = osName.indexOf("os/400") > -1;
 244   
                 } else {
 245  0
                     throw new BuildException(
 246   
                         "Don\'t know how to detect os family \""
 247   
                         + family + "\"");
 248   
                 }
 249   
             }
 250  46227
             if (name != null) {
 251  4
                 isName = name.equals(osName);
 252   
             }
 253  46227
             if (arch != null) {
 254  0
                 isArch = arch.equals(osArch);
 255   
             }
 256  46227
             if (version != null) {
 257  0
                 isVersion = version.equals(osVersion);
 258   
             }
 259  46227
             retValue = isFamily && isName && isArch && isVersion;
 260   
         }
 261  46227
         return retValue;
 262   
     }
 263   
 }
 264