You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/09/03 12:03:47 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntLikeTasksAtTopLevelTest.java

bodewig     2003/09/03 03:03:47

  Modified:    .        WHATSNEW
               docs/manual using.html
               docs/manual/CoreTasks ant.html antcall.html subant.html
               src/main/org/apache/tools/ant/taskdefs Ant.java SubAnt.java
  Added:       src/testcases/org/apache/tools/ant/taskdefs
                        AntLikeTasksAtTopLevelTest.java
  Log:
  Throw an exception instead of looping forever in top-level <*ant*> task.
  
  PR: 22759
  
  Revision  Changes    Path
  1.493     +5 -2      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.492
  retrieving revision 1.493
  diff -u -r1.492 -r1.493
  --- WHATSNEW	27 Aug 2003 14:23:17 -0000	1.492
  +++ WHATSNEW	3 Sep 2003 10:03:46 -0000	1.493
  @@ -231,6 +231,11 @@
   
   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.
   
   * A new filter reader namely tokenfilter has been added.  Bugzilla
  @@ -257,8 +262,6 @@
   * <filterset> will now resolve filters recursively.
   
   * <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).
   
  
  
  
  1.31      +3 -1      ant/docs/manual/using.html
  
  Index: using.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/using.html,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- using.html	22 Jul 2003 05:52:36 -0000	1.30
  +++ using.html	3 Sep 2003 10:03:46 -0000	1.31
  @@ -288,7 +288,9 @@
   Ant 1.6 all tasks can be declared outside targets (earlier version
   only allowed <tt>&lt;property&gt;</tt>,<tt>&lt;typedef&gt;</tt> and
   <tt>&lt;taskdef&gt;</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>&lt;antcall&gt;</code> for example).</p>
   
   <p>
   We have given some targets descriptions; this causes the <tt>projecthelp</tt>
  
  
  
  1.18      +6 -1      ant/docs/manual/CoreTasks/ant.html
  
  Index: ant.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/ant.html,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ant.html	12 May 2003 15:19:18 -0000	1.17
  +++ ant.html	3 Sep 2003 10:03:46 -0000	1.18
  @@ -9,7 +9,12 @@
   
   <h2><a name="ant">Ant</a></h2>
   <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 &quot;build.xml&quot;
   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
  
  
  
  1.16      +5 -2      ant/docs/manual/CoreTasks/antcall.html
  
  Index: antcall.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/antcall.html,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- antcall.html	12 May 2003 15:19:18 -0000	1.15
  +++ antcall.html	3 Sep 2003 10:03:46 -0000	1.16
  @@ -9,8 +9,11 @@
   
   <h2><a name="antcall">AntCall</a></h2>
   <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
   available in the new project.   Alternatively, you can
   set the <i>inheritAll</i> attribute to <code>false</code> and only
  
  
  
  1.7       +5 -0      ant/docs/manual/CoreTasks/subant.html
  
  Index: subant.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/subant.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- subant.html	22 May 2003 07:27:50 -0000	1.6
  +++ subant.html	3 Sep 2003 10:03:46 -0000	1.7
  @@ -53,6 +53,11 @@
   <p>
           Calls a given target for all defined sub-builds. This is an extension
           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>
       <table border="0" cellspacing="0" cellpadding="2" width="100%">
         <!-- Subsection heading -->
  
  
  
  1.86      +21 -11    ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- Ant.java	13 Aug 2003 14:46:15 -0000	1.85
  +++ Ant.java	3 Sep 2003 10:03:47 -0000	1.86
  @@ -357,21 +357,31 @@
                       + " 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();
  
  
  
  1.9       +1 -0      ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
  
  Index: SubAnt.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SubAnt.java	16 Jul 2003 14:14:20 -0000	1.8
  +++ SubAnt.java	3 Sep 2003 10:03:47 -0000	1.9
  @@ -431,6 +431,7 @@
       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);
  
  
  
  1.1                  ant/src/testcases/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java
  
  Index: AntLikeTasksAtTopLevelTest.java
  ===================================================================
  /*
   * 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
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntLikeTasksAtTopLevelTest.java

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 3 Sep 2003, peter reilly <pe...@corvil.com> wrote:

> Note that one can still cause infinite loops with
> antcall:
> 
> <project default="x">
>   <target name="x">
>     <antcall target="y"/>
>   </target>
> 
>   <target name="y">
>     <antcall target="x"/>
>   </target>
> </project>

True, but there are too many cases where you cannot detect the case
without actually running the build.  <ant> has always thrown an
exception if you invoked the target is was part of, i.e.

<target name="a">
  <antcall target="a"/>
</target>

has always been caught.  I've just extended it to top level
invocations.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntLikeTasksAtTopLevelTest.java

Posted by peter reilly <pe...@corvil.com>.
Import checks if the file has already been
imported:
So importing the current build file would import it
once.

The following import.xml:

<project>
  <echo>Hello World</echo>
  <import file="import.xml"/>
</project>

Using ant -f import.xml prints out "Hello World" twice.

Note that one can still cause infinite loops with
antcall:

<project default="x">
  <target name="x">
    <antcall target="y"/>
  </target>

  <target name="y">
    <antcall target="x"/>
  </target>
</project>

Peter

On Wednesday 03 September 2003 11:42, Stefan Bodewig wrote:
> On 3 Sep 2003, <bo...@apache.org> wrote:
> >   Throw an exception instead of looping forever in top-level <*ant*>
> >   task.
>
> does <import> need the same treatment?  What happens if a build file
> tries to import itself?
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntLikeTasksAtTopLevelTest.java

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
On Wed, 3 Sep 2003 08:42 pm, Stefan Bodewig wrote:
> On 3 Sep 2003, <bo...@apache.org> wrote:
> >   Throw an exception instead of looping forever in top-level <*ant*>
> >   task.
>
> does <import> need the same treatment?  What happens if a build file
> tries to import itself?
>

I think it is handled - should be a testcase anyway.

Conor


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntLikeTasksAtTopLevelTest.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 3 Sep 2003, <bo...@apache.org> wrote:

>   Throw an exception instead of looping forever in top-level <*ant*>
>   task.

does <import> need the same treatment?  What happens if a build file
tries to import itself?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org