Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 262   Methods: 17
NCLOC: 109   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Chmod.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-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;
 56   
 
 57   
 import java.io.File;
 58   
 import java.io.IOException;
 59   
 import org.apache.tools.ant.BuildException;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.taskdefs.condition.Os;
 62   
 import org.apache.tools.ant.types.Commandline;
 63   
 import org.apache.tools.ant.types.FileSet;
 64   
 import org.apache.tools.ant.types.PatternSet;
 65   
 
 66   
 /**
 67   
  * Chmod equivalent for unix-like environments.
 68   
  *
 69   
  * @author costin@eng.sun.com
 70   
  * @author Mariusz Nowostawski (Marni)
 71   
  *         <a href="mailto:mnowostawski@infoscience.otago.ac.nz">mnowostawski@infoscience.otago.ac.nz</a>
 72   
  * @author Stefan Bodewig
 73   
  *
 74   
  * @since Ant 1.1
 75   
  *
 76   
  * @ant.task category="filesystem"
 77   
  * @todo Refactor so it does not extend from ExecuteOn and then turn around
 78   
  *       and unsupport several attributes.
 79   
  */
 80   
 public class Chmod extends ExecuteOn {
 81   
 
 82   
     private FileSet defaultSet = new FileSet();
 83   
     private boolean defaultSetDefined = false;
 84   
     private boolean havePerm = false;
 85   
 
 86   
     /**
 87   
      * Chmod task for setting file and directory permissions.
 88   
      */
 89  0
     public Chmod() {
 90  0
         super.setExecutable("chmod");
 91  0
         super.setParallel(true);
 92  0
         super.setSkipEmptyFilesets(true);
 93   
     }
 94   
 
 95   
     /**
 96   
      * @see org.apache.tools.ant.ProjectComponent#setProject
 97   
      */
 98  0
     public void setProject(Project project) {
 99  0
         super.setProject(project);
 100  0
         defaultSet.setProject(project);
 101   
     }
 102   
 
 103   
     /**
 104   
      * The file or single directory of which the permissions must be changed.
 105   
      * @param src
 106   
      */
 107  0
     public void setFile(File src) {
 108  0
         FileSet fs = new FileSet();
 109  0
         fs.setFile(src);
 110  0
         addFileset(fs);
 111   
     }
 112   
 
 113   
     /**
 114   
      * The directory which holds the files whose permissions must be changed.
 115   
      * @param src
 116   
      */
 117  0
     public void setDir(File src) {
 118  0
         defaultSet.setDir(src);
 119   
     }
 120   
 
 121   
     /**
 122   
      * The new permissions.
 123   
      * @param perm
 124   
      */
 125  0
     public void setPerm(String perm) {
 126  0
         createArg().setValue(perm);
 127  0
         havePerm = true;
 128   
     }
 129   
 
 130   
     /**
 131   
      * Add a name entry on the include list.
 132   
      */
 133  0
     public PatternSet.NameEntry createInclude() {
 134  0
         defaultSetDefined = true;
 135  0
         return defaultSet.createInclude();
 136   
     }
 137   
 
 138   
     /**
 139   
      * Add a name entry on the exclude list.
 140   
      */
 141  0
     public PatternSet.NameEntry createExclude() {
 142  0
         defaultSetDefined = true;
 143  0
         return defaultSet.createExclude();
 144   
     }
 145   
 
 146   
     /**
 147   
      * Add a set of patterns.
 148   
      */
 149  0
     public PatternSet createPatternSet() {
 150  0
         defaultSetDefined = true;
 151  0
         return defaultSet.createPatternSet();
 152   
     }
 153   
 
 154   
     /**
 155   
      * Sets the set of include patterns. Patterns may be separated by a comma
 156   
      * or a space.
 157   
      *
 158   
      * @param includes the string containing the include patterns
 159   
      */
 160  0
     public void setIncludes(String includes) {
 161  0
         defaultSetDefined = true;
 162  0
         defaultSet.setIncludes(includes);
 163   
     }
 164   
 
 165   
     /**
 166   
      * Sets the set of exclude patterns. Patterns may be separated by a comma
 167   
      * or a space.
 168   
      *
 169   
      * @param excludes the string containing the exclude patterns
 170   
      */
 171  0
     public void setExcludes(String excludes) {
 172  0
         defaultSetDefined = true;
 173  0
         defaultSet.setExcludes(excludes);
 174   
     }
 175   
 
 176   
     /**
 177   
      * Sets whether default exclusions should be used or not.
 178   
      *
 179   
      * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
 180   
      *                           should be used, "false"|"off"|"no" when they
 181   
      *                           shouldn't be used.
 182   
      */
 183  0
     public void setDefaultexcludes(boolean useDefaultExcludes) {
 184  0
         defaultSetDefined = true;
 185  0
         defaultSet.setDefaultexcludes(useDefaultExcludes);
 186   
     }
 187   
 
 188  0
     protected void checkConfiguration() {
 189  0
         if (!havePerm) {
 190  0
             throw new BuildException("Required attribute perm not set in chmod",
 191   
                                      getLocation());
 192   
         }
 193   
 
 194  0
         if (defaultSetDefined && defaultSet.getDir(getProject()) != null) {
 195  0
             addFileset(defaultSet);
 196   
         }
 197  0
         super.checkConfiguration();
 198   
     }
 199   
 
 200  0
     public void execute() throws BuildException {
 201   
         /*
 202   
          * In Ant 1.1, <chmod dir="foo" /> means, change the permissions
 203   
          * of directory foo, not anything inside of it.  This is the case the
 204   
          * second branch of the if statement below catches for backwards
 205   
          * compatibility.
 206   
          */
 207  0
         if (defaultSetDefined || defaultSet.getDir(getProject()) == null) {
 208  0
             try {
 209  0
                 super.execute();
 210   
             } finally {
 211  0
                 if (defaultSetDefined && defaultSet.getDir(getProject()) != null) {
 212  0
                     filesets.removeElement(defaultSet);
 213   
                 }
 214   
             }
 215  0
         } else if (isValidOs()) {
 216   
             // we are chmodding the given directory
 217  0
             Execute execute = prepareExec();
 218  0
             Commandline cloned = (Commandline) cmdl.clone();
 219  0
             cloned.createArgument().setValue(defaultSet.getDir(getProject())
 220   
                                              .getPath());
 221  0
             try {
 222  0
                 execute.setCommandline(cloned.getCommandline());
 223  0
                 runExecute(execute);
 224   
             } catch (IOException e) {
 225  0
                 throw new BuildException("Execute failed: " + e, e, getLocation());
 226   
             } finally {
 227   
                 // close the output file if required
 228  0
                 logFlush();
 229   
             }
 230   
         }
 231   
     }
 232   
 
 233   
     /**
 234   
      * @ant.attribute ignore="true"
 235   
      */
 236  0
     public void setExecutable(String e) {
 237  0
         throw new BuildException(getTaskType()
 238   
             + " doesn\'t support the executable attribute", getLocation());
 239   
     }
 240   
 
 241   
     /**
 242   
      * @ant.attribute ignore="true"
 243   
      */
 244  0
     public void setCommand(Commandline cmdl) {
 245  0
         throw new BuildException(getTaskType()
 246   
             + " doesn\'t support the command attribute", getLocation());
 247   
     }
 248   
 
 249   
     /**
 250   
      * @ant.attribute ignore="true"
 251   
      */
 252  0
     public void setSkipEmptyFilesets(boolean skip) {
 253  0
         throw new BuildException(getTaskType()
 254   
             + " doesn\'t support the skipemptyfileset attribute", getLocation());
 255   
     }
 256   
 
 257  0
     protected boolean isValidOs() {
 258  0
         return (Os.isFamily("unix") || Os.isFamily("tandem")) 
 259   
             && super.isValidOs();
 260   
     }
 261   
 }
 262