Index: src/test/groovy/util/AntTest.groovy =================================================================== --- src/test/groovy/util/AntTest.groovy (revision 14730) +++ src/test/groovy/util/AntTest.groovy Sun Sep 20 01:49:48 EST 2009 @@ -1,6 +1,5 @@ package groovy.util -import java.io.File import org.apache.tools.ant.BuildEvent import org.apache.tools.ant.Project import org.apache.tools.ant.ProjectHelper Index: src/main/groovy/util/AntBuilder.java =================================================================== --- src/main/groovy/util/AntBuilder.java (revision 12900) +++ src/main/groovy/util/AntBuilder.java Sun Sep 20 01:51:56 EST 2009 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2008 the original author or authors. + * Copyright 2003-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,8 +52,6 @@ */ public class AntBuilder extends BuilderSupport { - private static final Class[] ADD_TASK_PARAM_TYPES = { String.class }; - private final Logger log = Logger.getLogger(getClass().getName()); private Project project; private final AntXMLContext antXmlContext; @@ -62,9 +60,9 @@ private final Target collectorTarget; private final Target implicitTarget; private Object lastCompletedNode; + // true when inside a task so special ant.target handling occurs just at top level + boolean insideTask; - - public AntBuilder() { this(createProject()); } @@ -161,14 +159,14 @@ /** * Determines, when the ANT Task that is represented by the "node" should perform. * Node must be an ANT Task or no "perform" is called. - * If node is an ANT Task, it performs right after complete contstruction. + * If node is an ANT Task, it performs right after complete construction. * If node is nested in a TaskContainer, calling "perform" is delegated to that * TaskContainer. * @param parent note: null when node is root * @param node the node that now has all its children applied */ protected void nodeCompleted(final Object parent, final Object node) { - + if (parent == null) insideTask = false; antElementHandler.onEndElement(null, null, antXmlContext); lastCompletedNode = node; @@ -191,6 +189,10 @@ // UnknownElement may wrap everything: task, path, ... if (task instanceof Task) { final String taskName = ((Task) task).getTaskName(); + if ("antcall".equals(taskName) && parent == null) { + throw new BuildException("antcall not supported within AntBuilder, consider using 'ant.project.executeTarget('targetName')' instead."); + } + // save original streams InputStream savedIn = System.in; InputStream savedProjectInputStream = project.getDefaultInputStream(); @@ -199,7 +201,7 @@ project.setDefaultInputStream(savedIn); System.setIn(new DemuxInputStream(project)); } - + try { ((Task) task).perform(); } finally { @@ -273,7 +275,7 @@ if ("import".equals(name)) { antXmlContext.setCurrentTarget(implicitTarget); } - else if ("target".equals(name)) { + else if ("target".equals(name) && !insideTask) { return onStartTarget(attrs, tagName, ns); } @@ -285,7 +287,8 @@ { log.log(Level.SEVERE, "Caught: " + e, e); } - + + insideTask = true; final RuntimeConfigurable wrapper = (RuntimeConfigurable) antXmlContext.getWrapperStack().lastElement(); return wrapper.getProxy(); }