antoine     2003/07/19 10:08:06

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
               src/testcases/org/apache/tools/ant DirectoryScannerTest.java
  Log:
  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.
  
  Revision  Changes    Path
  1.49      +17 -0     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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- DirectoryScanner.java     18 Jul 2003 12:45:54 -0000      1.48
  +++ DirectoryScanner.java     19 Jul 2003 17:08:06 -0000      1.49
  @@ -66,6 +66,7 @@
   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 @@
               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()) {
  
  
  
  1.17      +3 -18     
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DirectoryScannerTest.java 19 Jul 2003 15:57:21 -0000      1.16
  +++ DirectoryScannerTest.java 19 Jul 2003 17:08:06 -0000      1.17
  @@ -120,11 +120,7 @@
           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 @@
           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 @@
           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() {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to