FileDocCategorySizeDatePackage
Files.javaAPI DocApache Ant 1.7015646Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.resources

Files

public class Files extends org.apache.tools.ant.types.selectors.AbstractSelectorContainer implements Cloneable, org.apache.tools.ant.types.ResourceCollection
ResourceCollection implementation; like AbstractFileSet with absolute paths.
since
Ant 1.7

Fields Summary
private static final Iterator
EMPTY_ITERATOR
private org.apache.tools.ant.types.PatternSet
defaultPatterns
private Vector
additionalPatterns
private Vector
selectors
private boolean
useDefaultExcludes
private boolean
caseSensitive
private boolean
followSymlinks
private org.apache.tools.ant.DirectoryScanner
ds
Constructors Summary
public Files()
Construct a new Files collection.


              
      
        super();
    
protected Files(Files f)
Construct a new Files collection, shallowly cloned from the specified Files.

param
f the Files to use as a template.

        this.defaultPatterns = f.defaultPatterns;
        this.additionalPatterns = f.additionalPatterns;
        this.selectors = f.selectors;
        this.useDefaultExcludes = f.useDefaultExcludes;
        this.caseSensitive = f.caseSensitive;
        this.followSymlinks = f.followSymlinks;
        this.ds = f.ds;
        setProject(f.getProject());
    
Methods Summary
public synchronized voidappendExcludes(java.lang.String[] excludes)
Append excludes to the current list of include patterns.

param
excludes array containing the exclude patterns.

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

param
includes array containing the include patterns.

        checkAttributesAllowed();
        if (includes != null) {
            for (int i = 0; i < includes.length; i++) {
                defaultPatterns.createInclude().setName(includes[i]);
            }
            ds = 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();
        }
        super.appendSelector(selector);
        ds = null;
    
public synchronized java.lang.Objectclone()
Create 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
a cloned Object.

        if (isReference()) {
            return getRef().clone();
        }
        try {
            Files f = (Files) super.clone();
            f.defaultPatterns = (PatternSet) defaultPatterns.clone();
            f.additionalPatterns = new Vector(additionalPatterns.size());
            for (Iterator iter = additionalPatterns.iterator(); iter.hasNext();) {
                PatternSet ps = (PatternSet) iter.next();
                f.additionalPatterns.add(ps.clone());
            }
            f.selectors = new Vector(selectors);
            return f;
        } 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();
        }
        ds = null;
        return defaultPatterns.createExclude();
    
public synchronized PatternSet.NameEntrycreateExcludesFile()
Add a name entry to the excludes files list.

return
PatternSet.NameEntry.

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

return
PatternSet.NameEntry.

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

return
PatternSet.NameEntry.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        ds = null;
        return defaultPatterns.createIncludesFile();
    
public synchronized org.apache.tools.ant.types.PatternSetcreatePatternSet()
Create a nested patternset.

return
PatternSet.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        PatternSet patterns = new PatternSet();
        additionalPatterns.addElement(patterns);
        ds = null;
        return patterns;
    
private synchronized voidensureDirectoryScannerSetup()

        if (ds == null) {
            ds = new DirectoryScanner();
            PatternSet ps = mergePatterns(getProject());
            ds.setIncludes(ps.getIncludePatterns(getProject()));
            ds.setExcludes(ps.getExcludePatterns(getProject()));
            ds.setSelectors(getSelectors(getProject()));
            if (useDefaultExcludes) {
                ds.addDefaultExcludes();
            }
            ds.setCaseSensitive(caseSensitive);
            ds.setFollowSymlinks(followSymlinks);
        }
    
public synchronized booleangetDefaultexcludes()
Get whether default exclusions should be used or not.

return
the defaultexclusions value.

        return (isReference())
            ? getRef().getDefaultexcludes() : useDefaultExcludes;
    
protected org.apache.tools.ant.types.resources.FilesgetRef()
Perform the check for circular references and return the referenced Files collection.

return
FileCollection.

        return (Files) getCheckedRef();
    
public synchronized booleanhasPatterns()
Find out whether this Files collection has patterns.

return
whether any patterns are in this container.

        if (isReference()) {
            return getRef().hasPatterns();
        }
        if (hasPatterns(defaultPatterns)) {
            return true;
        }
        for (Iterator i = additionalPatterns.iterator(); i.hasNext();) {
            if (hasPatterns((PatternSet) i.next())) {
                return true;
            }
        }
        return false;
    
private booleanhasPatterns(org.apache.tools.ant.types.PatternSet ps)

        return ps.getIncludePatterns(getProject()).length > 0
            || ps.getExcludePatterns(getProject()).length > 0;
    
