(1) making project's default attribute optional. (2) don't run executeTarget(s) if not asked for one Adapt documentation and <antstructure>. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273111 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -30,7 +30,7 @@ to be unique. (For additional information, see the | |||||
| <tr> | <tr> | ||||
| <td valign="top">default</td> | <td valign="top">default</td> | ||||
| <td valign="top">the default target to use when no target is supplied.</td> | <td valign="top">the default target to use when no target is supplied.</td> | ||||
| <td align="center" valign="top">Yes.</td> | |||||
| <td align="center" valign="top">No. No target will be run if omitted.</td> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td valign="top">basedir</td> | <td valign="top">basedir</td> | ||||
| @@ -284,11 +284,11 @@ ant.java.version the JVM version Ant detected; currently it can hold | |||||
| </project> | </project> | ||||
| </pre> | </pre> | ||||
| Notice that we are declaring properties outside any target. The | |||||
| <tt><property></tt>,<tt><typedef></tt> and <tt><taskdef></tt> | |||||
| tasks are special in that they can be declared outside any target. When you | |||||
| do this they are evaluated before any targets are executed. No other tasks | |||||
| can be declared outside targets. | |||||
| <p>Notice that we are declaring properties outside any target. As of | |||||
| Ant 1.6 all tasks can be declared outside targets (earlier version | |||||
| only allowed <tt><property></tt>,<tt><typedef></tt> and | |||||
| <tt><taskdef></tt>). When you do this they are evaluated before | |||||
| any targets are executed.</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> | ||||
| @@ -0,0 +1,3 @@ | |||||
| <project> | |||||
| <echo message="Called" /> | |||||
| </project> | |||||
| @@ -0,0 +1,5 @@ | |||||
| <project basedir="." default="foo"> | |||||
| <target name="foo"> | |||||
| <ant antfile="notarget.xml" /> | |||||
| </target> | |||||
| </project> | |||||
| @@ -0,0 +1,3 @@ | |||||
| <project basedir="."> | |||||
| <ant antfile="notarget.xml" /> | |||||
| </project> | |||||
| @@ -604,7 +604,7 @@ public class Main { | |||||
| } | } | ||||
| // make sure that we have a target to execute | // make sure that we have a target to execute | ||||
| if (targets.size() == 0) { | |||||
| if (targets.size() == 0 && project.getDefaultTarget() != null) { | |||||
| targets.addElement(project.getDefaultTarget()); | targets.addElement(project.getDefaultTarget()); | ||||
| } | } | ||||
| @@ -451,11 +451,7 @@ public class ProjectHelperImpl extends ProjectHelper { | |||||
| } | } | ||||
| } | } | ||||
| if (def == null) { | |||||
| throw new SAXParseException("The default attribute of project " | |||||
| + "is required", | |||||
| helperImpl.locator); | |||||
| } else { | |||||
| if (def != null) { | |||||
| helperImpl.project.setDefaultTarget(def); | helperImpl.project.setDefaultTarget(def); | ||||
| } | } | ||||
| @@ -356,19 +356,21 @@ public class Ant extends Task { | |||||
| target = newProject.getDefaultTarget(); | target = newProject.getDefaultTarget(); | ||||
| } | } | ||||
| addReferences(); | |||||
| // Are we trying to call the target in which we are defined? | |||||
| // 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(project.getBaseDir()) && | if (newProject.getBaseDir().equals(project.getBaseDir()) && | ||||
| newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) && | |||||
| getOwningTarget() != null && | |||||
| target.equals(this.getOwningTarget().getName())) { | |||||
| newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) | |||||
| && (getOwningTarget() == null || | |||||
| getOwningTarget().getName().equals(target))) { | |||||
| throw new BuildException("ant task calling its own parent " | throw new BuildException("ant task calling its own parent " | ||||
| + "target"); | |||||
| + "target"); | |||||
| } | } | ||||
| newProject.executeTarget(target); | |||||
| addReferences(); | |||||
| if (target != null) { | |||||
| newProject.executeTarget(target); | |||||
| } | |||||
| } finally { | } finally { | ||||
| // help the gc | // help the gc | ||||
| newProject = null; | newProject = null; | ||||
| @@ -196,13 +196,14 @@ public class AntStructure extends Task { | |||||
| out.println(""); | out.println(""); | ||||
| out.print("<!ELEMENT project (target | property | taskdef"); | |||||
| out.print(" | typedef | "); | |||||
| out.print("<!ELEMENT project (target | "); | |||||
| out.print(TASKS); | |||||
| out.print(" | "); | |||||
| out.print(TYPES); | out.print(TYPES); | ||||
| out.println(")*>"); | out.println(")*>"); | ||||
| out.println("<!ATTLIST project"); | out.println("<!ATTLIST project"); | ||||
| out.println(" name CDATA #IMPLIED"); | out.println(" name CDATA #IMPLIED"); | ||||
| out.println(" default CDATA #REQUIRED"); | |||||
| out.println(" default CDATA #IMPLIED"); | |||||
| out.println(" basedir CDATA #IMPLIED>"); | out.println(" basedir CDATA #IMPLIED>"); | ||||
| out.println(""); | out.println(""); | ||||
| } | } | ||||
| @@ -0,0 +1,83 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2002 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 "The Jakarta Project", "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; | |||||
| /** | |||||
| * Tests for builds with tasks at the top level | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @since Ant 1.6 | |||||
| */ | |||||
| public class TopLevelTaskTest extends BuildFileTest { | |||||
| public TopLevelTaskTest(String name) { | |||||
| super(name); | |||||
| } | |||||
| public void testNoTarget() { | |||||
| configureProject("src/etc/testcases/core/topleveltasks/notarget.xml"); | |||||
| assertEquals("Called", getLog()); | |||||
| } | |||||
| public void testCalledFromTopLevelAnt() { | |||||
| configureProject("src/etc/testcases/core/topleveltasks/toplevelant.xml"); | |||||
| assertEquals("Called", getLog()); | |||||
| } | |||||
| public void testCalledFromTargetLevelAnt() { | |||||
| configureProject("src/etc/testcases/core/topleveltasks/targetlevelant.xml"); | |||||
| expectLog("foo", "Called"); | |||||
| } | |||||
| } | |||||