bodewig 2003/09/04 04:46:03
Modified: src/etc/testcases/taskdefs ant.xml
src/main/org/apache/tools/ant Project.java Target.java
src/main/org/apache/tools/ant/taskdefs Ant.java
src/testcases/org/apache/tools/ant/taskdefs AntTest.java
Log:
Catch another simple to detect case of infinite antcall loops
Revision Changes Path
1.11 +7 -0 ant/src/etc/testcases/taskdefs/ant.xml
Index: ant.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/ant.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ant.xml 12 May 2003 12:57:04 -0000 1.10
+++ ant.xml 4 Sep 2003 11:46:03 -0000 1.11
@@ -162,4 +162,11 @@
<echo>test2 is ${test2}</echo>
<echo>test1.x is ${test1.x}</echo>
</target>
+
+ <target name="infinite-loop-via-depends">
+ <antcall target="dependent"/>
+ </target>
+
+ <target name="middleman" depends="infinite-loop-via-depends"/>
+ <target name="dependent" depends="middleman"/>
</project>
1.153 +3 -4 ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -r1.152 -r1.153
--- Project.java 3 Sep 2003 15:22:10 -0000 1.152
+++ Project.java 4 Sep 2003 11:46:03 -0000 1.153
@@ -1589,8 +1589,7 @@
* Must not be <code>null</code>.
* @param targets A map of names to targets (String to Target).
* Must not be <code>null</code>.
- * @return a vector of strings with the names of the targets in
- * sorted order.
+ * @return a vector of Target objects in sorted order.
* @exception BuildException if there is a cyclic dependency among the
* targets, or if a named target does not
exist.
*/
@@ -2096,4 +2095,4 @@
// is private/protected.
}
}
-}
\ No newline at end of file
+}
1.44 +16 -0 ant/src/main/org/apache/tools/ant/Target.java
Index: Target.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Target.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- Target.java 24 Jul 2003 14:20:56 -0000 1.43
+++ Target.java 4 Sep 2003 11:46:03 -0000 1.44
@@ -256,6 +256,22 @@
}
/**
+ * Does this target depend on the named target?
+ *
+ * @since Ant 1.6
+ */
+ public boolean dependsOn(String other) {
+ if (getProject() != null) {
+ List l = getProject().topoSort(getName(),
+ getProject().getTargets());
+ int myIdx = l.indexOf(this);
+ int otherIdx = l.indexOf(getProject().getTargets().get(other));
+ return myIdx >= otherIdx;
+ }
+ return false;
+ }
+
+ /**
* Sets the "if" condition to test on execution. This is the
* name of a property to test for existence - if the property
* is not set, the task will not execute. The property goes
1.87 +17 -2 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.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- Ant.java 3 Sep 2003 10:03:47 -0000 1.86
+++ Ant.java 4 Sep 2003 11:46:03 -0000 1.87
@@ -68,6 +68,7 @@
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.PropertySet;
import org.apache.tools.ant.util.FileUtils;
@@ -363,7 +364,10 @@
if (newProject.getProperty("ant.file")
.equals(getProject().getProperty("ant.file"))
&& getOwningTarget() != null) {
- if (getOwningTarget().getName().equals("")) {
+
+ String owningTargetName = getOwningTarget().getName();
+
+ if (owningTargetName.equals("")) {
if (getTaskName().equals("antcall")) {
throw new BuildException("antcall must not be used
at"
+ " the top level.");
@@ -372,9 +376,20 @@
+ " top level must not
invoke"
+ " its own build file.");
}
- } else if (getOwningTarget().getName().equals(target)) {
+ } else if (owningTargetName.equals(target)) {
throw new BuildException(getTaskName() + " task calling "
+ "its own parent target.");
+ } else {
+ Target other =
+ (Target) getProject().getTargets().get(target);
+ if (other != null && other.dependsOn(owningTargetName)) {
+ throw new BuildException(getTaskName()
+ + " task calling a target"
+ + " that depends on"
+ + " its parent target \'"
+ + owningTargetName
+ + "\'.");
+ }
}
}
1.18 +5 -1
ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java
Index: AntTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- AntTest.java 12 May 2003 12:57:05 -0000 1.17
+++ AntTest.java 4 Sep 2003 11:46:03 -0000 1.18
@@ -302,6 +302,10 @@
assertTrue(getLog().indexOf("test1.x is 1") > -1);
}
+ public void testInfiniteLoopViaDepends() {
+ expectBuildException("infinite-loop-via-depends", "recursive call");
+ }
+
private class BasedirChecker implements BuildListener {
private String[] expectedBasedirs;
private int calls = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]