public synchronized booleanisCaseSensitive()
Find out if this Files collection is case-sensitive.

return
boolean indicating whether the Files collection is case-sensitive.

        return (isReference())
            ? getRef().isCaseSensitive() : caseSensitive;
    
public booleanisFilesystemOnly()
Always returns true.

return
true indicating that all elements of a Files collection will be FileResources.

        return true;
    
public synchronized booleanisFollowSymlinks()
Find out whether symbolic links should be followed.

return
boolean indicating whether symbolic links should be followed.

        return (isReference())
            ? getRef().isFollowSymlinks() : followSymlinks;
    
public synchronized java.util.Iteratoriterator()
Fulfill the ResourceCollection contract.

return
an Iterator of Resources.

        if (isReference()) {
            return getRef().iterator();
        }
        ensureDirectoryScannerSetup();
        ds.scan();
        int fct = ds.getIncludedFilesCount();
        int dct = ds.getIncludedDirsCount();
        if (fct + dct == 0) {
            return EMPTY_ITERATOR;
        }
        FileResourceIterator result = new FileResourceIterator();
        if (fct > 0) {
            result.addFiles(ds.getIncludedFiles());
        }
        if (dct > 0) {
            result.addFiles(ds.getIncludedDirectories());
        }
        return result;
    
public java.lang.String[]mergeExcludes(org.apache.tools.ant.Project p)
Get the merged exclude patterns for this Files collection.

param
p Project instance.
return
the exclude patterns of the default pattern set and all nested patternsets.

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

param
p Project instance.
return
the include patterns of the default pattern set and all nested patternsets.

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

param
p Project instance.
return
the default patternset merged with the additional sets in a new PatternSet instance.

        if (isReference()) {
            return getRef().mergePatterns(p);
        }
        PatternSet ps = new PatternSet();
        ps.append(defaultPatterns, p);
        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 voidsetCaseSensitive(boolean caseSensitive)
Set case-sensitivity of the Files collection.

param
caseSensitive boolean.

        checkAttributesAllowed();
        this.caseSensitive = caseSensitive;
        ds = null;
    
public synchronized voidsetDefaultexcludes(boolean useDefaultExcludes)
Set whether default exclusions should be used or not.

param
useDefaultExcludes boolean.

        checkAttributesAllowed();
        this.useDefaultExcludes = useDefaultExcludes;
        ds = null;
    
public synchronized voidsetExcludes(java.lang.String excludes)
Append 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.

        checkAttributesAllowed();
        defaultPatterns.setExcludes(excludes);
        ds = null;
    
public synchronized voidsetExcludesfile(java.io.File excl)
Set the File containing the excludes patterns.

param
excl File instance.
throws
BuildException if there is a problem.

        checkAttributesAllowed();
        defaultPatterns.setExcludesfile(excl);
        ds = null;
    
public synchronized voidsetFollowSymlinks(boolean followSymlinks)
Set whether or not symbolic links should be followed.

param
followSymlinks whether or not symbolic links should be followed.

        checkAttributesAllowed();
        this.followSymlinks = followSymlinks;
        ds = null;
    
public synchronized voidsetIncludes(java.lang.String includes)
Append 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.

        checkAttributesAllowed();
        defaultPatterns.setIncludes(includes);
        ds = null;
    
public synchronized voidsetIncludesfile(java.io.File incl)
Set the File containing the includes patterns.

param
incl File instance.
throws
BuildException if there is a problem.

        checkAttributesAllowed();
        defaultPatterns.setIncludesfile(incl);
        ds = null;
    
public voidsetRefid(org.apache.tools.ant.types.Reference r)
Make 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 if there is a problem.

        if (hasPatterns(defaultPatterns)) {
            throw tooManyAttributes();
        }
        if (!additionalPatterns.isEmpty()) {
            throw noChildrenAllowed();
        }
        if (!selectors.isEmpty()) {
            throw noChildrenAllowed();
        }
        super.setRefid(r);
    
public synchronized intsize()
Fulfill the ResourceCollection contract.

return
number of elements as int.

        if (isReference()) {
            return getRef().size();
        }
        ensureDirectoryScannerSetup();
        ds.scan();
        return ds.getIncludedFilesCount() + ds.getIncludedDirsCount();
    
public java.lang.StringtoString()
Format this Files collection as a String.

return
a descriptive String.

        if (isReference()) {
            return getRef().toString();
        }
        Iterator i = iterator();
        if (!i.hasNext()) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        while (i.hasNext()) {
            if (sb.length() > 0) {
                sb.append(File.pathSeparatorChar);
            }
            sb.append(i.next());
        }
        return sb.toString();