mbenson 2005/03/04 15:41:21 Modified: src/main/org/apache/tools/ant DirectoryScanner.java src/testcases/org/apache/tools/ant DirectoryScannerTest.java Log: By popular demand: Do not scan directories if their contents are excluded. Changed scannedDirs from a cache to a result and added a gettor method with a warning in the Javadoc that it was a testing method only. Revision Changes Path 1.93 +27 -2 ant/src/main/org/apache/tools/ant/DirectoryScanner.java Index: DirectoryScanner.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v retrieving revision 1.92 retrieving revision 1.93 diff -u -r1.92 -r1.93 --- DirectoryScanner.java 3 Mar 2005 20:42:43 -0000 1.92 +++ DirectoryScanner.java 4 Mar 2005 23:41:21 -0000 1.93 @@ -920,6 +920,7 @@ dirsExcluded = new Vector(); dirsDeselected = new Vector(); everythingIncluded = (basedir != null); + scannedDirs.clear(); } /** @@ -1118,7 +1119,7 @@ dirsDeselected.addElement(name); } everythingIncluded &= included; - if (fast && couldHoldIncluded(name)) { + if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) { scandir(file, name + File.separator, fast); } } @@ -1207,6 +1208,22 @@ } /** + * Test whether all contents of the specified directory must be excluded. + * @param name the directory name to check. + */ + private boolean contentsExcluded(String name) { + name = (name.endsWith(File.separator)) ? name : name + File.separator; + for (int i = 0; i < excludes.length; i++) { + String e = excludes[i]; + if (e.endsWith(File.separator + "**") && SelectorUtils.matchPath( + e.substring(0, e.length() - 2), name, isCaseSensitive())) { + return true; + } + } + return false; + } + + /** * Test whether or not a name matches against at least one exclude * pattern. * @@ -1566,13 +1583,21 @@ } /** + * This method is of interest for testing purposes. The returned + * Set is live and should not be modified. + * @return the Set of relative directory names that have been scanned. + */ + public Set getScannedDirs() { + return scannedDirs; + } + + /** * Clear internal caches. * * @since Ant 1.6 */ private synchronized void clearCaches() { fileListMap.clear(); - scannedDirs.clear(); includeNonPatterns.clear(); excludeNonPatterns.clear(); includePatterns = null; 1.33 +14 -0 ant/src/testcases/org/apache/tools/ant/DirectoryScannerTest.java Index: DirectoryScannerTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/DirectoryScannerTest.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- DirectoryScannerTest.java 25 Feb 2005 13:15:41 -0000 1.32 +++ DirectoryScannerTest.java 4 Mar 2005 23:41:21 -0000 1.33 @@ -26,6 +26,7 @@ import junit.framework.AssertionFailedError; import java.io.File; import java.io.IOException; +import java.util.Set; import java.util.TreeSet; import java.util.Iterator; @@ -397,6 +398,19 @@ } + public void testIsExcludedDirectoryScanned() { + getProject().executeTarget("children-of-excluded-dir-setup"); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] {"**/gamma/**"}); + ds.setFollowSymlinks(false); + ds.scan(); + Set set = ds.getScannedDirs(); + assertFalse("empty set", set.isEmpty()); + String s = "alpha/beta/gamma/".replace('/', File.separatorChar); + assertFalse("scanned " + s, set.contains(s)); + } + private void compareFiles(DirectoryScanner ds, String[] expectedFiles, String[] expectedDirectories) { String includedFiles[] = ds.getIncludedFiles();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]