    1   package groovy.util;
    2
    3   import org.apache.tools.ant.Task;
    4   import org.apache.tools.ant.TaskContainer;
    5   import org.apache.tools.ant.UnknownElement;
    6   import org.apache.tools.ant.BuildException;
    7
    8   import java.util.List;
    9   import java.util.ArrayList;
    10  import java.util.Iterator;
    11
    12  public class SpoofTaskContainer extends Task implements TaskContainer {
    13      private List tasks = new ArrayList();
    14      static StringBuffer spoof = new StringBuffer();
    15
    16      public SpoofTaskContainer() {
    17          super();
    18          spoof("SpoofTaskContainer ctor");
    19      }
    20
    21      static StringBuffer getSpoof(){
    22          return spoof;
    23      }
    24
    25      static void spoof(String message){
    26          spoof.append(message);
    27          spoof.append("\n");
    28      }
    29
    30      public void addTask(Task task) {
    31      	// to work with ant 1.6
    32          spoof("in addTask");
    33          if (task instanceof UnknownElement) {
    34              task.maybeConfigure();
    35              task = ((UnknownElement) task).getTask();
    36          }
    37          tasks.add(task);
    38      }
    39
    40      public void execute() throws BuildException {
    41          spoof("begin SpoofTaskContainer execute");
    42          for (Iterator iter = tasks.iterator(); iter.hasNext();) {
    43              Task task = (Task) iter.next();
    44              task.perform();
    45          }
    46          spoof("end SpoofTaskContainer execute");
    47      }
    48
    49  }