From abe9743630494f0dfa29498bad1a450bd2174123 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig <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:
<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.