ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/types DirSetTest.java
Date Wed, 03 Apr 2002 11:24:55 GMT
bodewig     02/04/03 03:24:55

  Modified:    src/main/org/apache/tools/ant/types DirSet.java FileSet.java
                        Path.java
               src/testcases/org/apache/tools/ant/types DirSetTest.java
  Log:
  reimplement DirSet as subclass of FileSet
  
  Revision  Changes    Path
  1.3       +7 -226    jakarta-ant/src/main/org/apache/tools/ant/types/DirSet.java
  
  Index: DirSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/DirSet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DirSet.java	3 Apr 2002 10:54:54 -0000	1.2
  +++ DirSet.java	3 Apr 2002 11:24:54 -0000	1.3
  @@ -64,238 +64,19 @@
   import java.util.Vector;
   
   /**
  - * Essentially a clone of FileSet, but gets a set of dirs instead of files.
  + * Subclass as hint for supporting tasks that the included directories
  + * instead of files should be used.
    */
  -public class DirSet extends DataType implements Cloneable {
  +public class DirSet extends FileSet {
       
  -    private PatternSet defaultPatterns = new PatternSet();
  -    private Vector additionalPatterns = new Vector();
  -
  -    private File dir;
  -    private boolean isCaseSensitive = true;
  -
       public DirSet() {
           super();
  +        setDataTypeName("dirset");
       }
   
       protected DirSet(DirSet dirset) {
  -        this.dir = dirset.dir;
  -        this.defaultPatterns = dirset.defaultPatterns;
  -        this.additionalPatterns = dirset.additionalPatterns;
  -        this.isCaseSensitive = dirset.isCaseSensitive;
  -        setProject(getProject());
  -    }
  -
  -    /**
  -     * Makes this instance in effect a reference to another PatternSet
  -     * instance.
  -     *
  -     * <p>You must not set another attribute or nest elements inside
  -     * this element if you make it a reference.</p> 
  -     */
  -    public void setRefid(Reference r) throws BuildException {
  -        if (dir != null || defaultPatterns.hasPatterns()) {
  -            throw tooManyAttributes();
  -        }
  -        if (!additionalPatterns.isEmpty()) {
  -            throw noChildrenAllowed();
  -        }
  -        super.setRefid(r);
  -    }
  -
  -    public void setDir(File dir) throws BuildException {
  -        if (isReference()) {
  -            throw tooManyAttributes();
  -        }
  -
  -        this.dir = dir;
  -    }
  -
  -    public File getDir(Project p) {
  -        if (isReference()) {
  -            return getRef(p).getDir(p);
  -        }
  -        return dir;
  -    }
  -
  -    public PatternSet createPatternSet() {
  -        if (isReference()) {
  -            throw noChildrenAllowed();
  -        }
  -        PatternSet patterns = new PatternSet();
  -        additionalPatterns.addElement(patterns);
  -        return patterns;
  -    }
  -
  -    /**
  -     * add a name entry on the include list
  -     */
  -    public PatternSet.NameEntry createInclude() {
  -        if (isReference()) {
  -            throw noChildrenAllowed();
  -        }
  -        return defaultPatterns.createInclude();
  -    }
  -    
  -    /**
  -     * add a name entry on the include files list
  -     */
  -    public PatternSet.NameEntry createIncludesFile() {
  -        if (isReference()) {
  -            throw noChildrenAllowed();
  -        }
  -        return defaultPatterns.createIncludesFile();
  -    }
  -    
  -    /**
  -     * add a name entry on the exclude list
  -     */
  -    public PatternSet.NameEntry createExclude() {
  -        if (isReference()) {
  -            throw noChildrenAllowed();
  -        }
  -        return defaultPatterns.createExclude();
  -    }
  -
  -    /**
  -     * add a name entry on the include files list
  -     */
  -    public PatternSet.NameEntry createExcludesFile() {
  -        if (isReference()) {
  -            throw noChildrenAllowed();
  -        }
  -        return defaultPatterns.createExcludesFile();
  -    }
  -    
  -    /**
  -     * Sets the set of include patterns. Patterns may be separated by a comma
  -     * or a space.
  -     *
  -     * @param includes the string containing the include patterns
  -     */
  -    public void setIncludes(String includes) {
  -        if (isReference()) {
  -            throw tooManyAttributes();
  -        }
  -
  -        defaultPatterns.setIncludes(includes);
  -    }
  -
  -    /**
  -     * Sets the set of exclude patterns. Patterns may be separated by a comma
  -     * or a space.
  -     *
  -     * @param excludes the string containing the exclude patterns
  -     */
  -    public void setExcludes(String excludes) {
  -        if (isReference()) {
  -            throw tooManyAttributes();
  -        }
  -
  -        defaultPatterns.setExcludes(excludes);
  -    }
  -
  -    /**
  -     * Sets the name of the file containing the includes patterns.
  -     *
  -     * @param incl The file to fetch the include patterns from.  
  -     */
  -     public void setIncludesfile(File incl) throws BuildException {
  -         if (isReference()) {
  -             throw tooManyAttributes();
  -         }
  -
  -         defaultPatterns.setIncludesfile(incl);
  -     }
  -
  -    /**
  -     * Sets the name of the file containing the includes patterns.
  -     *
  -     * @param excl The file to fetch the exclude patterns from.  
  -     */
  -     public void setExcludesfile(File excl) throws BuildException {
  -         if (isReference()) {
  -             throw tooManyAttributes();
  -         }
  -
  -         defaultPatterns.setExcludesfile(excl);
  -     }
  -
  -    /**
  -     * Sets case sensitivity of the file system
  -     *
  -     * @param isCaseSensitive "true"|"on"|"yes" if file system is case
  -     *                           sensitive, "false"|"off"|"no" when not.
  -     */
  -    public void setCaseSensitive(boolean isCaseSensitive) {
  -        this.isCaseSensitive = isCaseSensitive;
  -    }
  -
  -    /**
  -     * Returns the directory scanner needed to access the dirs to process.
  -     */
  -    public DirectoryScanner getDirectoryScanner(Project p) {
  -        if (isReference()) {
  -            return getRef(p).getDirectoryScanner(p);
  -        }
  -
  -        if (dir == null) {
  -            throw new BuildException("No directory specified for dirset.");
  -        }
  -
  -        if (!dir.exists()) {
  -            throw new BuildException(dir.getAbsolutePath()+" not found.");
  -        }
  -        if (!dir.isDirectory()) {
  -            throw new BuildException(dir.getAbsolutePath()+" is not a directory.");
  -        }
  -
  -        DirectoryScanner ds = new DirectoryScanner();
  -        setupDirectoryScanner(ds, p);
  -        ds.scan();
  -        ds.getIncludedDirectories();
  -        return ds;
  -    }
  -    
  -    public void setupDirectoryScanner(FileScanner ds, Project p) {
  -        if (ds == null) {
  -            throw new IllegalArgumentException("ds cannot be null");
  -        }
  -        
  -        ds.setBasedir(dir);
  -
  -        final int count = additionalPatterns.size();
  -        for (int i = 0; i < count; i++) {
  -            Object o = additionalPatterns.elementAt(i);
  -            defaultPatterns.append((PatternSet) o, p);
  -        }
  -
  -        p.log( "DirSet: Setup dir scanner in dir " + dir + 
  -            " with " + defaultPatterns, Project.MSG_DEBUG );
  -        
  -        ds.setIncludes(defaultPatterns.getIncludePatterns(p));
  -        ds.setExcludes(defaultPatterns.getExcludePatterns(p));
  -        ds.setCaseSensitive(isCaseSensitive);
  -    }
  -
  -    /**
  -     * Performs the check for circular references and returns the
  -     * referenced DirSet.  
  -     */
  -    protected DirSet getRef(Project p) {
  -        if (!checked) {
  -            Stack stk = new Stack();
  -            stk.push(this);
  -            dieOnCircularReference(stk, p);
  -        }
  -        
  -        Object o = ref.getReferencedObject(p);
  -        if (!(o instanceof DirSet)) {
  -            String msg = ref.getRefId()+" doesn\'t denote a dirset";
  -            throw new BuildException(msg);
  -        } else {
  -            return (DirSet) o;
  -        }
  +        super(dirset);
  +        setDataTypeName("dirset");
       }
   
       /**
  @@ -304,7 +85,7 @@
        */
       public Object clone() {
           if (isReference()) {
  -            return new DirSet(getRef(getProject()));
  +            return new DirSet((DirSet) getRef(getProject()));
           } else {
               return new DirSet(this);
           }
  
  
  
  1.25      +14 -4     jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java
  
  Index: FileSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- FileSet.java	3 Apr 2002 10:54:54 -0000	1.24
  +++ FileSet.java	3 Apr 2002 11:24:54 -0000	1.25
  @@ -83,6 +83,8 @@
       private boolean useDefaultExcludes = true;
       private boolean isCaseSensitive = true;
   
  +    private String dataTypeName = "fileset";
  +
       public FileSet() {
           super();
       }
  @@ -257,6 +259,13 @@
       }
   
       /**
  +     * sets the name used for this datatype instance.
  +     */
  +    protected final void setDataTypeName(String name) {
  +        dataTypeName = name;
  +    }
  +
  +    /**
        * Returns the directory scanner needed to access the files to process.
        */
       public DirectoryScanner getDirectoryScanner(Project p) {
  @@ -265,7 +274,8 @@
           }
   
           if (dir == null) {
  -            throw new BuildException("No directory specified for fileset.");
  +            throw new BuildException("No directory specified for "
  +                                     + dataTypeName + ".");
           }
   
           if (!dir.exists()) {
  @@ -294,7 +304,7 @@
               defaultPatterns.append((PatternSet) o, p);
           }
   
  -        p.log( "FileSet: Setup file scanner in dir " + dir + 
  +        p.log(dataTypeName + ": Setup scanner in dir " + dir + 
               " with " + defaultPatterns, Project.MSG_DEBUG );
           
           ds.setIncludes(defaultPatterns.getIncludePatterns(p));
  @@ -317,8 +327,8 @@
           }
           
           Object o = ref.getReferencedObject(p);
  -        if (!(o instanceof FileSet)) {
  -            String msg = ref.getRefId()+" doesn\'t denote a fileset";
  +        if (!o.getClass().equals(getClass())) {
  +            String msg = ref.getRefId()+" doesn\'t denote a " + dataTypeName;
               throw new BuildException(msg);
           } else {
               return (FileSet) o;
  
  
  
  1.33      +20 -20    jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Path.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Path.java	30 Mar 2002 01:03:40 -0000	1.32
  +++ Path.java	3 Apr 2002 11:24:54 -0000	1.33
  @@ -319,35 +319,23 @@
                   for (int j=0; j<parts.length; j++) {
                       addUnlessPresent(result, parts[j]);
                   }
  -            } else if (o instanceof FileSet) {
  -                FileSet fs = (FileSet) o;
  -                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
  -                String[] s = ds.getIncludedFiles();
  -                File dir = fs.getDir(getProject());
  -                for (int j=0; j<s.length; j++) {
  -                    File f = new File(dir, s[j]);
  -                    String absolutePath = f.getAbsolutePath();
  -                    addUnlessPresent(result, translateFile(absolutePath));
  -                } 
               } else if (o instanceof DirSet) {
                   DirSet dset = (DirSet) o;
                   DirectoryScanner ds = dset.getDirectoryScanner(getProject());
                   String[] s = ds.getIncludedDirectories();
                   File dir = dset.getDir(getProject());
  -                for (int j=0; j<s.length; j++) {
  -                    File d = new File(dir, s[j]);
  -                    String absolutePath = d.getAbsolutePath();
  -                    addUnlessPresent(result, translateFile(absolutePath));
  -                } 
  +                addUnlessPresent(result, dir, s);
  +            } else if (o instanceof FileSet) {
  +                FileSet fs = (FileSet) o;
  +                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
  +                String[] s = ds.getIncludedFiles();
  +                File dir = fs.getDir(getProject());
  +                addUnlessPresent(result, dir, s);
               } else if (o instanceof FileList) {
                   FileList fl = (FileList) o;
                   String[] s = fl.getFiles(getProject());
                   File dir = fl.getDir(getProject());
  -                for (int j=0; j<s.length; j++) {
  -                    File d = new File(dir, s[j]);
  -                    String absolutePath = d.getAbsolutePath();
  -                    addUnlessPresent(result, translateFile(absolutePath));
  -                } 
  +                addUnlessPresent(result, dir, s);
               }
           }
           String[] res = new String[result.size()];
  @@ -507,6 +495,18 @@
           if (v.indexOf(s) == -1) {
               v.addElement(s);
           }
  +    }
  +
  +    /**
  +     * Adds absolute path names of listed files in the given directory
  +     * to the Vector if they are not already included.
  +     */
  +    private static void addUnlessPresent(Vector v, File dir, String[] s) {
  +        for (int j=0; j<s.length; j++) {
  +            File d = new File(dir, s[j]);
  +            String absolutePath = d.getAbsolutePath();
  +            addUnlessPresent(v, translateFile(absolutePath));
  +        } 
       }
   
       /**
  
  
  
  1.2       +28 -0     jakarta-ant/src/testcases/org/apache/tools/ant/types/DirSetTest.java
  
  Index: DirSetTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/types/DirSetTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirSetTest.java	3 Apr 2002 10:54:54 -0000	1.1
  +++ DirSetTest.java	3 Apr 2002 11:24:55 -0000	1.2
  @@ -246,4 +246,32 @@
           File dir = f1.getDir(project);
           assertEquals("Dir is basedir", dir, project.getBaseDir());
       }
  +
  +    public void testFileSetIsNoDirSet() {
  +        DirSet ds = new DirSet();
  +        ds.setProject(project);
  +        FileSet fs = new FileSet();
  +        fs.setProject(project);
  +        project.addReference("dummy", fs);
  +        ds.setRefid(new Reference("dummy"));
  +        try {
  +            ds.getDir(project);
  +            fail("DirSet created from FileSet reference");
  +        } catch (BuildException e) {
  +            assertEquals("dummy doesn\'t denote a dirset", e.getMessage());
  +        }
  +
  +        ds = new DirSet();
  +        ds.setProject(project);
  +        project.addReference("dummy2", ds);
  +        fs.setRefid(new Reference("dummy2"));
  +        try {
  +            fs.getDir(project);
  +            fail("FileSet created from DirSet reference");
  +        } catch (BuildException e) {
  +            assertEquals("dummy2 doesn\'t denote a fileset", e.getMessage());
  +        }
  +
  +    }
  +
   }
  
  
  

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


Mime
View raw message