diff --git a/WHATSNEW b/WHATSNEW index 842f94207..4ce279b56 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -231,6 +231,11 @@ Fixed bugs: Other changes: -------------- +* All tasks can be used outside of s. Note that some tasks + will not work at all outside of targets as they would cause infinite + loops ( as well as and if they invoke the + current build file). + * Six new Clearcase tasks added. * A new filter reader namely tokenfilter has been added. Bugzilla @@ -258,8 +263,6 @@ Other changes: * has a new attribute that allows you to specify a default value. -* All tasks can be used outside of s - * Added task (requires JAI). * task has now proportions attribute in the nested element diff --git a/docs/manual/CoreTasks/ant.html b/docs/manual/CoreTasks/ant.html index d22922867..bfecfcb73 100644 --- a/docs/manual/CoreTasks/ant.html +++ b/docs/manual/CoreTasks/ant.html @@ -9,7 +9,12 @@

Ant

Description

-

Runs Ant on a supplied buildfile. This can be used to build subprojects.

+ +

Runs Ant on a supplied buildfile. This can be used to build +subprojects. This task must no be used outside of a +target if it invoces the same build file it is part +of.

+

When the antfile attribute is omitted, the file "build.xml" in the supplied directory (dir attribute) is used.

If no target attribute is supplied, the default target of the new project is diff --git a/docs/manual/CoreTasks/antcall.html b/docs/manual/CoreTasks/antcall.html index 6755a34ca..c87238ef1 100644 --- a/docs/manual/CoreTasks/antcall.html +++ b/docs/manual/CoreTasks/antcall.html @@ -9,8 +9,11 @@

AntCall

Description

-

Call another target within the same build-file optionally specifying some -properties (param's in this context)

+ +

Call another target within the same build-file optionally +specifying some properties (param's in this context). This +task must no be used outside of a target.

+

By default, all of the properties of the current project will be available in the new project. Alternatively, you can set the inheritAll attribute to false and only diff --git a/docs/manual/CoreTasks/subant.html b/docs/manual/CoreTasks/subant.html index e1330705f..6aed7f6e1 100644 --- a/docs/manual/CoreTasks/subant.html +++ b/docs/manual/CoreTasks/subant.html @@ -53,6 +53,11 @@

Calls a given target for all defined sub-builds. This is an extension of ant for bulk project execution. + + This task must no be used outside of a + target if it invoces the same build file it is + part of. +

diff --git a/docs/manual/using.html b/docs/manual/using.html index fd53908a3..e49be65a3 100644 --- a/docs/manual/using.html +++ b/docs/manual/using.html @@ -288,7 +288,9 @@ ant.java.version the JVM version Ant detected; currently it can hold Ant 1.6 all tasks can be declared outside targets (earlier version only allowed <property>,<typedef> and <taskdef>). When you do this they are evaluated before -any targets are executed.

+any targets are executed. Some tasks will generate build failures if +they are used outside of targets as they may cause infinite loops +otherwise (<antcall> for example).

We have given some targets descriptions; this causes the projecthelp diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index 1e7c77e86..2d7b00d19 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -357,23 +357,33 @@ public class Ant extends Task { + " in build file " + antFile.toString(), Project.MSG_VERBOSE); newProject.setUserProperty("ant.file" , antFile); + + // Are we trying to call the target in which we are defined (or + // the build file if this is a top level task)? + if (newProject.getProperty("ant.file") + .equals(getProject().getProperty("ant.file")) + && getOwningTarget() != null) { + if (getOwningTarget().getName().equals("")) { + if (getTaskName().equals("antcall")) { + throw new BuildException("antcall must not be used at" + + " the top level."); + } else { + throw new BuildException(getTaskName() + " task at the" + + " top level must not invoke" + + " its own build file."); + } + } else if (getOwningTarget().getName().equals(target)) { + throw new BuildException(getTaskName() + " task calling " + + "its own parent target."); + } + } + ProjectHelper.configureProject(newProject, new File(antFile)); if (target == null) { target = newProject.getDefaultTarget(); } - // Are we trying to call the target in which we are defined (or - // the build file if this is a top level task)? - if (newProject.getBaseDir().equals(getProject().getBaseDir()) - && newProject.getProperty("ant.file").equals(getProject().getProperty("ant.file")) - && getOwningTarget() != null - && (getOwningTarget().getName().equals("") - || getOwningTarget().getName().equals(target))) { - throw new BuildException("ant task calling its own parent " - + "target"); - } - addReferences(); if (target != null) { diff --git a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java index 82d59fa34..a5faa0bc1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java +++ b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java @@ -431,6 +431,7 @@ public class SubAnt private Ant createAntTask(File directory) { Ant ant = (Ant) getProject().createTask("ant"); ant.setOwningTarget(getOwningTarget()); + ant.setTaskName(getTaskName()); ant.init(); if (target != null && target.length() > 0) { ant.setTarget(target); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java b/src/testcases/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java new file mode 100644 index 000000000..57cf78828 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java @@ -0,0 +1,98 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "Ant" and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; + +/** + * @since Ant 1.6 + */ +public class AntLikeTasksAtTopLevelTest extends BuildFileTest { + public AntLikeTasksAtTopLevelTest(String name) { + super(name); + } + + public void testAnt() { + try { + configureProject("src/etc/testcases/taskdefs/toplevelant.xml"); + fail("no exception thrown"); + } catch (BuildException e) { + assertEquals("ant task at the top level must not invoke its own" + + " build file.", e.getMessage()); + } + } + + public void testSubant() { + try { + configureProject("src/etc/testcases/taskdefs/toplevelsubant.xml"); + fail("no exception thrown"); + } catch (BuildException e) { + assertEquals("subant task at the top level must not invoke its own" + + " build file.", e.getMessage()); + } + } + + public void testAntcall() { + try { + configureProject("src/etc/testcases/taskdefs/toplevelantcall.xml"); + fail("no exception thrown"); + } catch (BuildException e) { + assertEquals("antcall must not be used at the top level.", + e.getMessage()); + } + } + +}// AntLikeTasksAtTopLevelTest