You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/09/17 18:12:54 UTC
svn commit: r696355 - in /ant/core/trunk/src/main/org/apache/tools/ant:
DirectoryScanner.java types/selectors/TokenizedPath.java
Author: bodewig
Date: Wed Sep 17 09:12:53 2008
New Revision: 696355
URL: http://svn.apache.org/viewvc?rev=696355&view=rev
Log:
Bring back memoization of File.list
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java?rev=696355&r1=696354&r2=696355&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java Wed Sep 17 09:12:53 2008
@@ -287,6 +287,11 @@
private Map fileListMap = new HashMap();
/**
+ * Uses fileListMap to cache directory listings.
+ */
+ private final TokenizedPath.FileLister fileLister = new CachedFileLister();
+
+ /**
* List of all scanned directories.
*
* @since Ant 1.6
@@ -957,7 +962,8 @@
: FILE_UTILS.removeLeadingPath(canonBase,
getCanonicalFile(myfile));
if (!path.equals(currentelement) || ON_VMS) {
- myfile = currentPath.findFile(basedir, true);
+ myfile = currentPath.findFile(basedir, true,
+ fileLister);
if (myfile != null && basedir != null) {
currentelement = FILE_UTILS.removeLeadingPath(
basedir, myfile);
@@ -974,7 +980,7 @@
}
if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) {
- File f = currentPath.findFile(basedir, false);
+ File f = currentPath.findFile(basedir, false, fileLister);
if (f != null && f.exists()) {
// adapt currentelement to the case we've
// actually found
@@ -1896,4 +1902,9 @@
return new File(getCanonicalPath(file));
}
+ private class CachedFileLister implements TokenizedPath.FileLister {
+ public String[] list(File f) {
+ return DirectoryScanner.this.list(f);
+ }
+ }
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java?rev=696355&r1=696354&r2=696355&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java Wed Sep 17 09:12:53 2008
@@ -105,7 +105,7 @@
* @param cs whether to scan case-sensitively.
* @return File object that points to the file in question or null.
*/
- public File findFile(File base, final boolean cs) {
+ public File findFile(File base, final boolean cs, FileLister fileLister) {
String[] tokens = tokenizedPath;
if (FileUtils.isAbsolutePath(path)) {
if (base == null) {
@@ -123,7 +123,7 @@
tokens = SelectorUtils.tokenizePathAsArray(s);
}
}
- return findFile(base, tokens, cs);
+ return findFile(base, tokens, cs, fileLister);
}
/**
@@ -170,12 +170,12 @@
* @return File object that points to the file in question or null.
*/
private static File findFile(File base, final String[] pathElements,
- final boolean cs) {
+ final boolean cs, FileLister fileLister) {
for (int current = 0; current < pathElements.length; current++) {
if (!base.isDirectory()) {
return null;
}
- String[] files = base.list();
+ String[] files = fileLister.list(base);
if (files == null) {
throw new BuildException("IO error scanning directory "
+ base.getAbsolutePath());
@@ -206,4 +206,20 @@
public TokenizedPattern toPattern() {
return new TokenizedPattern(path, tokenizedPath);
}
+
+ /**
+ * Helper that obtains the listing of a directory.
+ */
+ public static interface FileLister {
+ String[] list(File file);
+ }
+
+ /**
+ * Default implementation using File.list().
+ */
+ public static final class DefaultLister implements FileLister {
+ public String[] list(File file) {
+ return file.list();
+ }
+ }
}