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/testcases/org/apache/tools/ant DirectoryScannerTest.java
Date Tue, 15 Jul 2003 23:19:15 GMT
antoine     2003/07/15 16:19:15

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
               src/testcases/org/apache/tools/ant DirectoryScannerTest.java
  Log:
  Fix the following (remark of Stefan Bodewig on July 15th 2003 on the dev list)
  * You go a long way to avoid redundantly adding patterns in
  DirectoryScanner#checkIncludePatterns (the parent check).  If the
  patterns come in reversed, you'll still have duplicate roots, no?  Say
  a/b/c is added before a/b is.  You may avoid this by sorting the
  include patterns first.
  
  Revision  Changes    Path
  1.45      +28 -13    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.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- DirectoryScanner.java	15 Jul 2003 14:18:07 -0000	1.44
  +++ DirectoryScanner.java	15 Jul 2003 23:19:15 -0000	1.45
  @@ -658,34 +658,49 @@
               String newpattern = 
                   SelectorUtils.rtrimWildcardTokens(includes[icounter]);
               // check whether the candidate new pattern has a parent
  -            boolean hasParent=false;
  +            boolean hasParent = false;
               Enumeration myenum = newroots.keys();
  +            // logically, there should be at most one child pattern present
  +            // let's use a vector though to be sure
  +            Vector vdelete = new Vector();
               while (myenum.hasMoreElements()) {
  -                String existingpattern= (String) myenum.nextElement();
  +                String existingpattern = (String) myenum.nextElement();
  +                // check whether the existing pattern is a child of the new pattern
  +                if (existingpattern.length() >= newpattern.length()) {
  +                    if (existingpattern.indexOf(newpattern) == 0) {
  +                        vdelete.add(existingpattern);
  +                    }
  +                }
  +                // check whether the new pattern is a child of the existing pattern
                   if (existingpattern.length() <= newpattern.length()) {
  -                    if (newpattern.indexOf(existingpattern)==0) {
  -                        hasParent=true;
  +                    if (newpattern.indexOf(existingpattern) == 0) {
  +                        hasParent = true;
  +                        break;
                       }
                   }
               }
  +            // add the new pattern if does not have parents
               if (!hasParent) {
  -                newroots.put(newpattern,includes[icounter]);
  +                newroots.put(newpattern, includes[icounter]);
  +                // remove child patterns
  +                for (int icounter2 = 0; icounter2 < vdelete.size(); icounter2++) {
  +                    newroots.remove(vdelete.elementAt(icounter2));
  +                }
               }
           }
   
           Enumeration enum2 = newroots.keys();
           while (enum2.hasMoreElements()) {
               String currentelement = (String) enum2.nextElement();
  -            File myfile=new File(basedir, currentelement);
  +            File myfile = new File(basedir, currentelement);
               if (myfile.exists()) {
                   if (myfile.isDirectory()) {
  -                    if (isIncluded(currentelement) 
  -                        && currentelement.length()>0) {
  -                        accountForIncludedDir(currentelement,myfile,true);
  +                    if (isIncluded(currentelement)
  +                        && currentelement.length() > 0) {
  +                        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;
  @@ -694,10 +709,10 @@
                           scandir(myfile, currentelement, true);
                       }
                   } else {
  -                    String originalpattern= 
  +                    String originalpattern =
                           (String) newroots.get(currentelement);
                       if (originalpattern.equals(currentelement)) {
  -                        accountForIncludedFile(currentelement,myfile);
  +                        accountForIncludedFile(currentelement, myfile);
                       }
                   }
               }
  
  
  
  1.12      +16 -0     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DirectoryScannerTest.java	11 Jul 2003 12:59:29 -0000	1.11
  +++ DirectoryScannerTest.java	15 Jul 2003 23:19:15 -0000	1.12
  @@ -133,6 +133,22 @@
           ds.scan();
           compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}
,new String[] {"", "alpha", "alpha/beta", "alpha/beta/gamma"});
       }
  +    // father and child pattern test
  +    public void testOrderOfIncludePatternsIrrelevant() {
  +        String [] expectedFiles = {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"};
  +        String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" };
  +        DirectoryScanner ds = new DirectoryScanner();
  +        ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
  +        ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"});
  +        ds.scan();
  +        compareFiles(ds, expectedFiles, expectedDirectories);
  +        // redo the test, but the 2 include patterns are inverted
  +        ds = new DirectoryScanner();
  +        ds.setBasedir(new File(getProject().getBaseDir(), "tmp"));
  +        ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"});
  +        ds.scan();
  +        compareFiles(ds, expectedFiles, expectedDirectories);
  +    }
       public void tearDown() {
           getProject().executeTarget("cleanup");
       }
  
  
  

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


Mime
View raw message