Author: bodewig
Date: Fri Aug 21 14:29:51 2009
New Revision: 806570
URL: http://svn.apache.org/viewvc?rev=806570&view=rev
Log:
provide proper control over caching in <resources>
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTypes/resources.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=806570&r1=806569&r2=806570&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Aug 21 14:29:51 2009
@@ -872,6 +872,9 @@
* <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
=============================================
Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?rev=806570&r1=806569&r2=806570&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/resources.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/resources.html Fri Aug 21 14:29:51 2009
@@ -363,6 +363,19 @@
preserving the order of nested collections as well as
duplicate resources (contrast with <a href="#union">union</a>).
</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>
<p>A group of files. These files are matched by <b>absolute</b> patterns
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java?rev=806570&r1=806569&r2=806570&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java Fri Aug
21 14:29:51 2009
@@ -214,7 +214,10 @@
if (rc == null) {
return;
}
- rcs = (rcs == null) ? new Resources() : rcs;
+ if (rcs == null) {
+ rcs = new Resources();
+ rcs.setCache(true);
+ }
rcs.add(rc);
}
@@ -579,8 +582,10 @@
}
Resources resourcesToDelete = new Resources();
resourcesToDelete.setProject(getProject());
+ resourcesToDelete.setCache(true);
Resources filesetDirs = new Resources();
filesetDirs.setProject(getProject());
+ filesetDirs.setCache(true);
FileSet implicit = null;
if (usedMatchingTask && dir != null && dir.isDirectory()) {
//add the files from the default fileset:
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=806570&r1=806569&r2=806570&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
Fri Aug 21 14:29:51 2009
@@ -67,21 +67,25 @@
};
private class MyCollection extends AbstractCollection {
- private Collection cache;
+ private Collection cached;
MyCollection() {
}
public int 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() {
- 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 Iterator rci = getNested().iterator();
@@ -109,6 +113,7 @@
private Vector rc;
private Collection coll;
+ private boolean cache = false;
/**
* Create a new Resources.
@@ -125,6 +130,14 @@
}
/**
+ * Set whether to cache collections.
+ * @param b boolean cache flag.
+ */
+ public synchronized void setCache(boolean b) {
+ cache = b;
+ }
+
+ /**
* Add a ResourceCollection.
* @param c the ResourceCollection to add.
*/