FileDocCategorySizeDatePackage
AbstractFileSet.javaAPI DocApache Ant 1.7026105Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.types

AbstractFileSet

public abstract class AbstractFileSet extends DataType implements Cloneable, org.apache.tools.ant.types.selectors.SelectorContainer
Class that holds an implicit patternset and supports nested patternsets and creates a DirectoryScanner using these patterns.

Common base class for DirSet and FileSet.

Fields Summary
private PatternSet
defaultPatterns
private Vector
additionalPatterns
private Vector
selectors
private File
dir
private boolean
useDefaultExcludes
private boolean
caseSensitive
private boolean
followSymlinks
private org.apache.tools.ant.DirectoryScanner
directoryScanner
Constructors Summary
public AbstractFileSet()
Construct a new AbstractFileSet.


             
      
        super();
    
protected AbstractFileSet(AbstractFileSet fileset)
Construct a new AbstractFileSet, shallowly cloned from the specified AbstractFileSet.

param
fileset the AbstractFileSet to use as a template.

        this.dir = fileset.dir;
        this.defaultPatterns = fileset.defaultPatterns;
        this.additionalPatterns = fileset.additionalPatterns;
        this.selectors = fileset.selectors;
        this.useDefaultExcludes = fileset.useDefaultExcludes;
        this.caseSensitive = fileset.caseSensitive;
        this.followSymlinks = fileset.followSymlinks;
        setProject(fileset.getProject());
    
Methods Summary
public voidadd(org.apache.tools.ant.types.selectors.FileSelector selector)
Add an arbitary selector.

param
selector the FileSelector to add.
since
Ant 1.6

        appendSelector(selector);
    
public voidaddAnd(org.apache.tools.ant.types.selectors.AndSelector selector)
Add an "And" selector entry on the selector list.

param
selector the AndSelector to add.

        appendSelector(selector);
    
public voidaddContains(org.apache.tools.ant.types.selectors.ContainsSelector selector)
Add a contains selector entry on the selector list.

param
selector the ContainsSelector to add.

        appendSelector(selector);
    
public voidaddContainsRegexp(org.apache.tools.ant.types.selectors.ContainsRegexpSelector selector)
Add a regular expression selector entry on the selector list.

param
selector the ContainsRegexpSelector to add.

        appendSelector(selector);
    
public voidaddCustom(org.apache.tools.ant.types.selectors.ExtendSelector selector)
Add an extended selector entry on the selector list.

param
selector the ExtendSelector to add.

        appendSelector(selector);
    
public voidaddDate(org.apache.tools.ant.types.selectors.DateSelector selector)
Add a selector date entry on the selector list.

param
selector the DateSelector to add.

        appendSelector(selector);
    
public voidaddDepend(org.apache.tools.ant.types.selectors.DependSelector selector)
Add a depends selector entry on the selector list.

param
selector the DependSelector to add.

        appendSelector(selector);
    
public voidaddDepth(org.apache.tools.ant.types.selectors.DepthSelector selector)
Add a depth selector entry on the selector list.

param
selector the DepthSelector to add.

        appendSelector(selector);
    
public voidaddDifferent(org.apache.tools.ant.types.selectors.DifferentSelector selector)
Add a DifferentSelector entry on the selector list.

param
selector the DifferentSelector to add.

        appendSelector(selector);
    
public voidaddFilename(org.apache.tools.ant.types.selectors.FilenameSelector selector)
Add a selector filename entry on the selector list.

param
selector the FilenameSelector to add.

        appendSelector(selector);
    
public voidaddMajority(org.apache.tools.ant.types.selectors.MajoritySelector selector)
Add a majority selector entry on the selector list.

param
selector the MajoritySelector to add.

        appendSelector(selector);
    
public voidaddModified(org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector selector)
Add the modified selector.

param
selector the ModifiedSelector to add.
since
ant 1.6

        appendSelector(selector);
    
public voidaddNone(org.apache.tools.ant.types.selectors.NoneSelector selector)
Add a "None" selector entry on the selector list.

param
selector the NoneSelector to add.

        appendSelector(selector);
    
public voidaddNot(org.apache.tools.ant.types.selectors.NotSelector selector)
Add a "Not" selector entry on the selector list.

param
selector the NotSelector to add.

        appendSelector(selector);
    
public voidaddOr(org.apache.tools.ant.types.selectors.OrSelector selector)
Add an "Or" selector entry on the selector list.

param
selector the OrSelector to add.

        appendSelector(selector);
    
public voidaddPresent(org.apache.tools.ant.types.selectors.PresentSelector selector)
Add a present selector entry on the selector list.

param
selector the PresentSelector to add.

        appendSelector(selector);
    
