Author: bodewig
Date: Thu Aug 27 14:08:13 2009
New Revision: 808421

URL: http://svn.apache.org/viewvc?rev=808421&view=rev
Log:
Optionally enable caching for <path>.  Should help in situations like PR 45696

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/using.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/Path.java

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=808421&r1=808420&r2=808421&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Aug 27 14:08:13 2009
@@ -934,6 +934,8 @@
    attribute different from the <classfileset>.
    Bugzilla Report 37763.
 
+ * <path> can now optionally cache its contents.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/using.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/using.html?rev=808421&r1=808420&r2=808421&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/using.html (original)
+++ ant/core/trunk/docs/manual/using.html Thu Aug 27 14:08:13 2009
@@ -551,6 +551,18 @@
 same level as <i>target</i>s, and reference them via their
 <i>id</i> attribute--see <a href="#references">References</a> for an
 example.</p>
+
+<p>By default a path like structure will re-evaluate all nested
+  resource collections whenever it is used, which may lead to
+  unnecessary re-scanning of the filesystem.  Since Ant 1.8.0 path has
+  an optional <i>cache</i> attribute, if it is set to true, the path
+  instance will only scan its nested resource collections once and
+  assume it doesn't change during the build anymore (the default
+  for <i>cache</i> still is <i>false</i>).  Even if you are using the
+  path only in a single task it may improve overall performance to set
+  <i>cache</i> to <i>true</i> if you are using complex nested
+  constructs.</p>
+
 <p>A path-like structure can include a reference to another path-like
 structure (a path being itself a resource collection)
 via nested <code>&lt;path&gt;</code> elements:</p>
@@ -563,7 +575,7 @@
       &lt;pathelement location=&quot;classes&quot;/&gt;
     &lt;/path&gt;
 
-    &lt;path id=&quot;tests.path&quot;&gt;
+    &lt;path id=&quot;tests.path&quot; cache=&quot;true&quot;&gt;
       &lt;path refid=&quot;base.path&quot;/&gt;
       &lt;pathelement location=&quot;testclasses&quot;/&gt;
     &lt;/path&gt;

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/Path.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/Path.java?rev=808421&r1=808420&r2=808421&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/Path.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/Path.java Thu Aug 27 
14:08:13 2009
@@ -78,6 +78,11 @@
     public static Path systemBootClasspath =
         new Path(null, System.getProperty("sun.boot.class.path"));
 
+    static {
+        systemClasspath.setCache(true);
+        systemBootClasspath.setCache(true);
+    }
+
     private static final Iterator EMPTY_ITERATOR
         = Collections.EMPTY_SET.iterator();
 
@@ -145,6 +150,7 @@
     private Boolean preserveBC;
 
     private Union union = null;
+    private boolean cache = false;
 
     /**
      * Invoked by IntrospectionHelper for <code>setXXX(Path p)</code>
@@ -280,7 +286,7 @@
         if (union == null) {
             union = new Union();
             union.setProject(getProject());
-            union.setCache(false);
+            union.setCache(cache);
         }
         union.add(c);
         setChecked(false);
@@ -349,6 +355,17 @@
     }
 
     /**
+     * Whether to cache the current path.
+     */
+    public void setCache(boolean b) {
+        checkAttributesAllowed();
+        cache = b;
+        if (union != null) {
+            union.setCache(b);
+        }
+    }
+
+    /**
      * Returns all path elements defined by this and nested path objects.
      * @return list of path elements.
      */


Reply via email to