    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              spoof("configuring UnknownElement");
    35              task.maybeConfigure();
    36              task = ((UnknownElement) task).getTask();
    37          }
    38          tasks.add(task);
    39      }
    40
    41      public void execute() throws BuildException {
    42          spoof("begin SpoofTaskContainer execute");
    43          for (Iterator iter = tasks.iterator(); iter.hasNext();) {
    44              Task task = (Task) iter.next();
    45              task.perform();
    46          }
    47          spoof("end SpoofTaskContainer execute");
    48      }
    49
    50  }