Browse Source

Fix a problem introduced in the recent optimization of DirectoryScanner :

under Windows, the case of the includedFiles and of the includedDirectories
was influenced by the case used in the include patterns of the fileset.
This change fixes it.
I am using File.getCanonicalFile() because it is the only way I know to get
the real case of a file under Windows.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274865 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
8585763d20
2 changed files with 20 additions and 18 deletions
  1. +17
    -0
      src/main/org/apache/tools/ant/DirectoryScanner.java
  2. +3
    -18
      src/testcases/org/apache/tools/ant/DirectoryScannerTest.java

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

@@ -66,6 +66,7 @@ import org.apache.tools.ant.types.selectors.FileSelector;
import org.apache.tools.ant.types.selectors.SelectorScanner;
import org.apache.tools.ant.types.selectors.SelectorUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.taskdefs.condition.Os;

/**
* Class for scanning a directory for files/directories which match certain
@@ -694,6 +695,22 @@ public class DirectoryScanner
String currentelement = (String) enum2.nextElement();
String originalpattern = (String) newroots.get(currentelement);
File myfile = new File(basedir, currentelement);
// we need to call getCanonicalFile here for DOS systems
// the reason being that otherwise File will be influenced
// by the case of currentelement, which we want to avoid
if (Os.isFamily("dos") && myfile.exists()) {
try {
// getAbsoluteFile() is not enough here unfortunately
myfile = myfile.getCanonicalFile();
}
catch (Exception ex) {
throw new BuildException(ex);
}
// the variable currentelement is actually telling what
// the scan results will contain
currentelement = fileUtils.removeLeadingPath(basedir,
myfile);
}
if (!myfile.exists() && !isCaseSensitive) {
File f = findFileCaseInsensitive(basedir, currentelement);
if (f.exists()) {


+ 3
- 18
src/testcases/org/apache/tools/ant/DirectoryScannerTest.java View File

@@ -120,11 +120,7 @@ public class DirectoryScannerTest extends BuildFileTest {
ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
ds.scan();
if (Os.isFamily("dos")) {
compareFiles(ds, new String[] {"alpha/beta/gamma/GAMMA.XML"}, new String[] {});
} else {
compareFiles(ds, new String[] {}, new String[] {});
}
compareFiles(ds, new String[] {}, new String[] {});
}

public void testFullPathMatchesCaseInsensitive() {
@@ -133,13 +129,8 @@ public class DirectoryScannerTest extends BuildFileTest {
ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
ds.scan();
if (Os.isFamily("dos")) {
compareFiles(ds, new String[] {"alpha/beta/gamma/GAMMA.XML"},
new String[] {});
} else {
compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
new String[] {});
}
compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
new String[] {});
}

public void test2ButCaseInsesitive() {
@@ -148,15 +139,9 @@ public class DirectoryScannerTest extends BuildFileTest {
ds.setIncludes(new String[] {"ALPHA/"});
ds.setCaseSensitive(false);
ds.scan();
if (Os.isFamily("dos")) {
compareFiles(ds, new String[] {"ALPHA/beta/beta.xml",
"ALPHA/beta/gamma/gamma.xml"},
new String[] {"ALPHA", "ALPHA/beta", "ALPHA/beta/gamma"});
} else {
compareFiles(ds, new String[] {"alpha/beta/beta.xml",
"alpha/beta/gamma/gamma.xml"},
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
}

public void testAllowSymlinks() {


Loading…
Cancel
Save