mbenson 2005/02/11 14:37:04 Modified: src/main/org/apache/tools/ant DirectoryScanner.java Log: Merged duplicate code from private methods. Revision Changes Path 1.87 +19 -69 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.86 retrieving revision 1.87 diff -u -r1.86 -r1.87 --- DirectoryScanner.java 11 Feb 2005 20:53:47 -0000 1.86 +++ DirectoryScanner.java 11 Feb 2005 22:37:04 -0000 1.87 @@ -849,7 +849,7 @@ 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 @@ } } 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 @@ -1448,75 +1448,18 @@ } /** - * From <code>base</code> 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 <code>new File(base, - * path)</code>. - * - * @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 <code>base</code> 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 <code>base</code> 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 @@ * * @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 @@ + 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;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]