From 65802780b638e786a26841d5c3e2cba710d7b716 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 11 Feb 2005 22:37:04 +0000 Subject: [PATCH] Merged duplicate code from private methods. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277648 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/DirectoryScanner.java | 88 ++++--------------- 1 file changed, 19 insertions(+), 69 deletions(-) diff --git a/src/main/org/apache/tools/ant/DirectoryScanner.java b/src/main/org/apache/tools/ant/DirectoryScanner.java index 72f3c14c8..765527d9a 100644 --- a/src/main/org/apache/tools/ant/DirectoryScanner.java +++ b/src/main/org/apache/tools/ant/DirectoryScanner.java @@ -849,7 +849,7 @@ public class DirectoryScanner String path = FILE_UTILS.removeLeadingPath(canonBase, canonFile); if (!path.equals(currentelement) || ON_VMS) { - myfile = findFile(basedir, currentelement); + myfile = findFile(basedir, currentelement, true); if (myfile != null) { currentelement = FILE_UTILS.removeLeadingPath(basedir, @@ -861,7 +861,7 @@ public class DirectoryScanner } } if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) { - File f = findFileCaseInsensitive(basedir, currentelement); + File f = findFile(basedir, currentelement, false); if (f.exists()) { // adapt currentelement to the case we've // actually found @@ -1447,76 +1447,19 @@ public class DirectoryScanner return files; } - /** - * From base traverse the filesystem in a case - * insensitive manner in order to find a file that matches the - * given name. - * - * @param base base File (dir). - * @param path file path. - * @return File object that points to the file in question. if it - * hasn't been found it will simply be new File(base, - * path). - * - * @since Ant 1.6 - */ - private File findFileCaseInsensitive(File base, String path) { - File f = findFileCaseInsensitive(base, - SelectorUtils.tokenizePath(path)); - return f == null ? new File(base, path) : f; - } - - /** - * From base traverse the filesystem in a case - * insensitive manner in order to find a file that matches the - * given stack of names. - * - * @param base base File (dir). - * @param pathElements Vector of path elements (dirs...file). - * @return File object that points to the file in question or null. - * - * @since Ant 1.6 - */ - private File findFileCaseInsensitive(File base, Vector pathElements) { - if (pathElements.size() == 0) { - return base; - } - if (!base.isDirectory()) { - return null; - } - String[] files = list(base); - if (files == null) { - throw new BuildException("IO error scanning directory " - + base.getAbsolutePath()); - } - String current = (String) pathElements.remove(0); - for (int i = 0; i < files.length; i++) { - if (files[i].equals(current)) { - return findFileCaseInsensitive( - new File(base, files[i]), pathElements); - } - } - for (int i = 0; i < files.length; i++) { - if (files[i].equalsIgnoreCase(current)) { - return findFileCaseInsensitive( - new File(base, files[i]), pathElements); - } - } - return null; - } - /** * From base traverse the filesystem in order to find * a file that matches the given name. * * @param base base File (dir). * @param path file path. + * @param cs whether to scan case-sensitively. * @return File object that points to the file in question or null. * - * @since Ant 1.6 + * @since Ant 1.7 */ - private File findFile(File base, String path) { - return findFile(base, SelectorUtils.tokenizePath(path)); + private File findFile(File base, String path, boolean cs) { + return findFile(base, SelectorUtils.tokenizePath(path), cs); } /** @@ -1525,11 +1468,12 @@ public class DirectoryScanner * * @param base base File (dir). * @param pathElements Vector of path elements (dirs...file). + * @param cs whether to scan case-sensitively. * @return File object that points to the file in question or null. * - * @since Ant 1.6 + * @since Ant 1.7 */ - private File findFile(File base, Vector pathElements) { + private File findFile(File base, Vector pathElements, boolean cs) { if (pathElements.size() == 0) { return base; } @@ -1542,10 +1486,16 @@ public class DirectoryScanner + base.getAbsolutePath()); } String current = (String) pathElements.remove(0); - for (int i = 0; i < files.length; i++) { - if (files[i].equals(current)) { - base = new File(base, files[i]); - return findFile(base, pathElements); + + //always scan first NOT ignoring case; if cs, do a 2nd scan ignoring case: + boolean[] ignoreCase = cs ? new boolean[] {false} + : new boolean[] {false, true}; + for (int i = 0; i < ignoreCase.length; i++) { + for (int j = 0; j < files.length; j++) { + if (ignoreCase[i] ? files[j].equalsIgnoreCase(current) + : files[j].equals(current)) { + return findFile(new File(base, files[j]), pathElements, cs); + } } } return null;