You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2009/01/16 01:05:31 UTC

svn commit: r734864 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/ main/org/apache/tools/ant/types/resources/ tests/antunit/types/resources/comparators/

Author: mbenson
Date: Thu Jan 15 16:05:31 2009
New Revision: 734864

URL: http://svn.apache.org/viewvc?rev=734864&view=rev
Log:
pathconvert preserveduplicates

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java
    ant/core/trunk/src/tests/antunit/types/resources/comparators/test.xml

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PathConvert.java?rev=734864&r1=734863&r2=734864&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PathConvert.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PathConvert.java Thu Jan 15 16:05:31 2009
@@ -18,6 +18,7 @@
 package org.apache.tools.ant.taskdefs;
 
 import java.io.File;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 import java.util.ArrayList;
@@ -31,8 +32,10 @@
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.types.ResourceCollection;
 import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.types.resources.Resources;
 import org.apache.tools.ant.types.resources.Union;
 import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.IdentityMapper;
 
 /**
  * Converts path and classpath information to a specific target OS
@@ -52,7 +55,7 @@
     /**
      * Path to be converted
      */
-    private Union path = null;
+    private Resources path = null;
     /**
      * Reference to path/fileset to convert
      */
@@ -89,6 +92,8 @@
     /** Filename mapper */
     private Mapper mapper = null;
 
+    private boolean preserveDuplicates;
+
     /**
      * Construct a new instance of the PathConvert task.
      */
@@ -191,10 +196,9 @@
         getPath().add(rc);
     }
 
-    private synchronized Union getPath() {
+    private synchronized Resources getPath() {
         if (path == null) {
-            path = new Union();
-            path.setProject(getProject());
+            path = new Resources(getProject());
         }
         return path;
     }
@@ -295,6 +299,24 @@
     }
 
     /**
+     * Set the preserveDuplicates.
+     * @param preserveDuplicates the boolean to set
+     * @since Ant 1.8
+     */
+    public void setPreserveDuplicates(boolean preserveDuplicates) {
+        this.preserveDuplicates = preserveDuplicates;
+    }
+
+    /**
+     * Get the preserveDuplicates.
+     * @return boolean
+     * @since Ant 1.8
+     */
+    public boolean isPreserveDuplicates() {
+        return preserveDuplicates;
+    }
+
+    /**
      * Learn whether the refid attribute of this element been set.
      * @return true if refid is valid.
      */
