You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Twiggs, Glenn" <Gl...@bmc.com> on 1999/11/24 22:31:34 UTC

PATCH: jakarta-tools/ant/src/main/org/apache/tools/ant/Project.ja va

Here is a patch to Project that will suppress multiple executions of the
same target in a build session. It will also prevent circular references
from "crashing" a build. The same target was executing twice when I built
target "all" using the following build.xml:

  <project default="main" ...>
    <target name="main">
      ...
    </target>
    <target name="stuff" depends="main">
      ...
    </target>
    <target name="all" depends="main,stuff"/>
  <project...>

This is what got logged to stdout:

  Executing Target: main
  ...
  Executing Target: main
  ...
  Executing Target: stuff
  ...
  Executing Target: all

The Project.executeTarget(...) method did not know enough to only execute
target "main" once. By adding a vector of visited targets, multiple target
execution (and therefore, circular references) can be suppressed.

This leads to the question: should circular references be suppressed? For
example, the following target declaration is clearly incorrect, but the
patch will allow it to run successfully:

  <target name="main" depends="main"/>

I guess this could be characterized as a partial fix - multiple valid
references to the same target will suppress multiple executions of the
target, but circular references will be silently ignored (except for the
verbose logging message).

Glenn.

Index: ant/src/main/org/apache/tools/ant/Project.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java
,v
retrieving revision 1.12
diff -r1.12 Project.java
64a65
> import java.util.Vector;
98c99,100
<
---
>     private Vector visitedTargets = new Vector();
>
302,303c304,305
<       // make sure any dependencies on this target are executed
<       // first
---
>         // Check to see if the target has already been visited. If so,
assume
>         // it to be up to date and do not execute the target.
305,317c307,310
<       // XXX
<       // note that we aren't catching circular dependencies
<       // right now... The user will get a hell of an error message
<       // so it's not too bad..
<
<       Enumeration enum = target.getDependencies();
<       while (enum.hasMoreElements()) {
<           String dependency = (String)enum.nextElement();
<           Target prereqTarget = (Target)targets.get(dependency);
<           executeTarget(prereqTarget);
<       }
<
<       log("Executing Target: " + target.getName(), MSG_INFO);
---
>         if (!visitedTargets.contains(target)) {
>
>             // make sure any dependencies on this target are executed
>             // first
319c312,331
<       target.execute();
---
>             Enumeration enum = target.getDependencies();
>             while (enum.hasMoreElements()) {
>                 String dependency = (String)enum.nextElement();
>                 Target prereqTarget = (Target)targets.get(dependency);
>                 executeTarget(prereqTarget);
>             }
>
>             log("Executing Target: " + target.getName(), MSG_INFO);
>
>             visitedTargets.addElement(target);
>             target.execute();
>         } else {
>
>             // XXX
>             // note that we aren't catching circular dependencies right
now.
>             // This log message is the only indicator of a circular
dependency.
>
>             log("Skipping previously visited Target: " + target.getName(),
>                 MSG_VERBOSE);
>         }

Re: PATCH: jakarta-tools/ant/src/main/org/apache/tools/ant/Project.ja va

Posted by jon * <jo...@clearink.com>.
on 11/24/99 1:31 PM, Twiggs, Glenn <Gl...@bmc.com> wrote:

> Here is a patch to Project that will suppress multiple executions of the
> same target in a build session. It will also prevent circular references
> from "crashing" a build. The same target was executing twice when I built
> target "all" using the following build.xml:

I'm taking care of applying this path.

-jon