From abe9743630494f0dfa29498bad1a450bd2174123 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 27 Aug 2009 14:08:13 +0000 Subject: [PATCH] Optionally enable caching for . Should help in situations like PR 45696 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@808421 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 ++ docs/manual/using.html | 14 +++++++++++++- src/main/org/apache/tools/ant/types/Path.java | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 55427972b..4f314c04b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -934,6 +934,8 @@ Other changes: attribute different from the . Bugzilla Report 37763. + * can now optionally cache its contents. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/docs/manual/using.html b/docs/manual/using.html index de8ae3c2e..32b790b66 100644 --- a/docs/manual/using.html +++ b/docs/manual/using.html @@ -551,6 +551,18 @@ you can define them with a <path> element at the same level as targets, and reference them via their id attribute--see References for an example.

+ +

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 cache 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 cache still is false). Even if you are using the + path only in a single task it may improve overall performance to set + cache to true if you are using complex nested + constructs.

+

A path-like structure can include a reference to another path-like structure (a path being itself a resource collection) via nested <path> elements:

@@ -563,7 +575,7 @@ via nested <path> elements:

<pathelement location="classes"/> </path> - <path id="tests.path"> + <path id="tests.path" cache="true"> <path refid="base.path"/> <pathelement location="testclasses"/> </path> diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index cc97e28bc..be39099bb 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -78,6 +78,11 @@ public class Path extends DataType implements Cloneable, ResourceCollection { 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 @@ public class Path extends DataType implements Cloneable, ResourceCollection { private Boolean preserveBC; private Union union = null; + private boolean cache = false; /** * Invoked by IntrospectionHelper for setXXX(Path p) @@ -280,7 +286,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { if (union == null) { union = new Union(); union.setProject(getProject()); - union.setCache(false); + union.setCache(cache); } union.add(c); setChecked(false); @@ -348,6 +354,17 @@ public class Path extends DataType implements Cloneable, ResourceCollection { } } + /** + * 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.