@@ -307,7 +329,7 @@
      * @throws BuildException if something is invalid.
      */
     public void execute() throws BuildException {
-        Union savedPath = path;
+        Resources savedPath = path;
         String savedPathSep = pathSep; // may be altered in validateSetup
         String savedDirSep = dirSep; // may be altered in validateSetup
 
@@ -335,31 +357,27 @@
 
             StringBuffer rslt = new StringBuffer();
 
-            // Get the list of path components in canonical form
-            String[] elems = path.list();
-
-            if (mapper != null) {
-                FileNameMapper impl = mapper.getImplementation();
-                List ret = new ArrayList();
-                for (int i = 0; i < elems.length; ++i) {
-                    String[] mapped = impl.mapFileName(elems[i]);
-                    for (int m = 0; mapped != null && m < mapped.length; ++m) {
-                        ret.add(mapped[m]);
-                    }
+            ResourceCollection resources = isPreserveDuplicates() ? (ResourceCollection) path : new Union(path);
+            List ret = new ArrayList();
+            FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation();
+            for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
+                String[] mapped = mapperImpl.mapFileName(String.valueOf(iter.next()));
+                for (int m = 0; mapped != null && m < mapped.length; ++m) {
+                    ret.add(mapped[m]);
                 }
-                elems = (String[]) ret.toArray(new String[ret.size()]);
             }
-            for (int i = 0; i < elems.length; i++) {
-                String elem = mapElement(elems[i]); // Apply the path prefix map
+            boolean first = true;
+            for (Iterator mappedIter = ret.iterator(); mappedIter.hasNext(); ) {
+                String elem = mapElement((String) mappedIter.next()); // Apply the path prefix map
 
                 // Now convert the path and file separator characters from the
                 // current os to the target os.
 
-                if (i != 0) {
+                if (first) {
                     rslt.append(pathSep);
+                    first = false;
                 }
-                StringTokenizer stDirectory =
-                    new StringTokenizer(elem, fromDirSep, true);
+                StringTokenizer stDirectory = new StringTokenizer(elem, fromDirSep, true);
 
                 while (stDirectory.hasMoreTokens()) {
                     String token = stDirectory.nextToken();
@@ -373,8 +391,7 @@
                 if (property == null) {
                     log(value);
                 } else {
-                    log("Set property " + property + " = " + value,
-                        Project.MSG_VERBOSE);
+                    log("Set property " + property + " = " + value, Project.MSG_VERBOSE);
                     getProject().setNewProperty(property, value);
                 }
             }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java?rev=734864&r1=734863&r2=734864&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java Thu Jan 15 16:05:31 2009
@@ -28,7 +28,6 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.DataType;
-import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
 
 /**
@@ -42,6 +41,21 @@
     private boolean cache = true;
 
     /**
+     * Create a new BaseResourceCollectionContainer.
+     */
+    public BaseResourceCollectionContainer() {
+        // TODO Auto-generated constructor stub
+    }
+    
+    /**
+     * Create a new BaseResourceCollectionContainer.
+     * @since Ant 1.8
+     */
+    public BaseResourceCollectionContainer(Project project) {
+        setProject(project);
+    }
+
+    /**
      * Set whether to cache collections.
      * @param b boolean cache flag.
      */
@@ -159,8 +173,7 @@
         /* now check each Resource in case the child only
            lets through files from any children IT may have: */
         for (Iterator i = cacheCollection().iterator(); i.hasNext();) {
-            Resource r = (Resource) i.next();
-            if (r.as(FileProvider.class) == null) {
+            if (!(i.next() instanceof FileProvider)) {
                 return false;
             }
         }
@@ -185,7 +198,9 @@
             for (Iterator i = rc.iterator(); i.hasNext();) {
                 Object o = i.next();
                 if (o instanceof DataType) {
-                    pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
+                    stk.push(o);
+                    invokeCircularReferenceCheck((DataType) o, stk, p);
+                    stk.pop();
                 }
             }
             setChecked(true);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java?rev=734864&r1=734863&r2=734864&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java Thu Jan 15 16:05:31 2009
@@ -108,6 +108,19 @@
     private Collection coll;
 
     /**
+     * Create a new Resources.
+     */
+    public Resources() {
+    }
+
+    /**
+     * Create a new Resources.
+     */
+    public Resources(Project project) {
+        setProject(project);
+    }
+
+    /**
      * Add a ResourceCollection.
      * @param c the ResourceCollection to add.
      */
@@ -208,7 +221,7 @@
             for (Iterator i = getNested().iterator(); i.hasNext();) {
                 Object o = i.next();
                 if (o instanceof DataType) {
-                    pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
+                    invokeCircularReferenceCheck((DataType) o, stk, p);
                 }
             }
             setChecked(true);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java?rev=734864&r1=734863&r2=734864&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java Thu Jan 15 16:05:31 2009
@@ -23,6 +23,7 @@
 import java.util.LinkedHashSet;
 import java.util.List;
 
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
 
@@ -48,10 +49,28 @@
     }
 
     /**
+     * Create a new Union.
+     * @param project owning Project
+     */
+    public Union(Project project) {
+        super(project);
+    }
+
+    /**
      * Convenience constructor.
      * @param rc the ResourceCollection to add.
      */
     public Union(ResourceCollection rc) {
+        this(Project.getProject(rc), rc);
+    }
+    
+    /**
+     * Convenience constructor.
+     * @param project owning Project
+     * @param rc the ResourceCollection to add.
+     */
+    public Union(Project project, ResourceCollection rc) {
+        super(project);
         add(rc);
     }
 

Modified: ant/core/trunk/src/tests/antunit/types/resources/comparators/test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/resources/comparators/test.xml?rev=734864&r1=734863&r2=734864&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/resources/comparators/test.xml (original)
+++ ant/core/trunk/src/tests/antunit/types/resources/comparators/test.xml Thu Jan 15 16:05:31 2009
@@ -293,7 +293,7 @@
       <resourcecount refid="testEquals" count="3" />
     </au:assertTrue>
 
-    <pathconvert refid="testEquals" property="testEquals" pathsep="">
+    <pathconvert refid="testEquals" property="testEquals" pathsep="" preserveduplicates="true">
       <mergemapper to="X" />
     </pathconvert>
 



Re: svn commit: r734864 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/ main/org/apache/tools/ant/types/resources/ tests/antunit/types/resources/comparators/

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-01-16, Matt Benson <gu...@yahoo.com> wrote:

> Apparently I didn't have something up to date; will correct!

Looks good now, thanks Matt

Stefan

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


Re: svn commit: r734864 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/ main/org/apache/tools/ant/types/resources/ tests/antunit/types/resources/comparators/

Posted by Matt Benson <gu...@yahoo.com>.
--- Stefan Bodewig <bo...@apache.org> wrote:

> On 2009-01-16, <mb...@apache.org> wrote:
> 
> > Modified:
>
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
> > @@ -159,8 +173,7 @@
> >          /* now check each Resource in case the
> child only
> >             lets through files from any children
> IT may have: */
> >          for (Iterator i =
> cacheCollection().iterator(); i.hasNext();) {
> > -            Resource r = (Resource) i.next();
> > -            if (r.as(FileProvider.class) == null)
> {
> > +            if (!(i.next() instanceof
> FileProvider)) {
> >                  return false;
> >              }
> >          }
> > @@ -185,7 +198,9 @@
> >              for (Iterator i = rc.iterator();
> i.hasNext();) {
> >                  Object o = i.next();
> >                  if (o instanceof DataType) {
> > -                   
> pushAndInvokeCircularReferenceCheck((DataType) o,
> stk, p);
> > +                    stk.push(o);
> > +                   
> invokeCircularReferenceCheck((DataType) o, stk, p);
> > +                    stk.pop();
> >                  }
> >              }
> >              setChecked(true);
> 
> and
> 
> > Modified:
>
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
> > @@ -208,7 +221,7 @@
> >              for (Iterator i =
> getNested().iterator(); i.hasNext();) {
> >                  Object o = i.next();
> >                  if (o instanceof DataType) {
> > -                   
> pushAndInvokeCircularReferenceCheck((DataType) o,
> stk, p);
> > +                   
> invokeCircularReferenceCheck((DataType) o, stk, p);
> >                  }
> >              }
> >              setChecked(true);
> 
> Looks as if you had reverted some of my changes from
> last year, have
> they been causing problems?

Ugh... no, this would be an artifact of the
workspace-switching I went through yesterday while
trying to work through the xalan issue.  Apparently I
didn't have something up to date; will correct!

Thanks,
Matt

> 
> 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: svn commit: r734864 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/ main/org/apache/tools/ant/types/resources/ tests/antunit/types/resources/comparators/

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-01-16, <mb...@apache.org> wrote:

> Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
> @@ -159,8 +173,7 @@
>          /* now check each Resource in case the child only
>             lets through files from any children IT may have: */
>          for (Iterator i = cacheCollection().iterator(); i.hasNext();) {
> -            Resource r = (Resource) i.next();
> -            if (r.as(FileProvider.class) == null) {
> +            if (!(i.next() instanceof FileProvider)) {
>                  return false;
>              }
>          }
> @@ -185,7 +198,9 @@
>              for (Iterator i = rc.iterator(); i.hasNext();) {
>                  Object o = i.next();
>                  if (o instanceof DataType) {
> -                    pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
> +                    stk.push(o);
> +                    invokeCircularReferenceCheck((DataType) o, stk, p);
> +                    stk.pop();
>                  }
>              }
>              setChecked(true);

and

> Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
> @@ -208,7 +221,7 @@
>              for (Iterator i = getNested().iterator(); i.hasNext();) {
>                  Object o = i.next();
>                  if (o instanceof DataType) {
> -                    pushAndInvokeCircularReferenceCheck((DataType) o, stk, p);
> +                    invokeCircularReferenceCheck((DataType) o, stk, p);
>                  }
>              }
>              setChecked(true);

Looks as if you had reverted some of my changes from last year, have
they been causing problems?

Stefan

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