public voidaddSelector(org.apache.tools.ant.types.selectors.SelectSelector selector)
Add a "Select" selector entry on the selector list.

param
selector the SelectSelector to add.

        appendSelector(selector);
    
public voidaddSize(org.apache.tools.ant.types.selectors.SizeSelector selector)
Add a selector size entry on the selector list.

param
selector the SizeSelector to add.

        appendSelector(selector);
    
public voidaddType(org.apache.tools.ant.types.selectors.TypeSelector selector)
Add a selector type entry on the selector list.

param
selector the TypeSelector to add.

        appendSelector(selector);
    
public synchronized voidappendExcludes(java.lang.String[] excludes)
Appends excludes to the current list of include patterns.

param
excludes array containing the exclude patterns.
since
Ant 1.7

        if (isReference()) {
            throw tooManyAttributes();
        }
        if (excludes != null) {
            for (int i = 0; i < excludes.length; i++) {
                defaultPatterns.createExclude().setName(excludes[i]);
            }
            directoryScanner = null;
        }
    
public synchronized voidappendIncludes(java.lang.String[] includes)
Appends includes to the current list of include patterns.

param
includes array containing the include patterns.
since
Ant 1.7

        if (isReference()) {
            throw tooManyAttributes();
        }
        if (includes != null) {
            for (int i = 0; i < includes.length; i++) {
                defaultPatterns.createInclude().setName(includes[i]);
            }
            directoryScanner = null;
        }
    
public synchronized voidappendSelector(org.apache.tools.ant.types.selectors.FileSelector selector)
Add a new selector into this container.

param
selector the new FileSelector to add.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        selectors.addElement(selector);
        directoryScanner = null;
    
