From af0dbb6ef20efb56df867fa8025d13b0319383e6 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 3 Apr 2002 11:24:55 +0000 Subject: [PATCH] reimplement DirSet as subclass of FileSet git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272182 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/types/DirSet.java | 233 +----------------- .../org/apache/tools/ant/types/FileSet.java | 18 +- src/main/org/apache/tools/ant/types/Path.java | 40 +-- .../apache/tools/ant/types/DirSetTest.java | 28 +++ 4 files changed, 69 insertions(+), 250 deletions(-) diff --git a/src/main/org/apache/tools/ant/types/DirSet.java b/src/main/org/apache/tools/ant/types/DirSet.java index 7d8334845..c70c8710f 100644 --- a/src/main/org/apache/tools/ant/types/DirSet.java +++ b/src/main/org/apache/tools/ant/types/DirSet.java @@ -64,238 +64,19 @@ import java.util.Stack; 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. - * - *

You must not set another attribute or nest elements inside - * this element if you make it a reference.

- */ - 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 class DirSet extends DataType implements Cloneable { */ public Object clone() { if (isReference()) { - return new DirSet(getRef(getProject())); + return new DirSet((DirSet) getRef(getProject())); } else { return new DirSet(this); } diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java index 0db2ce13b..b8bad50c0 100644 --- a/src/main/org/apache/tools/ant/types/FileSet.java +++ b/src/main/org/apache/tools/ant/types/FileSet.java @@ -83,6 +83,8 @@ public class FileSet extends DataType implements Cloneable { private boolean useDefaultExcludes = true; private boolean isCaseSensitive = true; + private String dataTypeName = "fileset"; + public FileSet() { super(); } @@ -256,6 +258,13 @@ public class FileSet extends DataType implements Cloneable { this.isCaseSensitive = isCaseSensitive; } + /** + * 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. */ @@ -265,7 +274,8 @@ public class FileSet extends DataType implements Cloneable { } 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 @@ public class FileSet extends DataType implements Cloneable { 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 @@ public class FileSet extends DataType implements Cloneable { } 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; diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index f6b0032db..880226b3e 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -319,35 +319,23 @@ public class Path extends DataType implements Cloneable { for (int j=0; j