Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 43509 invoked from network); 21 Apr 2010 08:31:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Apr 2010 08:31:49 -0000 Received: (qmail 15802 invoked by uid 500); 21 Apr 2010 08:31:49 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 15717 invoked by uid 500); 21 Apr 2010 08:31:47 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 15707 invoked by uid 99); 21 Apr 2010 08:31:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Apr 2010 08:31:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Apr 2010 08:31:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C846523889B3; Wed, 21 Apr 2010 08:30:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r936200 - in /ant/core/trunk: ./ docs/manual/CoreTypes/ src/main/org/apache/tools/ant/types/resources/ src/tests/antunit/taskdefs/ Date: Wed, 21 Apr 2010 08:30:59 -0000 To: notifications@ant.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100421083059.C846523889B3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Wed Apr 21 08:30:59 2010 New Revision: 936200 URL: http://svn.apache.org/viewvc?rev=936200&view=rev Log: Add enableMultipleMappings and cache attributes to mappedresources Modified: ant/core/trunk/WHATSNEW ant/core/trunk/docs/manual/CoreTypes/resources.html ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=936200&r1=936199&r2=936200&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Apr 21 08:30:59 2010 @@ -138,6 +138,9 @@ Other changes: * Added SimpleBigProjectLogger, intermediate between NoBannerLogger and BigProjectLogger. + * supports new attributes enablemultiplemappings + and cache. + Changes from Ant 1.8.0RC1 TO Ant 1.8.0 ====================================== Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?rev=936200&r1=936199&r2=936200&view=diff ============================================================================== --- ant/core/trunk/docs/manual/CoreTypes/resources.html (original) +++ ant/core/trunk/docs/manual/CoreTypes/resources.html Wed Apr 21 08:30:59 2010 @@ -1081,9 +1081,32 @@ larger collection. Since Ant 1.7 use mappedresources with tasks that only allow file-system based resources.

-

mappedresources doesn't support any attributes.

-
+

Parameters specified as attributes

+ + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
cacheWhether to cache results; enabling + may improve performance. Since Ant 1.8.1No, default false
enablemultiplemappings + If true the the collection will use all the mappings for a + given source path. If false the it will only process the first + resource. + since Ant 1.8.1.No - defaults to false.
+

Parameters specified as nested elements

A single resource collection is required.

A single mapper can be used to map Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java?rev=936200&r1=936199&r2=936200&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java Wed Apr 21 08:30:59 2010 @@ -75,4 +75,28 @@ public class MappedResource extends Reso ? null : getResource().as(clazz); } + /** + * Get the hash code for this Resource. + * @since Ant 1.8.1 + */ + public int hashCode() { + String n = getName(); + return n == null ? super.hashCode() : n.hashCode(); + } + + /** + * Equality check based on the resource's name in addition to the + * resource itself. + * @since Ant 1.8.1 + */ + public boolean equals(Object other) { + if (other == null || !other.getClass().equals(getClass())) { + return false; + } + MappedResource m = (MappedResource) other; + String myName = getName(); + String otherName = m.getName(); + return (myName == null ? otherName == null : myName.equals(otherName)) + && getResource().equals(m.getResource()); + } } 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=936200&r1=936199&r2=936200&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 Wed Apr 21 08:30:59 2010 @@ -17,6 +17,8 @@ */ package org.apache.tools.ant.types.resources; +import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.Stack; import org.apache.tools.ant.BuildException; @@ -28,6 +30,7 @@ import org.apache.tools.ant.types.Resour import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.IdentityMapper; +import org.apache.tools.ant.util.MergingMapper; /** * Wrapper around a resource collections that maps the names of the @@ -39,6 +42,9 @@ public class MappedResourceCollection private ResourceCollection nested = null; private Mapper mapper = null; + private boolean enableMultipleMappings = false; + private boolean cache = false; + private Collection cachedColl = null; /** * Adds the required nested ResourceCollection. @@ -55,6 +61,7 @@ public class MappedResourceCollection getLocation()); } setChecked(false); + cachedColl = null; nested = c; } @@ -73,6 +80,7 @@ public class MappedResourceCollection } setChecked(false); mapper = new Mapper(getProject()); + cachedColl = null; return mapper; } @@ -86,6 +94,29 @@ public class MappedResourceCollection } /** + * Set method of handling mappers that return multiple + * mappings for a given source path. + * @param enableMultipleMappings If true the type will + * use all the mappings for a given source path, if + * false, only the first mapped name is + * processed. + * By default, this setting is false to provide backward + * compatibility with earlier releases. + * @since Ant 1.8.1 + */ + public void setEnableMultipleMappings(boolean enableMultipleMappings) { + this.enableMultipleMappings = enableMultipleMappings; + } + + /** + * Set whether to cache collections. + * @since Ant 1.8.1 + */ + public void setCache(boolean cache) { + this.cache = cache; + } + + /** * {@inheritDoc} */ public boolean isFilesystemOnly() { @@ -105,7 +136,7 @@ public class MappedResourceCollection return ((MappedResourceCollection) getCheckedRef()).size(); } checkInitialized(); - return nested.size(); + return cacheCollection().size(); } /** @@ -116,7 +147,7 @@ public class MappedResourceCollection return ((MappedResourceCollection) getCheckedRef()).iterator(); } checkInitialized(); - return new MappedIterator(nested.iterator(), mapper); + return cacheCollection().iterator(); } /** @@ -140,6 +171,7 @@ public class MappedResourceCollection (MappedResourceCollection) super.clone(); c.nested = nested; c.mapper = mapper; + c.cachedColl = null; return c; } catch (CloneNotSupportedException e) { throw new BuildException(e); @@ -180,30 +212,32 @@ public class MappedResourceCollection dieOnCircularReference(); } - private static class MappedIterator implements Iterator { - private final Iterator sourceIterator; - private final FileNameMapper mapper; - - private MappedIterator(Iterator source, Mapper m) { - sourceIterator = source; - if (m != null) { - mapper = m.getImplementation(); + private synchronized Collection cacheCollection() { + if (cachedColl == null || !cache) { + cachedColl = getCollection(); + } + return cachedColl; + } + + private Collection getCollection() { + Collection collected = new ArrayList(); + FileNameMapper m = + mapper != null ? mapper.getImplementation() : new IdentityMapper(); + for (Iterator iter = nested.iterator(); iter.hasNext(); ) { + Resource r = (Resource) iter.next(); + if (enableMultipleMappings) { + String[] n = m.mapFileName(r.getName()); + if (n != null) { + for (int i = 0; i < n.length; i++) { + collected.add(new MappedResource(r, + new MergingMapper(n[i])) + ); + } + } } else { - mapper = new IdentityMapper(); + collected.add(new MappedResource(r, m)); } } - - public boolean hasNext() { - return sourceIterator.hasNext(); - } - - public Object next() { - return new MappedResource((Resource) sourceIterator.next(), - mapper); - } - - public void remove() { - throw new UnsupportedOperationException(); - } + return collected; } } Modified: ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml?rev=936200&r1=936199&r2=936200&view=diff ============================================================================== --- ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml (original) +++ ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml Wed Apr 21 08:30:59 2010 @@ -116,6 +116,48 @@ public class NullByteStreamResource exte actual="${output}/bar.txt"/> + + + + Hello, world! + + + + + + + + + + + + + + + + + + + + Hello, world! + + + + + + + + + + + + + + +