public synchronized java.lang.Objectclone()
Creates a deep clone of this instance, except for the nested selectors (the list of selectors is a shallow clone of this instance's list).

return
the cloned object
since
Ant 1.6

        if (isReference()) {
            return (getRef(getProject())).clone();
        } else {
            try {
                AbstractFileSet fs = (AbstractFileSet) super.clone();
                fs.defaultPatterns = (PatternSet) defaultPatterns.clone();
                fs.additionalPatterns = new Vector(additionalPatterns.size());
                Enumeration e = additionalPatterns.elements();
                while (e.hasMoreElements()) {
                    fs.additionalPatterns
                        .addElement(((PatternSet) e.nextElement()).clone());
                }
                fs.selectors = new Vector(selectors);
                return fs;
            } catch (CloneNotSupportedException e) {
                throw new BuildException(e);
            }
        }
    
public synchronized PatternSet.NameEntrycreateExclude()
Add a name entry to the exclude list.

return
PatternSet.NameEntry.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        directoryScanner = null;
        return defaultPatterns.createExclude();
    
public synchronized PatternSet.NameEntrycreateExcludesFile()
Add a name entry to the excludes files list.

return
PatternSet.NameEntry.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        directoryScanner = null;
        return defaultPatterns.createExcludesFile();
    
public synchronized PatternSet.NameEntrycreateInclude()
Add a name entry to the include list.

return
PatternSet.NameEntry.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        directoryScanner = null;
        return defaultPatterns.createInclude();
    
public synchronized PatternSet.NameEntrycreateIncludesFile()
Add a name entry to the include files list.

return
PatternSet.NameEntry.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        directoryScanner = null;
        return defaultPatterns.createIncludesFile();
    
public synchronized PatternSetcreatePatternSet()
Creates a nested patternset.

return
PatternSet.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        PatternSet patterns = new PatternSet();
        additionalPatterns.addElement(patterns);
        directoryScanner = null;
        return patterns;
    
public synchronized booleangetDefaultexcludes()
Whether default exclusions should be used or not.

return
the default exclusions value.
since
Ant 1.6.3

        return (isReference())
            ? getRef(getProject()).getDefaultexcludes() : useDefaultExcludes;
    
public java.io.FilegetDir()
Retrieves the base-directory for this instance.

return
File.

        return getDir(getProject());
    
public synchronized java.io.FilegetDir(org.apache.tools.ant.Project p)
Retrieves the base-directory for this instance.

param
p the Project against which the reference is resolved, if set.
return
File.

        return (isReference()) ? getRef(p).getDir(p) : dir;
    
public org.apache.tools.ant.DirectoryScannergetDirectoryScanner()
Returns the directory scanner needed to access the files to process.

return
a DirectoryScanner instance.

        return getDirectoryScanner(getProject());
    
public org.apache.tools.ant.DirectoryScannergetDirectoryScanner(org.apache.tools.ant.Project p)
Returns the directory scanner needed to access the files to process.

param
p the Project against which the DirectoryScanner should be configured.
return
a DirectoryScanner instance.

        if (isReference()) {
            return getRef(p).getDirectoryScanner(p);
        }
        DirectoryScanner ds = null;
        synchronized (this) {
            if (directoryScanner != null && p == getProject()) {
                ds = directoryScanner;
            } else {
                if (dir == null) {
                    throw new BuildException("No directory specified for "
                                             + getDataTypeName() + ".");
                }
                if (!dir.exists()) {
                    throw new BuildException(dir.getAbsolutePath()
                                             + " not found.");
                }
                if (!dir.isDirectory()) {
                    throw new BuildException(dir.getAbsolutePath()
                                             + " is not a directory.");
                }
                ds = new DirectoryScanner();
                setupDirectoryScanner(ds, p);
                ds.setFollowSymlinks(followSymlinks);
                directoryScanner = (p == getProject()) ? ds : directoryScanner;
            }
        }
        ds.scan();
        return ds;
    
protected org.apache.tools.ant.types.AbstractFileSetgetRef(org.apache.tools.ant.Project p)
Performs the check for circular references and returns the referenced FileSet.

param
p the current project
return
the referenced FileSet

        return (AbstractFileSet) getCheckedRef(p);
    
public synchronized org.apache.tools.ant.types.selectors.FileSelector[]getSelectors(org.apache.tools.ant.Project p)
Returns the set of selectors as an array.

param
p the current project
return
a FileSelector[] of the selectors in this container.

        return (isReference())
            ? getRef(p).getSelectors(p) : (FileSelector[]) (selectors.toArray(
            new FileSelector[selectors.size()]));
    
public synchronized booleanhasPatterns()
Indicates whether there are any patterns here.

return
whether any patterns are in this container.

        if (isReference() && getProject() != null) {
            return getRef(getProject()).hasPatterns();
        }
        if (defaultPatterns.hasPatterns(getProject())) {
            return true;
        }
        Enumeration e = additionalPatterns.elements();
        while (e.hasMoreElements()) {
            PatternSet ps = (PatternSet) e.nextElement();
            if (ps.hasPatterns(getProject())) {
                return true;
            }
        }
        return false;
    
public synchronized booleanhasSelectors()
Indicates whether there are any selectors here.

return
whether any selectors are in this container.

        return (isReference() && getProject() != null)
            ? getRef(getProject()).hasSelectors() : !(selectors.isEmpty());
    
public synchronized booleanisCaseSensitive()
Find out if the fileset is case sensitive.

return
boolean indicating whether the fileset is case sensitive.
since
Ant 1.7

        return (isReference())
            ? getRef(getProject()).isCaseSensitive() : caseSensitive;
    
public synchronized booleanisFollowSymlinks()
Find out if the fileset wants to follow symbolic links.

return
boolean indicating whether symbolic links should be followed.
since
Ant 1.6

        return (isReference())
            ? getRef(getProject()).isFollowSymlinks() : followSymlinks;
    
public java.lang.String[]mergeExcludes(org.apache.tools.ant.Project p)
Get the merged exclude patterns for this AbstractFileSet.

param
p the project to use.
return
the exclude patterns of the default pattern set and all nested patternsets.
since
Ant 1.7

        return mergePatterns(p).getExcludePatterns(p);
    
public java.lang.String[]mergeIncludes(org.apache.tools.ant.Project p)
Get the merged include patterns for this AbstractFileSet.

param
p the project to use.
return
the include patterns of the default pattern set and all nested patternsets.
since
Ant 1.7

        return mergePatterns(p).getIncludePatterns(p);
    
public synchronized PatternSetmergePatterns(org.apache.tools.ant.Project p)
Get the merged patterns for this AbstractFileSet.

param
p the project to use.
return
the default patternset merged with the additional sets in a new PatternSet instance.
since
Ant 1.7

        if (isReference()) {
            return getRef(p).mergePatterns(p);
        }
        PatternSet ps = (PatternSet) defaultPatterns.clone();
        final int count = additionalPatterns.size();
        for (int i = 0; i < count; i++) {
            Object o = additionalPatterns.elementAt(i);
            ps.append((PatternSet) o, p);
        }
        return ps;
    
public synchronized intselectorCount()
Gives the count of the number of selectors in this container.

return
the number of selectors in this container as an int.

        return (isReference() && getProject() != null)
            ? getRef(getProject()).selectorCount() : selectors.size();
    
public synchronized java.util.EnumerationselectorElements()
Returns an enumerator for accessing the set of selectors.

return
an Enumeration of selectors.

        return (isReference() && getProject() != null)
            ? getRef(getProject()).selectorElements() : selectors.elements();
    
public synchronized voidsetCaseSensitive(boolean caseSensitive)
Sets case sensitivity of the file system.

param
caseSensitive boolean.

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.caseSensitive = caseSensitive;
        directoryScanner = null;
    
public synchronized voidsetDefaultexcludes(boolean useDefaultExcludes)
Sets whether default exclusions should be used or not.

param
useDefaultExcludes boolean.

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.useDefaultExcludes = useDefaultExcludes;
        directoryScanner = null;
    
public synchronized voidsetDir(java.io.File dir)
Sets the base-directory for this instance.

param
dir the directory's File instance.
throws
BuildException on error

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.dir = dir;
        directoryScanner = null;
    
public synchronized voidsetExcludes(java.lang.String excludes)
Appends excludes to the current list of exclude patterns.

Patterns may be separated by a comma or a space.

param
excludes the String containing the exclude patterns.

        if (isReference()) {
            throw tooManyAttributes();
        }
        defaultPatterns.setExcludes(excludes);
        directoryScanner = null;
    
public synchronized voidsetExcludesfile(java.io.File excl)
Sets the File containing the excludes patterns.

param
excl File instance.
throws
BuildException on error

        if (isReference()) {
            throw tooManyAttributes();
        }
        defaultPatterns.setExcludesfile(excl);
        directoryScanner = null;
    
public synchronized voidsetFile(java.io.File file)
Creates a single file fileset.

param
file the single File included in this AbstractFileSet.

        if (isReference()) {
            throw tooManyAttributes();
        }
        setDir(file.getParentFile());
        createInclude().setName(file.getName());
    
public synchronized voidsetFollowSymlinks(boolean followSymlinks)
Sets whether or not symbolic links should be followed.

param
followSymlinks whether or not symbolic links should be followed.

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.followSymlinks = followSymlinks;
        directoryScanner = null;
    
public synchronized voidsetIncludes(java.lang.String includes)
Appends includes to the current list of include patterns.

Patterns may be separated by a comma or a space.

param
includes the String containing the include patterns.

        if (isReference()) {
            throw tooManyAttributes();
        }
        defaultPatterns.setIncludes(includes);
        directoryScanner = null;
    
public synchronized voidsetIncludesfile(java.io.File incl)
Sets the File containing the includes patterns.

param
incl File instance.
throws
BuildException on error

        if (isReference()) {
            throw tooManyAttributes();
        }
        defaultPatterns.setIncludesfile(incl);
        directoryScanner = null;
    
public voidsetRefid(Reference r)
Makes this instance in effect a reference to another instance.

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

param
r the Reference to use.
throws
BuildException on error

        if (dir != null || defaultPatterns.hasPatterns(getProject())) {
            throw tooManyAttributes();
        }
        if (!additionalPatterns.isEmpty()) {
            throw noChildrenAllowed();
        }
        if (!selectors.isEmpty()) {
            throw noChildrenAllowed();
        }
        super.setRefid(r);
    
public voidsetupDirectoryScanner(org.apache.tools.ant.FileScanner ds)
Set up the specified directory scanner against this AbstractFileSet's Project.

param
ds a FileScanner instance.

        setupDirectoryScanner(ds, getProject());
    
public synchronized voidsetupDirectoryScanner(org.apache.tools.ant.FileScanner ds, org.apache.tools.ant.Project p)
Set up the specified directory scanner against the specified project.

param
ds a FileScanner instance.
param
p an Ant Project instance.

        if (isReference()) {
            getRef(p).setupDirectoryScanner(ds, p);
            return;
        }
        if (ds == null) {
            throw new IllegalArgumentException("ds cannot be null");
        }
        ds.setBasedir(dir);

        PatternSet ps = mergePatterns(p);
        p.log(getDataTypeName() + ": Setup scanner in dir " + dir
            + " with " + ps, Project.MSG_DEBUG);

        ds.setIncludes(ps.getIncludePatterns(p));
        ds.setExcludes(ps.getExcludePatterns(p));
        if (ds instanceof SelectorScanner) {
            SelectorScanner ss = (SelectorScanner) ds;
            ss.setSelectors(getSelectors(p));
        }
        if (useDefaultExcludes) {
            ds.addDefaultExcludes();
        }
        ds.setCaseSensitive(caseSensitive);
    
public java.lang.StringtoString()
Returns included files as a list of semicolon-separated filenames.

return
a String of included filenames.

        DirectoryScanner ds = getDirectoryScanner(getProject());
        String[] files = ds.getIncludedFiles();
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < files.length; i++) {
            if (i > 0) {
                sb.append(';");
            }
            sb.append(files[i]);
        }
        return sb.toString();