Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 242   Methods: 12
NCLOC: 88   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CallTarget.java 16.7% 36.8% 25% 29.4%
 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 org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.Task;
 59   
 import java.io.IOException;
 60   
 
 61   
 /**
 62   
  * Call another target in the same project.
 63   
  *
 64   
  *  <pre>
 65   
  *    &lt;target name="foo"&gt;
 66   
  *      &lt;antcall target="bar"&gt;
 67   
  *        &lt;param name="property1" value="aaaaa" /&gt;
 68   
  *        &lt;param name="foo" value="baz" /&gt;
 69   
  *       &lt;/antcall&gt;
 70   
  *    &lt;/target&gt;
 71   
  *
 72   
  *    &lt;target name="bar" depends="init"&gt;
 73   
  *      &lt;echo message="prop is ${property1} ${foo}" /&gt;
 74   
  *    &lt;/target&gt;
 75   
  * </pre>
 76   
  *
 77   
  * <p>This only works as expected if neither property1 nor foo are
 78   
  * defined in the project itself.
 79   
  *
 80   
  *
 81   
  * @author Stefan Bodewig 
 82   
  *
 83   
  * @since Ant 1.2
 84   
  *
 85   
  * @ant.task name="antcall" category="control"
 86   
  */
 87   
 public class CallTarget extends Task {
 88   
 
 89   
     private Ant callee;
 90   
     private String subTarget;
 91   
     // must match the default value of Ant#inheritAll
 92   
     private boolean inheritAll = true;
 93   
     // must match the default value of Ant#inheritRefs
 94   
     private boolean inheritRefs = false;
 95   
 
 96   
     /**
 97   
      * If true, pass all properties to the new Ant project.
 98   
      * Defaults to true.
 99   
      */
 100  0
     public void setInheritAll(boolean inherit) {
 101  0
        inheritAll = inherit;
 102   
     }
 103   
 
 104   
     /**
 105   
      * If true, pass all references to the new Ant project.
 106   
      * Defaults to false
 107   
      * @param inheritRefs new value
 108   
      */
 109  0
     public void setInheritRefs(boolean inheritRefs) {
 110  0
         this.inheritRefs = inheritRefs;
 111   
     }
 112   
 
 113   
     /**
 114   
      * init this task by creating new instance of the ant task and
 115   
      * configuring it's by calling its own init method.
 116   
      */
 117  4
     public void init() {
 118  4
         callee = (Ant) getProject().createTask("ant");
 119  4
         callee.setOwningTarget(getOwningTarget());
 120  4
         callee.setTaskName(getTaskName());
 121  4
         callee.setLocation(getLocation());
 122  4
         callee.init();
 123   
     }
 124   
 
 125   
     /**
 126   
      * hand off the work to the ant task of ours, after setting it up
 127   
      * @throws BuildException on validation failure or if the target didn't
 128   
      * execute
 129   
      */
 130  4
     public void execute() throws BuildException {
 131  4
         if (callee == null) {
 132  0
             init();
 133   
         }
 134   
         
 135  4
         if (subTarget == null) {
 136  1
             throw new BuildException("Attribute target is required.", 
 137   
                                      getLocation());
 138   
         }
 139   
         
 140  3
         callee.setAntfile(getProject().getProperty("ant.file"));
 141  3
         callee.setTarget(subTarget);
 142  2
         callee.setInheritAll(inheritAll);
 143  2
         callee.setInheritRefs(inheritRefs);
 144  2
         callee.execute();
 145   
     }
 146   
 
 147   
     /**
 148   
      * Property to pass to the invoked target.
 149   
      */
 150  0
     public Property createParam() {
 151  0
         if (callee == null) {
 152  0
             init();
 153   
         }
 154  0
         return callee.createProperty();
 155   
     }
 156   
 
 157   
     /**
 158   
      * Reference element identifying a data type to carry
 159   
      * over to the invoked target.
 160   
      * @since Ant 1.5
 161   
      */
 162  0
     public void addReference(Ant.Reference r) {
 163  0
         if (callee == null) {
 164  0
             init();
 165   
         }
 166  0
         callee.addReference(r);
 167   
     }
 168   
 
 169   
     /**
 170   
      * Target to execute, required.
 171   
      */
 172  3
     public void setTarget(String target) {
 173  3
         subTarget = target;
 174   
     }
 175   
 
 176   
     /**
 177   
      * Pass output sent to System.out to the new project.
 178   
      *
 179   
      * @since Ant 1.5
 180   
      */
 181  0
     public void handleOutput(String line) {
 182  0
         if (callee != null) {
 183  0
             callee.handleOutput(line);
 184   
         } else {
 185  0
             super.handleOutput(line);
 186   
         }
 187   
     }
 188   
     
 189   
     /**
 190   
      * @see Task#handleInput(byte[], int, int)
 191   
      * 
 192   
      * @since Ant 1.6
 193   
      */
 194  0
     public int handleInput(byte[] buffer, int offset, int length) 
 195   
         throws IOException {
 196  0
         if (callee != null) {
 197  0
             return callee.handleInput(buffer, offset, length);
 198   
         } else {
 199  0
             return super.handleInput(buffer, offset, length);
 200   
         }
 201   
     }
 202   
 
 203   
     /**
 204   
      * Pass output sent to System.out to the new project.
 205   
      *
 206   
      * @since Ant 1.5.2
 207   
      */
 208  0
     public void handleFlush(String line) {
 209  0
         if (callee != null) {
 210  0
             callee.handleFlush(line);
 211   
         } else {
 212  0
             super.handleFlush(line);
 213   
         }
 214   
     }
 215   
     
 216   
     /**
 217   
      * Pass output sent to System.err to the new project.
 218   
      *
 219   
      * @since Ant 1.5
 220   
      */
 221  0
     public void handleErrorOutput(String line) {
 222  0
         if (callee != null) {
 223  0
             callee.handleErrorOutput(line);
 224   
         } else {
 225  0
             super.handleErrorOutput(line);
 226   
         }
 227   
     }
 228   
     
 229   
     /**
 230   
      * Pass output sent to System.err to the new project.
 231   
      *
 232   
      * @since Ant 1.5.2
 233   
      */
 234  0
     public void handleErrorFlush(String line) {
 235  0
         if (callee != null) {
 236  0
             callee.handleErrorFlush(line);
 237   
         } else {
 238  0
             super.handleErrorFlush(line);
 239   
         }
 240   
     }
 241   
 }
 242