git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@806570 13f79535-47bb-0310-9956-ffa450edef68master
@@ -872,6 +872,9 @@ Other changes: | |||||
* <propertyfile> now can delete entries. | * <propertyfile> now can delete entries. | ||||
* The <resources> resource collection can now optionally cache its | |||||
contents. | |||||
Changes from Ant 1.7.0 TO Ant 1.7.1 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
============================================= | ============================================= | ||||
@@ -363,6 +363,19 @@ Ant's "legacy" datatypes have been modified to behave as Resource Collections: | |||||
preserving the order of nested collections as well as | preserving the order of nested collections as well as | ||||
duplicate resources (contrast with <a href="#union">union</a>). | duplicate resources (contrast with <a href="#union">union</a>). | ||||
</p> | </p> | ||||
<blockquote> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">cache</td> | |||||
<td valign="top">Whether to cache results</td> | |||||
<td valign="top" align="center">No, default <i>false</i></td> | |||||
</tr> | |||||
</table> | |||||
<h4><a name="files">files</a></h4> | <h4><a name="files">files</a></h4> | ||||
<p>A group of files. These files are matched by <b>absolute</b> patterns | <p>A group of files. These files are matched by <b>absolute</b> patterns | ||||
@@ -214,7 +214,10 @@ public class Delete extends MatchingTask { | |||||
if (rc == null) { | if (rc == null) { | ||||
return; | return; | ||||
} | } | ||||
rcs = (rcs == null) ? new Resources() : rcs; | |||||
if (rcs == null) { | |||||
rcs = new Resources(); | |||||
rcs.setCache(true); | |||||
} | |||||
rcs.add(rc); | rcs.add(rc); | ||||
} | } | ||||
@@ -579,8 +582,10 @@ public class Delete extends MatchingTask { | |||||
} | } | ||||
Resources resourcesToDelete = new Resources(); | Resources resourcesToDelete = new Resources(); | ||||
resourcesToDelete.setProject(getProject()); | resourcesToDelete.setProject(getProject()); | ||||
resourcesToDelete.setCache(true); | |||||
Resources filesetDirs = new Resources(); | Resources filesetDirs = new Resources(); | ||||
filesetDirs.setProject(getProject()); | filesetDirs.setProject(getProject()); | ||||
filesetDirs.setCache(true); | |||||
FileSet implicit = null; | FileSet implicit = null; | ||||
if (usedMatchingTask && dir != null && dir.isDirectory()) { | if (usedMatchingTask && dir != null && dir.isDirectory()) { | ||||
//add the files from the default fileset: | //add the files from the default fileset: | ||||
@@ -67,21 +67,25 @@ public class Resources extends DataType implements ResourceCollection { | |||||
}; | }; | ||||
private class MyCollection extends AbstractCollection { | private class MyCollection extends AbstractCollection { | ||||
private Collection cache; | |||||
private Collection cached; | |||||
MyCollection() { | MyCollection() { | ||||
} | } | ||||
public int size() { | public int size() { | ||||
return getCache().size(); | return getCache().size(); | ||||
} | } | ||||
public synchronized Iterator iterator() { | |||||
return cache != null ? cache.iterator() : new MyIterator(); | |||||
public Iterator iterator() { | |||||
return getCache().iterator(); | |||||
} | } | ||||
private synchronized Collection getCache() { | private synchronized Collection getCache() { | ||||
if (cache == null) { | |||||
cache = CollectionUtils.asCollection(new MyIterator()); | |||||
Collection coll = cached; | |||||
if (coll == null) { | |||||
coll = CollectionUtils.asCollection(new MyIterator()); | |||||
if (cache) { | |||||
cached = coll; | |||||
} | |||||
} | } | ||||
return cache; | |||||
return coll; | |||||
} | } | ||||
private class MyIterator implements Iterator { | private class MyIterator implements Iterator { | ||||
private Iterator rci = getNested().iterator(); | private Iterator rci = getNested().iterator(); | ||||
@@ -109,6 +113,7 @@ public class Resources extends DataType implements ResourceCollection { | |||||
private Vector rc; | private Vector rc; | ||||
private Collection coll; | private Collection coll; | ||||
private boolean cache = false; | |||||
/** | /** | ||||
* Create a new Resources. | * Create a new Resources. | ||||
@@ -124,6 +129,14 @@ public class Resources extends DataType implements ResourceCollection { | |||||
setProject(project); | setProject(project); | ||||
} | } | ||||
/** | |||||
* Set whether to cache collections. | |||||
* @param b boolean cache flag. | |||||
*/ | |||||
public synchronized void setCache(boolean b) { | |||||
cache = b; | |||||
} | |||||
/** | /** | ||||
* Add a ResourceCollection. | * Add a ResourceCollection. | ||||
* @param c the ResourceCollection to add. | * @param c the ResourceCollection to add. | ||||