|
@@ -17,6 +17,8 @@ |
|
|
*/ |
|
|
*/ |
|
|
package org.apache.tools.ant.types.resources; |
|
|
package org.apache.tools.ant.types.resources; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Collection; |
|
|
import java.util.Iterator; |
|
|
import java.util.Iterator; |
|
|
import java.util.Stack; |
|
|
import java.util.Stack; |
|
|
import org.apache.tools.ant.BuildException; |
|
|
import org.apache.tools.ant.BuildException; |
|
@@ -28,6 +30,7 @@ import org.apache.tools.ant.types.Resource; |
|
|
import org.apache.tools.ant.types.ResourceCollection; |
|
|
import org.apache.tools.ant.types.ResourceCollection; |
|
|
import org.apache.tools.ant.util.FileNameMapper; |
|
|
import org.apache.tools.ant.util.FileNameMapper; |
|
|
import org.apache.tools.ant.util.IdentityMapper; |
|
|
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 |
|
|
* Wrapper around a resource collections that maps the names of the |
|
@@ -39,6 +42,9 @@ public class MappedResourceCollection |
|
|
|
|
|
|
|
|
private ResourceCollection nested = null; |
|
|
private ResourceCollection nested = null; |
|
|
private Mapper mapper = null; |
|
|
private Mapper mapper = null; |
|
|
|
|
|
private boolean enableMultipleMappings = false; |
|
|
|
|
|
private boolean cache = false; |
|
|
|
|
|
private Collection cachedColl = null; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Adds the required nested ResourceCollection. |
|
|
* Adds the required nested ResourceCollection. |
|
@@ -55,6 +61,7 @@ public class MappedResourceCollection |
|
|
getLocation()); |
|
|
getLocation()); |
|
|
} |
|
|
} |
|
|
setChecked(false); |
|
|
setChecked(false); |
|
|
|
|
|
cachedColl = null; |
|
|
nested = c; |
|
|
nested = c; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -73,6 +80,7 @@ public class MappedResourceCollection |
|
|
} |
|
|
} |
|
|
setChecked(false); |
|
|
setChecked(false); |
|
|
mapper = new Mapper(getProject()); |
|
|
mapper = new Mapper(getProject()); |
|
|
|
|
|
cachedColl = null; |
|
|
return mapper; |
|
|
return mapper; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -85,6 +93,29 @@ public class MappedResourceCollection |
|
|
createMapper().add(fileNameMapper); |
|
|
createMapper().add(fileNameMapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 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} |
|
|
* {@inheritDoc} |
|
|
*/ |
|
|
*/ |
|
@@ -105,7 +136,7 @@ public class MappedResourceCollection |
|
|
return ((MappedResourceCollection) getCheckedRef()).size(); |
|
|
return ((MappedResourceCollection) getCheckedRef()).size(); |
|
|
} |
|
|
} |
|
|
checkInitialized(); |
|
|
checkInitialized(); |
|
|
return nested.size(); |
|
|
|
|
|
|
|
|
return cacheCollection().size(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -116,7 +147,7 @@ public class MappedResourceCollection |
|
|
return ((MappedResourceCollection) getCheckedRef()).iterator(); |
|
|
return ((MappedResourceCollection) getCheckedRef()).iterator(); |
|
|
} |
|
|
} |
|
|
checkInitialized(); |
|
|
checkInitialized(); |
|
|
return new MappedIterator(nested.iterator(), mapper); |
|
|
|
|
|
|
|
|
return cacheCollection().iterator(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -140,6 +171,7 @@ public class MappedResourceCollection |
|
|
(MappedResourceCollection) super.clone(); |
|
|
(MappedResourceCollection) super.clone(); |
|
|
c.nested = nested; |
|
|
c.nested = nested; |
|
|
c.mapper = mapper; |
|
|
c.mapper = mapper; |
|
|
|
|
|
c.cachedColl = null; |
|
|
return c; |
|
|
return c; |
|
|
} catch (CloneNotSupportedException e) { |
|
|
} catch (CloneNotSupportedException e) { |
|
|
throw new BuildException(e); |
|
|
throw new BuildException(e); |
|
@@ -180,30 +212,32 @@ public class MappedResourceCollection |
|
|
dieOnCircularReference(); |
|
|
dieOnCircularReference(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static class MappedIterator implements Iterator { |
|
|
|
|
|
private final Iterator sourceIterator; |
|
|
|
|
|
private final FileNameMapper mapper; |
|
|
|
|
|
|
|
|
private synchronized Collection cacheCollection() { |
|
|
|
|
|
if (cachedColl == null || !cache) { |
|
|
|
|
|
cachedColl = getCollection(); |
|
|
|
|
|
} |
|
|
|
|
|
return cachedColl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private MappedIterator(Iterator source, Mapper m) { |
|
|
|
|
|
sourceIterator = source; |
|
|
|
|
|
if (m != null) { |
|
|
|
|
|
mapper = m.getImplementation(); |
|
|
|
|
|
|
|
|
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 { |
|
|
} 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; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |