ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant DirectoryScanner.java
Date Wed, 16 Jul 2003 11:47:53 GMT
bodewig     2003/07/16 04:47:53

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
  Log:
  Fix case-insensitive DirectiryScanner - I hope
  
  Revision  Changes    Path
  1.46      +66 -4     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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- DirectoryScanner.java	15 Jul 2003 23:19:15 -0000	1.45
  +++ DirectoryScanner.java	16 Jul 2003 11:47:52 -0000	1.46
  @@ -692,7 +692,18 @@
           Enumeration enum2 = newroots.keys();
           while (enum2.hasMoreElements()) {
               String currentelement = (String) enum2.nextElement();
  +            String originalpattern = (String) newroots.get(currentelement);
               File myfile = new File(basedir, currentelement);
  +            if (!myfile.exists() && !isCaseSensitive) {
  +                File f = findFileCaseInsensitive(basedir, currentelement);
  +                if (f.exists()) {
  +                    // adapt currentelement to the case we've actually found
  +                    currentelement = fileUtils.removeLeadingPath(basedir,
  +                                                                 f);
  +                    myfile = f;
  +                }
  +            }
  +
               if (myfile.exists()) {
                   if (myfile.isDirectory()) {
                       if (isIncluded(currentelement)
  @@ -700,7 +711,8 @@
                           accountForIncludedDir(currentelement, myfile, true);
                       }  else {
                           if (currentelement.length() > 0) {
  -                            if (currentelement.charAt(currentelement.length()-1)
  +                            if (currentelement.charAt(currentelement.length()
  +                                                      - 1) 
                                   != File.separatorChar) {
                                   currentelement = 
                                       currentelement + File.separatorChar;
  @@ -709,9 +721,11 @@
                           scandir(myfile, currentelement, true);
                       }
                   } else {
  -                    String originalpattern =
  -                        (String) newroots.get(currentelement);
  -                    if (originalpattern.equals(currentelement)) {
  +                    if (isCaseSensitive 
  +                        && originalpattern.equals(currentelement)) {
  +                        accountForIncludedFile(currentelement, myfile);
  +                    } else if (!isCaseSensitive 
  +                        && originalpattern.equalsIgnoreCase(currentelement)) {
                           accountForIncludedFile(currentelement, myfile);
                       }
                   }
  @@ -1130,4 +1144,52 @@
                               f.isDirectory());
       }
   
  +    /**
  +     * From <code>base</code> traverse the filesystem in a case
  +     * insensitive manner in order to find a file that matches the
  +     * given name.
  +     *
  +     * @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.
  +     *
  +     * @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;
  +        } else {
  +            if (!base.isDirectory()) {
  +                return null;
  +            }
  +            String[] files = base.list();
  +            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].equalsIgnoreCase(current)) {
  +                    base = new File(base, files[i]);
  +                    return findFileCaseInsensitive(base, pathElements);
  +                }
  +            }
  +        }
  +        return null;
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message