ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant DirectoryScanner.java
Date Tue, 29 Jul 2003 10:49:12 GMT
antoine     2003/07/29 03:49:12

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
  Log:
  do not scan needlessly excluded directories
  PR: 21941
  
  Revision  Changes    Path
  1.60      +37 -2     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.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- DirectoryScanner.java	29 Jul 2003 09:10:07 -0000	1.59
  +++ DirectoryScanner.java	29 Jul 2003 10:49:11 -0000	1.60
  @@ -825,7 +825,6 @@
           if (fast && hasBeenScanned(vpath)) {
               return;
           }
  -
           String[] newfiles = dir.list();
   
           if (newfiles == null) {
  @@ -980,12 +979,48 @@
       protected boolean couldHoldIncluded(String name) {
           for (int i = 0; i < includes.length; i++) {
               if (matchPatternStart(includes[i], name, isCaseSensitive)) {
  -                return true;
  +                if (isMorePowerfulThanExcludes(name, includes[i])) {
  +                    return true;
  +                }
               }
           }
           return false;
       }
   
  +    /**
  +     *  find out whether one particular include pattern is more powerful
  +     *  than all the excludes
  +     *  note : the power comparison is based on the length of the include pattern
  +     *  and of the exclude patterns without the wildcards
  +     *  ideally the comparison should be done based on the depth
  +     *  of the match, that is to say how many file separators have been matched
  +     *  before the first ** or the end of the pattern
  +     *
  +     *  IMPORTANT : this function should return false "with care"
  +     *
  +     *  @param name the relative path that one want to test
  +     *  @param includepattern  one include pattern
  +     *  @return true if there is no exclude pattern more powerful than this include pattern
  +     *  @since ant1.6
  +     */
  +    private boolean isMorePowerfulThanExcludes(String name, String includepattern) {
  +        String shortpattern = SelectorUtils.rtrimWildcardTokens(includepattern);
  +        for (int counter=0; counter <excludes.length; counter++) {
  +            String shortexclude = SelectorUtils.rtrimWildcardTokens(excludes[counter]);
  +            // here we are checking that the trimmed exclude pattern is not a plain directory
  +            // <exclude name="foo"/> means exclude only the directory foo, but not
its subdirs
  +            if (shortexclude.length() < excludes[counter].length()) {
  +                if (excludes[counter].charAt(shortexclude.length()) == File.separatorChar)
{
  +                    if (matchPath(shortexclude, name, isCaseSensitive)) {
  +                        if (shortexclude.length() > shortpattern.length()) {
  +                            return false;
  +                        }
  +                    }
  +                }
  +            }
  +        }
  +        return true;
  +    }
       /**
        * Tests whether or not a name matches against at least one exclude
        * pattern.
  
  
  

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


Mime
View raw message