You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/11/28 16:42:06 UTC

svn commit: r721523 - in /ant/core/trunk/src/main/org/apache/tools/ant/types: ./ resources/ resources/comparators/ resources/selectors/

Author: bodewig
Date: Fri Nov 28 07:42:05 2008
New Revision: 721523

URL: http://svn.apache.org/viewvc?rev=721523&view=rev
Log:
first step of reference-check auditing after I re-understood how things are supposed to work.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/Resource.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/XMLCatalog.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Restrict.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Tokens.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/ArchiveFileSet.java Fri Nov 28 07:42:05 2008
@@ -19,6 +19,7 @@
 
 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 @@
             throw new BuildException(ERROR_DIR_AND_SRC_ATTRIBUTES);
         }
         this.src = src;
+        setChecked(false);
     }
 
     /**
@@ -256,6 +258,7 @@
      * @return a directory scanner
      */
     public DirectoryScanner getDirectoryScanner(Project p) {
+        dieOnCircularReference();
         if (isReference()) {
             return getRef(p).getDirectoryScanner(p);
         }
@@ -512,4 +515,21 @@
             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);
+        }
+    }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java Fri Nov 28 07:42:05 2008
@@ -92,6 +92,7 @@
             }
         }
         container.add(fileNameMapper);
+        setChecked(false);
     }
 
     /**
@@ -139,6 +140,7 @@
         if (this.classpath == null) {
             this.classpath = new Path(getProject());
         }
+        setChecked(false);
         return this.classpath.createPath();
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java Fri Nov 28 07:42:05 2008
@@ -119,6 +119,7 @@
                 throw new BuildException("Cannot have > 1 <inputmapper>");
             }
         }
+        setChecked(false);
         this.inputMapper = inputMapper;
     }
 
@@ -138,6 +139,7 @@
                 throw new BuildException("Cannot have > 1 <outputmapper>");
             }
         }
+        setChecked(false);
         this.outputMapper = outputMapper;
     }
 
@@ -157,6 +159,7 @@
                 throw new BuildException("Cannot have > 1 <errormapper>");
             }
         }
+        setChecked(false);
         this.errorMapper = errorMapper;
     }
 
@@ -388,6 +391,7 @@
         FilterChain result = new FilterChain();
         result.setProject(getProject());
         inputFilterChains.add(result);
+        setChecked(false);
         return result;
     }
 
@@ -402,6 +406,7 @@
         FilterChain result = new FilterChain();
         result.setProject(getProject());
         outputFilterChains.add(result);
+        setChecked(false);
         return result;
     }
 
@@ -416,6 +421,7 @@
         FilterChain result = new FilterChain();
         result.setProject(getProject());
         errorFilterChains.add(result);
+        setChecked(false);
         return result;
     }
 
@@ -438,6 +444,7 @@
             getRef().configure(redirector, sourcefile);
             return;
         }
+        dieOnCircularReference();
         if (alwaysLog != null) {
             redirector.setAlwaysLog(alwaysLog.booleanValue());
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/Resource.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/Resource.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/Resource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/Resource.java Fri Nov 28 07:42:05 2008
@@ -434,7 +434,7 @@
      * <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;

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/XMLCatalog.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/XMLCatalog.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/XMLCatalog.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/XMLCatalog.java Fri Nov 28 07:42:05 2008
@@ -27,6 +27,7 @@
 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 @@
         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
      */

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java Fri Nov 28 07:42:05 2008
@@ -23,6 +23,7 @@
 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 @@
                                      + " nested into mappedresources",
                                      getLocation());
         }
+        setChecked(false);
         nested = c;
     }
 
@@ -69,6 +71,7 @@
             throw new BuildException("Cannot define more than one mapper",
                                      getLocation());
         }
+        setChecked(false);
         mapper = new Mapper(getProject());
         return mapper;
     }
@@ -114,6 +117,17 @@
     }
 
     /**
+     * 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 @@
             throw new BuildException("A nested resource collection element is"
                                      + " required", getLocation());
         }
+        dieOnCircularReference();
     }
 
     private static class MappedIterator implements Iterator {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java Fri Nov 28 07:42:05 2008
@@ -66,6 +66,7 @@
             throw new BuildException("only single argument resource collections"
                                      + " are supported");
         }
+        setChecked(false);
         resource = (Resource) a.iterator().next();
     }
 
@@ -195,6 +196,7 @@
         if (resource == null) {
             throw new BuildException("no resource specified");
         }
+        dieOnCircularReference();
         return resource;
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Restrict.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Restrict.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Restrict.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Restrict.java Fri Nov 28 07:42:05 2008
@@ -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 @@
             return;
         }
         w.add(c);
+        setChecked(false);
     }
 
     /**
@@ -145,4 +148,19 @@
         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);
+        }
+    }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java Fri Nov 28 07:42:05 2008
@@ -126,6 +126,7 @@
         }
         comp.add(c);
         FailFast.invalidate(this);
+        setChecked(false);
     }
 
     /**
@@ -143,7 +144,9 @@
         if (isReference()) {
             super.dieOnCircularReference(stk, p);
         } else {
+            stk.push(comp);
             DataType.invokeCircularReferenceCheck(comp, stk, p);
+            stk.pop();
             setChecked(true);
         }
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Tokens.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Tokens.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Tokens.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Tokens.java Fri Nov 28 07:42:05 2008
@@ -102,6 +102,7 @@
             throw new BuildException("Only one nested tokenizer allowed.");
         }
         this.tokenizer = tokenizer;
+        setChecked(false);
     }
 
     /**
@@ -122,6 +123,7 @@
             if (tokenizer instanceof DataType) {
                 stk.push(tokenizer);
                 invokeCircularReferenceCheck((DataType) tokenizer, stk, p);
+                stk.pop();
             }
             setChecked(true);
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java Fri Nov 28 07:42:05 2008
@@ -48,6 +48,7 @@
         }
         v = (v == null) ? new Vector() : v;
         v.add(c);
+        setChecked(false);
     }
 
     /**
@@ -115,6 +116,7 @@
                     if (o instanceof DataType) {
                         stk.push(o);
                         invokeCircularReferenceCheck((DataType) o, stk, p);
+                        stk.pop();
                     }
                 }
             }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java Fri Nov 28 07:42:05 2008
@@ -58,6 +58,7 @@
             throw noChildrenAllowed();
         }
         comp.add(c);
+        setChecked(false);
     }
 
     /**
@@ -95,6 +96,7 @@
             throw oneControl();
         }
         control = new Union();
+        setChecked(false);
         return control;
     }
 
@@ -107,6 +109,7 @@
         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 @@
             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);
         }
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java?rev=721523&r1=721522&r2=721523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java Fri Nov 28 07:42:05 2008
@@ -120,6 +120,7 @@
                 if (o instanceof DataType) {
                     stk.push(o);
                     invokeCircularReferenceCheck((DataType) o, stk, p);
+                    stk.pop();
                 }
             }
             setChecked(true);