PR: 22759 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275176 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -231,6 +231,11 @@ Fixed bugs: | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| * All tasks can be used outside of <target>s. Note that some tasks | |||||
| will not work at all outside of targets as they would cause infinite | |||||
| loops (<antcall> as well as <ant> and <subant> if they invoke the | |||||
| current build file). | |||||
| * Six new Clearcase tasks added. | * Six new Clearcase tasks added. | ||||
| * A new filter reader namely tokenfilter has been added. Bugzilla | * A new filter reader namely tokenfilter has been added. Bugzilla | ||||
| @@ -258,8 +263,6 @@ Other changes: | |||||
| * <input> has a new attribute that allows you to specify a default value. | * <input> has a new attribute that allows you to specify a default value. | ||||
| * All tasks can be used outside of <target>s | |||||
| * Added <image> task (requires JAI). | * Added <image> task (requires JAI). | ||||
| * <image> task has now proportions attribute in the <scale/> nested element | * <image> task has now proportions attribute in the <scale/> nested element | ||||
| @@ -9,7 +9,12 @@ | |||||
| <h2><a name="ant">Ant</a></h2> | <h2><a name="ant">Ant</a></h2> | ||||
| <h3>Description</h3> | <h3>Description</h3> | ||||
| <p>Runs Ant on a supplied buildfile. This can be used to build subprojects.</p> | |||||
| <p>Runs Ant on a supplied buildfile. This can be used to build | |||||
| subprojects. <strong>This task must no be used outside of a | |||||
| <code>target</code> if it invoces the same build file it is part | |||||
| of.</strong></p> | |||||
| <p>When the <i>antfile</i> attribute is omitted, the file "build.xml" | <p>When the <i>antfile</i> attribute is omitted, the file "build.xml" | ||||
| in the supplied directory (<i>dir</i> attribute) is used.</p> | in the supplied directory (<i>dir</i> attribute) is used.</p> | ||||
| <p>If no target attribute is supplied, the default target of the new project is | <p>If no target attribute is supplied, the default target of the new project is | ||||
| @@ -9,8 +9,11 @@ | |||||
| <h2><a name="antcall">AntCall</a></h2> | <h2><a name="antcall">AntCall</a></h2> | ||||
| <h3>Description</h3> | <h3>Description</h3> | ||||
| <p>Call another target within the same build-file optionally specifying some | |||||
| properties (param's in this context)</p> | |||||
| <p>Call another target within the same build-file optionally | |||||
| specifying some properties (param's in this context). <strong>This | |||||
| task must no be used outside of a <code>target</code>.</strong></p> | |||||
| <p>By default, all of the properties of the current project will be | <p>By default, all of the properties of the current project will be | ||||
| available in the new project. Alternatively, you can | available in the new project. Alternatively, you can | ||||
| set the <i>inheritAll</i> attribute to <code>false</code> and only | set the <i>inheritAll</i> attribute to <code>false</code> and only | ||||
| @@ -53,6 +53,11 @@ | |||||
| <p> | <p> | ||||
| Calls a given target for all defined sub-builds. This is an extension | Calls a given target for all defined sub-builds. This is an extension | ||||
| of ant for bulk project execution. | of ant for bulk project execution. | ||||
| <strong>This task must no be used outside of a | |||||
| <code>target</code> if it invoces the same build file it is | |||||
| part of.</strong> | |||||
| </p> | </p> | ||||
| <table border="0" cellspacing="0" cellpadding="2" width="100%"> | <table border="0" cellspacing="0" cellpadding="2" width="100%"> | ||||
| <!-- Subsection heading --> | <!-- Subsection heading --> | ||||
| @@ -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 | Ant 1.6 all tasks can be declared outside targets (earlier version | ||||
| only allowed <tt><property></tt>,<tt><typedef></tt> and | only allowed <tt><property></tt>,<tt><typedef></tt> and | ||||
| <tt><taskdef></tt>). When you do this they are evaluated before | <tt><taskdef></tt>). When you do this they are evaluated before | ||||
| any targets are executed.</p> | |||||
| any targets are executed. Some tasks will generate build failures if | |||||
| they are used outside of targets as they may cause infinite loops | |||||
| otherwise (<code><antcall></code> for example).</p> | |||||
| <p> | <p> | ||||
| We have given some targets descriptions; this causes the <tt>projecthelp</tt> | We have given some targets descriptions; this causes the <tt>projecthelp</tt> | ||||
| @@ -357,23 +357,33 @@ public class Ant extends Task { | |||||
| + " in build file " + antFile.toString(), | + " in build file " + antFile.toString(), | ||||
| Project.MSG_VERBOSE); | Project.MSG_VERBOSE); | ||||
| newProject.setUserProperty("ant.file" , antFile); | 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)); | ProjectHelper.configureProject(newProject, new File(antFile)); | ||||
| if (target == null) { | if (target == null) { | ||||
| target = newProject.getDefaultTarget(); | 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(); | addReferences(); | ||||
| if (target != null) { | if (target != null) { | ||||
| @@ -431,6 +431,7 @@ public class SubAnt | |||||
| private Ant createAntTask(File directory) { | private Ant createAntTask(File directory) { | ||||
| Ant ant = (Ant) getProject().createTask("ant"); | Ant ant = (Ant) getProject().createTask("ant"); | ||||
| ant.setOwningTarget(getOwningTarget()); | ant.setOwningTarget(getOwningTarget()); | ||||
| ant.setTaskName(getTaskName()); | |||||
| ant.init(); | ant.init(); | ||||
| if (target != null && target.length() > 0) { | if (target != null && target.length() > 0) { | ||||
| ant.setTarget(target); | ant.setTarget(target); | ||||
| @@ -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 | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| 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 | |||||