    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 resetSpoof() {
    26      	spoof = new StringBuffer();
    27      }
    28
    29      static void spoof(String message){
    30          spoof.append(message);
    31          spoof.append("\n");
    32      }
    33
    34      public void addTask(Task task) {
    35      	// to work with ant 1.6
    36          spoof("in addTask");
    37          if (task instanceof UnknownElement) {
    38              spoof("configuring UnknownElement");
    39              task.maybeConfigure();
    40              task = ((UnknownElement) task).getTask();
    41          }
    42          tasks.add(task);
    43      }
    44
    45      public void execute() throws BuildException {
    46          spoof("begin SpoofTaskContainer execute");
    47          for (Iterator iter = tasks.iterator(); iter.hasNext();) {
    48              Task task = (Task) iter.next();
    49              task.perform();
    50          }
    51          spoof("end SpoofTaskContainer execute");
    52      }
    53
    54  }