diff options
13 files changed, 104 insertions, 2 deletions
diff --git a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java index 058ba960b..15c65aa58 100755 --- a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java +++ b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.types; import java.io.File; import java.util.Iterator; +import java.util.Stack; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -150,6 +151,7 @@ public abstract class ArchiveFileSet extends FileSet { throw new BuildException(ERROR_DIR_AND_SRC_ATTRIBUTES); } this.src = src; + setChecked(false); } /** @@ -256,6 +258,7 @@ public abstract class ArchiveFileSet extends FileSet { * @return a directory scanner */ public DirectoryScanner getDirectoryScanner(Project p) { + dieOnCircularReference(); if (isReference()) { return getRef(p).getDirectoryScanner(p); } @@ -512,4 +515,21 @@ public abstract class ArchiveFileSet extends FileSet { checkAttributesAllowed(); } } + + protected synchronized void dieOnCircularReference(Stack stk, Project p) + throws BuildException { + if (isChecked()) { + return; + } + if (isReference()) { + super.dieOnCircularReference(stk, p); + } else { + if (src != null) { + stk.push(src); + invokeCircularReferenceCheck(src, stk, p); + stk.pop(); + } + setChecked(true); + } + } } diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java index 8ab3a50cc..ce2a9cf83 100644 --- a/src/main/org/apache/tools/ant/types/Mapper.java +++ b/src/main/org/apache/tools/ant/types/Mapper.java @@ -92,6 +92,7 @@ public class Mapper extends DataType implements Cloneable { } } container.add(fileNameMapper); + setChecked(false); } /** @@ -139,6 +140,7 @@ public class Mapper extends DataType implements Cloneable { if (this.classpath == null) { this.classpath = new Path(getProject()); } + setChecked(false); return this.classpath.createPath(); } diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java index 0f3755835..507fbe2f1 100755 --- a/src/main/org/apache/tools/ant/types/RedirectorElement.java +++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java @@ -119,6 +119,7 @@ public class RedirectorElement extends DataType { throw new BuildException("Cannot have > 1 <inputmapper>"); } } + setChecked(false); this.inputMapper = inputMapper; } @@ -138,6 +139,7 @@ public class RedirectorElement extends DataType { throw new BuildException("Cannot have > 1 <outputmapper>"); } } + setChecked(false); this.outputMapper = outputMapper; } @@ -157,6 +159,7 @@ public class RedirectorElement extends DataType { throw new BuildException("Cannot have > 1 <errormapper>"); } } + setChecked(false); this.errorMapper = errorMapper; } @@ -388,6 +391,7 @@ public class RedirectorElement extends DataType { FilterChain result = new FilterChain(); result.setProject(getProject()); inputFilterChains.add(result); + setChecked(false); return result; } @@ -402,6 +406,7 @@ public class RedirectorElement extends DataType { FilterChain result = new FilterChain(); result.setProject(getProject()); outputFilterChains.add(result); + setChecked(false); return result; } @@ -416,6 +421,7 @@ public class RedirectorElement extends DataType { FilterChain result = new FilterChain(); result.setProject(getProject()); errorFilterChains.add(result); + setChecked(false); return result; } @@ -438,6 +444,7 @@ public class RedirectorElement extends DataType { getRef().configure(redirector, sourcefile); return; } + dieOnCircularReference(); if (alwaysLog != null) { redirector.setAlwaysLog(alwaysLog.booleanValue()); } diff --git a/src/main/org/apache/tools/ant/types/Resource.java b/src/main/org/apache/tools/ant/types/Resource.java index fe7ece5c8..557952a75 100644 --- a/src/main/org/apache/tools/ant/types/Resource.java +++ b/src/main/org/apache/tools/ant/types/Resource.java @@ -434,7 +434,7 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc * <p>This implementation of the method will return the current * instance itself if it can be assigned to the given class.</p> * - * @since ant 1.8.0 + * @since Ant 1.8.0 */ public Object as(Class clazz) { return clazz.isAssignableFrom(getClass()) ? this : null; diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java index 66413e519..739dac134 100644 --- a/src/main/org/apache/tools/ant/types/XMLCatalog.java +++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java @@ -27,6 +27,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; +import java.util.Stack; import java.util.Vector; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; @@ -451,6 +452,28 @@ public class XMLCatalog extends DataType return source; } + protected synchronized void dieOnCircularReference(Stack stk, Project p) + throws BuildException { + if (isChecked()) { + return; + } + if (isReference()) { + super.dieOnCircularReference(stk, p); + } else { + if (classpath != null) { + stk.push(classpath); + invokeCircularReferenceCheck(classpath, stk, p); + stk.pop(); + } + if (catalogPath != null) { + stk.push(catalogPath); + invokeCircularReferenceCheck(catalogPath, stk, p); + stk.pop(); + } + setChecked(true); + } + } + /** * @since Ant 1.6 */ diff --git a/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java b/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java index 51b4c9999..a0e563438 100644 --- a/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java +++ b/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java @@ -23,6 +23,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.DataType; import org.apache.tools.ant.types.Mapper; +import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.util.FileNameMapper; @@ -53,6 +54,7 @@ public class MappedResourceCollection + " nested into mappedresources", getLocation()); } + setChecked(false); nested = c; } @@ -69,6 +71,7 @@ public class MappedResourceCollection throw new BuildException("Cannot define more than one mapper", getLocation()); } + setChecked(false); mapper = new Mapper(getProject()); return mapper; } @@ -114,6 +117,17 @@ public class MappedResourceCollection } /** + * Overrides the base version. + * @param r the Reference to set. + */ + public void setRefid(Reference r) { + if (nested != null || mapper != null) { + throw tooManyAttributes(); + } + super.setRefid(r); + } + + /** * Implement clone. The nested resource collection and mapper are * copied. * @return a cloned instance. @@ -165,6 +179,7 @@ public class MappedResourceCollection throw new BuildException("A nested resource collection element is" + " required", getLocation()); } + dieOnCircularReference(); } private static class MappedIterator implements Iterator { diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java b/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java index 8b13a8134..2e8ddfd0a 100644 --- a/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java +++ b/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java @@ -66,6 +66,7 @@ public abstract class ResourceDecorator extends Resource { throw new BuildException("only single argument resource collections" + " are supported"); } + setChecked(false); resource = (Resource) a.iterator().next(); } @@ -195,6 +196,7 @@ public abstract class ResourceDecorator extends Resource { if (resource == null) { throw new BuildException("no resource specified"); } + dieOnCircularReference(); return resource; } diff --git a/src/main/org/apache/tools/ant/types/resources/Restrict.java b/src/main/org/apache/tools/ant/types/resources/Restrict.java index aba581fae..bc5514b08 100644 --- a/src/main/org/apache/tools/ant/types/resources/Restrict.java +++ b/src/main/org/apache/tools/ant/types/resources/Restrict.java @@ -17,10 +17,12 @@ */ package org.apache.tools.ant.types.resources; -import java.util.Iterator; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; +import java.util.Stack; +import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.resources.selectors.ResourceSelector; @@ -67,6 +69,7 @@ outer: for (Iterator ri = w.getResourceCollection().iterator(); ri.hasNext( return; } w.add(c); + setChecked(false); } /** @@ -145,4 +148,19 @@ outer: for (Iterator ri = w.getResourceCollection().iterator(); ri.hasNext( return w.toString(); } + protected synchronized void dieOnCircularReference(Stack stk, Project p) { + if (isChecked()) { + return; + } + + // takes care of Selectors + super.dieOnCircularReference(stk, p); + + if (!isReference()) { + stk.push(w); + invokeCircularReferenceCheck(w, stk, p); + stk.pop(); + setChecked(true); + } + } } diff --git a/src/main/org/apache/tools/ant/types/resources/Sort.java b/src/main/org/apache/tools/ant/types/resources/Sort.java index 593f24f9f..fb6a88a83 100644 --- a/src/main/org/apache/tools/ant/types/resources/Sort.java +++ b/src/main/org/apache/tools/ant/types/resources/Sort.java @@ -126,6 +126,7 @@ public class Sort extends BaseResourceCollectionWrapper { } comp.add(c); FailFast.invalidate(this); + setChecked(false); } /** @@ -143,7 +144,9 @@ public class Sort extends BaseResourceCollectionWrapper { if (isReference()) { super.dieOnCircularReference(stk, p); } else { + stk.push(comp); DataType.invokeCircularReferenceCheck(comp, stk, p); + stk.pop(); setChecked(true); } } diff --git a/src/main/org/apache/tools/ant/types/resources/Tokens.java b/src/main/org/apache/tools/ant/types/resources/Tokens.java index a60d790ad..febc50a80 100644 --- a/src/main/org/apache/tools/ant/types/resources/Tokens.java +++ b/src/main/org/apache/tools/ant/types/resources/Tokens.java @@ -102,6 +102,7 @@ public class Tokens extends BaseResourceCollectionWrapper { throw new BuildException("Only one nested tokenizer allowed."); } this.tokenizer = tokenizer; + setChecked(false); } /** @@ -122,6 +123,7 @@ public class Tokens extends BaseResourceCollectionWrapper { if (tokenizer instanceof DataType) { stk.push(tokenizer); invokeCircularReferenceCheck((DataType) tokenizer, stk, p); + stk.pop(); } setChecked(true); } diff --git a/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java b/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java index 425c5b1aa..a6ea34f09 100644 --- a/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java +++ b/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java @@ -48,6 +48,7 @@ public class DelegatedResourceComparator extends ResourceComparator { } v = (v == null) ? new Vector() : v; v.add(c); + setChecked(false); } /** @@ -115,6 +116,7 @@ s. if (o instanceof DataType) { stk.push(o); invokeCircularReferenceCheck((DataType) o, stk, p); + stk.pop(); } } } diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java b/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java index f1d7d0e72..cfbce231c 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java @@ -58,6 +58,7 @@ public class Compare extends DataType implements ResourceSelector { throw noChildrenAllowed(); } comp.add(c); + setChecked(false); } /** @@ -95,6 +96,7 @@ public class Compare extends DataType implements ResourceSelector { throw oneControl(); } control = new Union(); + setChecked(false); return control; } @@ -107,6 +109,7 @@ public class Compare extends DataType implements ResourceSelector { if (control == null) { throw oneControl(); } + dieOnCircularReference(); int t = 0, f = 0; for (Iterator it = control.iterator(); it.hasNext();) { if (when.evaluate(comp.compare(r, (Resource) it.next()))) { @@ -134,9 +137,13 @@ public class Compare extends DataType implements ResourceSelector { super.dieOnCircularReference(stk, p); } else { if (control != null) { + stk.push(control); DataType.invokeCircularReferenceCheck(control, stk, p); + stk.pop(); } + stk.push(comp); DataType.invokeCircularReferenceCheck(comp, stk, p); + stk.pop(); setChecked(true); } } diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java b/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java index 158fbc3cf..db4edac9e 100755 --- a/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java @@ -120,6 +120,7 @@ public class ResourceSelectorContainer extends DataType { if (o instanceof DataType) { stk.push(o); invokeCircularReferenceCheck((DataType) o, stk, p); + stk.pop(); } } setChecked(true); |