Browse Source

minor performace tweaks

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@696144 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
a98a49253b
2 changed files with 24 additions and 23 deletions
  1. +17
    -21
      src/main/org/apache/tools/ant/DirectoryScanner.java
  2. +7
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java

+ 17
- 21
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -26,9 +26,9 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Stack;
import java.util.Vector; import java.util.Vector;


import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.taskdefs.condition.Os;
@@ -196,7 +196,7 @@ public class DirectoryScanner
* *
* @see #addDefaultExcludes() * @see #addDefaultExcludes()
*/ */
private static Vector defaultExcludes = new Vector();
private static Set defaultExcludes = new HashSet();
static { static {
resetDefaultExcludes(); resetDefaultExcludes();
} }
@@ -532,7 +532,7 @@ public class DirectoryScanner
* *
* @return An array of <code>String</code> based on the current * @return An array of <code>String</code> based on the current
* contents of the <code>defaultExcludes</code> * contents of the <code>defaultExcludes</code>
* <code>Vector</code>.
* <code>Set</code>.
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
@@ -552,11 +552,7 @@ public class DirectoryScanner
* @since Ant 1.6 * @since Ant 1.6
*/ */
public static boolean addDefaultExclude(String s) { public static boolean addDefaultExclude(String s) {
if (defaultExcludes.indexOf(s) == -1) {
defaultExcludes.add(s);
return true;
}
return false;
return defaultExcludes.add(s);
} }


/** /**
@@ -580,7 +576,7 @@ public class DirectoryScanner
* @since Ant 1.6 * @since Ant 1.6
*/ */
public static void resetDefaultExcludes() { public static void resetDefaultExcludes() {
defaultExcludes = new Vector();
defaultExcludes = new HashSet();
for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
defaultExcludes.add(DEFAULTEXCLUDES[i]); defaultExcludes.add(DEFAULTEXCLUDES[i]);
} }
@@ -1128,17 +1124,17 @@ public class DirectoryScanner
+ dir.getAbsolutePath() + "'"); + dir.getAbsolutePath() + "'");
} }
} }
scandir(dir, vpath, fast, newfiles, new Stack());
scandir(dir, vpath, fast, newfiles, new LinkedList());
} }


private void scandir(File dir, String vpath, boolean fast, private void scandir(File dir, String vpath, boolean fast,
String[] newfiles, Stack directoryNamesFollowed) {
String[] newfiles, LinkedList directoryNamesFollowed) {
// avoid double scanning of directories, can only happen in fast mode // avoid double scanning of directories, can only happen in fast mode
if (fast && hasBeenScanned(vpath)) { if (fast && hasBeenScanned(vpath)) {
return; return;
} }
if (!followSymlinks) { if (!followSymlinks) {
Vector noLinks = new Vector();
ArrayList noLinks = new ArrayList();
for (int i = 0; i < newfiles.length; i++) { for (int i = 0; i < newfiles.length; i++) {
try { try {
if (FILE_UTILS.isSymbolicLink(dir, newfiles[i])) { if (FILE_UTILS.isSymbolicLink(dir, newfiles[i])) {
@@ -1147,19 +1143,19 @@ public class DirectoryScanner
(file.isDirectory() (file.isDirectory()
? dirsExcluded : filesExcluded).addElement(name); ? dirsExcluded : filesExcluded).addElement(name);
} else { } else {
noLinks.addElement(newfiles[i]);
noLinks.add(newfiles[i]);
} }
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "IOException caught while checking " String msg = "IOException caught while checking "
+ "for links, couldn't get canonical path!"; + "for links, couldn't get canonical path!";
// will be caught and redirected to Ant's logging system // will be caught and redirected to Ant's logging system
System.err.println(msg); System.err.println(msg);
noLinks.addElement(newfiles[i]);
noLinks.add(newfiles[i]);
} }
} }
newfiles = (String[]) (noLinks.toArray(new String[noLinks.size()])); newfiles = (String[]) (noLinks.toArray(new String[noLinks.size()]));
} else { } else {
directoryNamesFollowed.push(dir.getName());
directoryNamesFollowed.addFirst(dir.getName());
} }


for (int i = 0; i < newfiles.length; i++) { for (int i = 0; i < newfiles.length; i++) {
@@ -1205,7 +1201,7 @@ public class DirectoryScanner
} }


if (followSymlinks) { if (followSymlinks) {
directoryNamesFollowed.pop();
directoryNamesFollowed.removeFirst();
} }
} }


@@ -1235,7 +1231,7 @@ public class DirectoryScanner


private void accountForIncludedDir(String name, File file, boolean fast, private void accountForIncludedDir(String name, File file, boolean fast,
String[] children, String[] children,
Stack directoryNamesFollowed) {
LinkedList directoryNamesFollowed) {
processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected); processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected);
if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) { if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) {
scandir(file, name + File.separator, fast, children, scandir(file, name + File.separator, fast, children,
@@ -1831,22 +1827,22 @@ public class DirectoryScanner
* @since Ant 1.8.0 * @since Ant 1.8.0
*/ */
private boolean causesIllegalSymlinkLoop(String dirName, File parent, private boolean causesIllegalSymlinkLoop(String dirName, File parent,
Stack directoryNamesFollowed) {
LinkedList directoryNamesFollowed) {
try { try {
if (CollectionUtils.frequency(directoryNamesFollowed, dirName) if (CollectionUtils.frequency(directoryNamesFollowed, dirName)
>= maxLevelsOfSymlinks >= maxLevelsOfSymlinks
&& FILE_UTILS.isSymbolicLink(parent, dirName)) { && FILE_UTILS.isSymbolicLink(parent, dirName)) {


Stack s = (Stack) directoryNamesFollowed.clone();
LinkedList s = (LinkedList) directoryNamesFollowed.clone();
ArrayList files = new ArrayList(); ArrayList files = new ArrayList();
File f = FILE_UTILS.resolveFile(parent, dirName); File f = FILE_UTILS.resolveFile(parent, dirName);
String target = getCanonicalPath(f); String target = getCanonicalPath(f);
files.add(target); files.add(target);


String relPath = ""; String relPath = "";
while (!s.empty()) {
while (s.size() > 0) {
relPath += "../"; relPath += "../";
String dir = (String) s.pop();
String dir = (String) s.removeFirst();
if (dirName.equals(dir)) { if (dirName.equals(dir)) {
f = FILE_UTILS.resolveFile(parent, relPath + dir); f = FILE_UTILS.resolveFile(parent, relPath + dir);
files.add(getCanonicalPath(f)); files.add(getCanonicalPath(f));


+ 7
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java View File

@@ -103,8 +103,13 @@ public class DefaultExcludesTest extends BuildFileTest {
private void assertEquals(String message, String[] expected, String[] actual) { private void assertEquals(String message, String[] expected, String[] actual) {
// check that both arrays have the same size // check that both arrays have the same size
assertEquals(message + " : string array length match", expected.length, actual.length); assertEquals(message + " : string array length match", expected.length, actual.length);
for (int counter=0; counter <expected.length; counter++) {
assertEquals(message + " : " + counter + "th element in array match", expected[counter], actual[counter]);
for (int counter=0; counter < expected.length; counter++) {
boolean found = false;
for (int i = 0; !found && i < actual.length; i++) {
found |= expected[counter].equals(actual[i]);
}
assertTrue(message + " : didn't find element "
+ expected[counter] + " in array match", found);
} }


} }


Loading…
Cancel
Save