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/testcases/org/apache/tools/ant DirectoryScannerTest.java
Date Wed, 12 Feb 2003 09:05:04 GMT
bodewig     2003/02/12 01:05:04

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
               src/main/org/apache/tools/ant/taskdefs Jar.java Zip.java
               src/main/org/apache/tools/ant/types ZipScanner.java
               src/testcases/org/apache/tools/ant DirectoryScannerTest.java
  Removed:     src/main/org/apache/tools/ant ResourceScanner.java
  Log:
  Remove the (at least for now) superfluous ResourceScanner interface.
  
  Revision  Changes    Path
  1.38      +3 -48     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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- DirectoryScanner.java	10 Feb 2003 14:13:30 -0000	1.37
  +++ DirectoryScanner.java	12 Feb 2003 09:05:03 -0000	1.38
  @@ -58,6 +58,7 @@
   import java.io.IOException;
   import java.util.Vector;
   import org.apache.tools.ant.types.Resource;
  +import org.apache.tools.ant.types.ResourceFactory;
   import org.apache.tools.ant.types.selectors.FileSelector;
   import org.apache.tools.ant.types.selectors.SelectorScanner;
   import org.apache.tools.ant.types.selectors.SelectorUtils;
  @@ -151,7 +152,7 @@
    * @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
    * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
    */
  -public class DirectoryScanner implements ResourceScanner, SelectorScanner {
  +public class DirectoryScanner implements FileScanner, SelectorScanner, ResourceFactory
{
   
       /**
        * Patterns which should be excluded by default.
  @@ -811,27 +812,6 @@
       }
   
       /**
  -     * Returns the resources of the files which matched at least one
  -     * of the include patterns and none of the exclude patterns.  The
  -     * names are relative to the base directory.
  -     *
  -     * @return resource information for the files which matched at
  -     * least one of the include patterns and none of the exclude
  -     * patterns.
  -     *
  -     * @since Ant 1.5.2
  -     */
  -    public Resource[] getIncludedFileResources() {
  -        String[] names = getIncludedFiles();
  -        int count = names.length;
  -        Resource[] resources = new Resource[count];
  -        for (int i = 0; i < count; i++) {
  -            resources[i] = getResource(names[i]);
  -        }
  -        return resources;
  -    }
  -
  -    /**
        * Returns the names of the files which matched none of the include
        * patterns. The names are relative to the base directory. This involves
        * performing a slow scan if one has not already been completed.
  @@ -899,26 +879,6 @@
       }
   
       /**
  -     * Returns the resource object for the directories which matched
  -     * at least one of the include patterns and none of the exclude
  -     * patterns.  The names are relative to the base directory.
  -     *
  -     * @return the names of the directories which matched at least one of the
  -     * include patterns and none of the exclude patterns.
  -     *
  -     * @since Ant 1.5.2
  -     */
  -    public Resource[] getIncludedDirectoryResources() {
  -        String[] names = getIncludedDirectories();
  -        int count = names.length;
  -        Resource[] resources = new Resource[count];
  -        for (int i = 0; i < count; i++) {
  -            resources[i] = getResource(names[i]);
  -        }
  -        return resources;
  -    }
  -    
  -    /**
        * Returns the names of the directories which matched none of the include
        * patterns. The names are relative to the base directory. This involves
        * performing a slow scan if one has not already been completed.
  @@ -994,12 +954,7 @@
        * @since Ant 1.5.2
        */
       public Resource getResource(String name) {
  -        File f = null;
  -        if (basedir != null) {
  -            f = new File(basedir, name);
  -        } else {
  -            f = new File(name);
  -        }            
  +        File f = fileUtils.resolveFile(basedir, name);
           return new Resource(name, f.exists(), f.lastModified(), 
                               f.isDirectory());
       }
  
  
  
  1.67      +0 -1      ant/src/main/org/apache/tools/ant/taskdefs/Jar.java
  
  Index: Jar.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- Jar.java	10 Feb 2003 14:13:34 -0000	1.66
  +++ Jar.java	12 Feb 2003 09:05:04 -0000	1.67
  @@ -70,7 +70,6 @@
   import java.util.zip.ZipFile;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.ResourceScanner;
   import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.Resource;
  
  
  
  1.94      +23 -12    ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- Zip.java	10 Feb 2003 14:13:37 -0000	1.93
  +++ Zip.java	12 Feb 2003 09:05:04 -0000	1.94
  @@ -73,7 +73,6 @@
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.FileScanner;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.ResourceScanner;
   import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.PatternSet;
  @@ -441,10 +440,15 @@
                           PatternSet.NameEntry ne = oldFiles.createExclude();
                           ne.setName((String) addedFiles.elementAt(i));
                       }
  -                    addResources(oldFiles, 
  -                                 oldFiles.getDirectoryScanner(getProject())
  -                                         .getIncludedFileResources(),
  -                                 zOut);
  +                    DirectoryScanner ds = 
  +                        oldFiles.getDirectoryScanner(getProject());
  +                    String[] f = ds.getIncludedFiles();
  +                    Resource[] r = new Resource[f.length];
  +                    for (int i = 0; i < f.length; i++) {
  +                        r[i] = ds.getResource(f[i]);
  +                    }
  +                    
  +                    addResources(oldFiles, r, zOut);
                   }
                   finalizeZipOutputStream(zOut);
   
  @@ -801,13 +805,20 @@
       protected Resource[][] grabResources(FileSet[] filesets) {
           Resource[][] result = new Resource[filesets.length][];
           for (int i = 0; i < filesets.length; i++) {
  -            ResourceScanner rs = filesets[i].getDirectoryScanner(getProject());
  -            Resource[] files = rs.getIncludedFileResources();
  -            Resource[] directories = rs.getIncludedDirectoryResources();
  -            result[i] = new Resource[files.length + directories.length];
  -            System.arraycopy(directories, 0, result[i], 0, directories.length);
  -            System.arraycopy(files, 0, result[i], directories.length, 
  -                             files.length);
  +            DirectoryScanner rs = 
  +                filesets[i].getDirectoryScanner(getProject());
  +            Vector resources = new Vector();
  +            String[] directories = rs.getIncludedDirectories();
  +            for (int j = 0; j < directories.length; j++) {
  +                resources.add(rs.getResource(directories[j]));
  +            }
  +            String[] files = rs.getIncludedFiles();
  +            for (int j = 0; j < files.length; j++) {
  +                resources.add(rs.getResource(files[j]));
  +            }
  +            
  +            result[i] = new Resource[resources.size()];
  +            resources.copyInto(result[i]);
           }
           return result;
       }
  
  
  
  1.15      +0 -60     ant/src/main/org/apache/tools/ant/types/ZipScanner.java
  
  Index: ZipScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/ZipScanner.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ZipScanner.java	10 Feb 2003 14:14:31 -0000	1.14
  +++ ZipScanner.java	12 Feb 2003 09:05:04 -0000	1.15
  @@ -202,66 +202,6 @@
       }
   
       /**
  -     * Returns the resources of the files which matched at least one of the
  -     * include patterns and none of the exclude patterns.
  -     * The names are relative to the base directory.
  -     *
  -     * @return resource information for the files which matched at
  -     * least one of the include patterns and none of the exclude
  -     * patterns.
  -     *
  -     * @since Ant 1.5.2
  -     */
  -    public Resource[] getIncludedFileResources() {
  -        if (srcFile != null) {
  -            Vector myvector = new Vector();
  -            // first check if the archive needs to be scanned again
  -            scanme();
  -            for (Enumeration e = myentries.elements(); e.hasMoreElements() ;) {
  -                Resource myresource= (Resource) e.nextElement();
  -                if (!myresource.isDirectory() && match(myresource.getName())) {
  -                    myvector.addElement(myresource.clone());
  -                }
  -            }
  -            Resource[] resources = new Resource[myvector.size()];
  -            myvector.copyInto(resources);
  -            return resources;
  -        } else {
  -            return super.getIncludedFileResources();
  -        }
  -    }
  -
  -    /**
  -     * Returns the resources of the files which matched at least one of the
  -     * include patterns and none of the exclude patterns.
  -     * The names are relative to the base directory.
  -     *
  -     * @return resource information for the files which matched at
  -     * least one of the include patterns and none of the exclude
  -     * patterns.
  -     *
  -     * @since Ant 1.5.2
  -     */
  -    public Resource[] getIncludedDirectoryResources() {
  -        if (srcFile != null) {
  -            Vector myvector = new Vector();
  -            // first check if the archive needs to be scanned again
  -            scanme();
  -            for (Enumeration e = myentries.elements(); e.hasMoreElements() ;) {
  -                Resource myresource= (Resource) e.nextElement();
  -                if (myresource.isDirectory() && match(myresource.getName())) {
  -                    myvector.addElement(myresource.clone());
  -                }
  -            }
  -            Resource[] resources = new Resource[myvector.size()];
  -            myvector.copyInto(resources);
  -            return resources;
  -        } else {
  -            return super.getIncludedDirectoryResources();
  -        }
  -    }
  -
  -    /**
        * @param name path name of the file sought in the archive
        *
        * @since Ant 1.5.2
  
  
  
  1.9       +0 -30     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DirectoryScannerTest.java	10 Feb 2003 14:14:44 -0000	1.8
  +++ DirectoryScannerTest.java	12 Feb 2003 09:05:04 -0000	1.9
  @@ -187,20 +187,6 @@
           assertTrue("(1) zip package included", haveZipPackage);
           assertTrue("(1) taskdefs package not included", !haveTaskdefsPackage);
   
  -        haveZipPackage = false;
  -        Resource[] includedResources = ds.getIncludedDirectoryResources();
  -        for (int i=0; i<includedResources.length; i++) {
  -            if (includedResources[i].getName().equals("zip")) {
  -                haveZipPackage = true;
  -            } else if (includedResources[i].getName().equals("ant" 
  -                                                             + File.separator
  -                                                             + "taskdefs")) {
  -                haveTaskdefsPackage = true;
  -            }
  -        }
  -        assertTrue("(1b) zip package included", haveZipPackage);
  -        assertTrue("(1b) taskdefs package not included", !haveTaskdefsPackage);
  -
           ds = new DirectoryScanner();
           ds.setBasedir(dir);
           ds.setExcludes(new String[] {"ant"});
  @@ -216,22 +202,6 @@
           }
           assertTrue("(2) zip package included", haveZipPackage);
           assertTrue("(2) taskdefs package included", haveTaskdefsPackage);
  -
  -        haveZipPackage = false;
  -        haveTaskdefsPackage = false;
  -        includedResources = ds.getIncludedDirectoryResources();
  -        for (int i=0; i<includedResources.length; i++) {
  -            if (includedResources[i].getName().equals("zip")) {
  -                haveZipPackage = true;
  -            } else if (includedResources[i].getName().equals("ant"
  -                                                             + File.separator
  -                                                             + "taskdefs")) {
  -                haveTaskdefsPackage = true;
  -            }
  -        }
  -        assertTrue("(2b) zip package included", haveZipPackage);
  -        assertTrue("(2b) taskdefs package included", haveTaskdefsPackage);
  -
       }
   
   }
  
  
  

Mime
View raw message