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

PatternSet

public class PatternSet extends DataType implements Cloneable
Named collection of include/exclude tags.

Moved out of MatchingTask to make it a standalone object that could be referenced (by scripts for example).

Fields Summary
private Vector
includeList
private Vector
excludeList
private Vector
includesFileList
private Vector
excludesFileList
Constructors Summary
public PatternSet()
Creates a new PatternSet instance.

        super();
    
Methods Summary
public voidaddConfiguredPatternset(org.apache.tools.ant.types.PatternSet p)
This is a patternset nested element.

param
p a configured patternset nested element.

        if (isReference()) {
            throw noChildrenAllowed();
        }

        String[] nestedIncludes = p.getIncludePatterns(getProject());
        String[] nestedExcludes = p.getExcludePatterns(getProject());

        if (nestedIncludes != null) {
            for (int i = 0; i < nestedIncludes.length; i++) {
                createInclude().setName(nestedIncludes[i]);
            }
        }

        if (nestedExcludes != null) {
            for (int i = 0; i < nestedExcludes.length; i++) {
                createExclude().setName(nestedExcludes[i]);
            }
        }
    
private org.apache.tools.ant.types.PatternSet$NameEntryaddPatternToList(java.util.Vector list)
add a name entry to the given list

        NameEntry result = new NameEntry();
        list.addElement(result);
        return result;
    
public voidappend(org.apache.tools.ant.types.PatternSet other, org.apache.tools.ant.Project p)
Adds the patterns of the other instance to this set.

param
other the other PatternSet instance.
param
p the current project.

        if (isReference()) {
            throw new BuildException("Cannot append to a reference");
        }

        String[] incl = other.getIncludePatterns(p);
        if (incl != null) {
            for (int i = 0; i < incl.length; i++) {
                createInclude().setName(incl[i]);
            }
        }

        String[] excl = other.getExcludePatterns(p);
        if (excl != null) {
            for (int i = 0; i < excl.length; i++) {
                createExclude().setName(excl[i]);
            }
        }
    
public java.lang.Objectclone()

since
Ant 1.6
return
a clone of this patternset.

        try {
            PatternSet ps = (PatternSet) super.clone();
            ps.includeList = (Vector) includeList.clone();
            ps.excludeList = (Vector) excludeList.clone();
            ps.includesFileList = (Vector) includesFileList.clone();
            ps.excludesFileList = (Vector) excludesFileList.clone();
            return ps;
        } catch (CloneNotSupportedException e) {
            throw new BuildException(e);
        }
    
public org.apache.tools.ant.types.PatternSet$NameEntrycreateExclude()
add a name entry on the exclude list

return
a nested exclude element to be configured.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        return addPatternToList(excludeList);
    
public org.apache.tools.ant.types.PatternSet$NameEntrycreateExcludesFile()
add a name entry on the exclude files list

return
a nested excludesfile element to be configured.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        return addPatternToList(excludesFileList);
    
public org.apache.tools.ant.types.PatternSet$NameEntrycreateInclude()
add a name entry on the include list

return
a nested include element to be configured.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        return addPatternToList(includeList);
    
public org.apache.tools.ant.types.PatternSet$NameEntrycreateIncludesFile()
add a name entry on the include files list

return
a nested includesfile element to be configured.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        return addPatternToList(includesFileList);
    
public java.lang.String[]getExcludePatterns(org.apache.tools.ant.Project p)
Returns the filtered include patterns.

param
p the current project.
return
the filtered excluded patterns.

        if (isReference()) {
            return getRef(p).getExcludePatterns(p);
        } else {
            readFiles(p);
            return makeArray(excludeList, p);
        }
    
public java.lang.String[]getIncludePatterns(org.apache.tools.ant.Project p)
Returns the filtered include patterns.

param
p the current project.
return
the filtered included patterns.

        if (isReference()) {
            return getRef(p).getIncludePatterns(p);
        } else {
            readFiles(p);
            return makeArray(includeList, p);
        }
    
private org.apache.tools.ant.types.PatternSetgetRef(org.apache.tools.ant.Project p)
Performs the check for circular references and returns the referenced PatternSet.

        return (PatternSet) getCheckedRef(p);
    
public booleanhasPatterns(org.apache.tools.ant.Project p)
Helper for FileSet classes. Check if there are patterns defined.

param
p the current project.
return
true if there are patterns.

        if (isReference()) {
            return getRef(p).hasPatterns(p);
        } else {
            return includesFileList.size() > 0 || excludesFileList.size() > 0
                || includeList.size() > 0 || excludeList.size() > 0;
        }
    
private java.lang.String[]makeArray(java.util.Vector list, org.apache.tools.ant.Project p)
Convert a vector of NameEntry elements into an array of Strings.

        if (list.size() == 0) {
            return null;
        }

        Vector tmpNames = new Vector();
        for (Enumeration e = list.elements(); e.hasMoreElements();) {
            NameEntry ne = (NameEntry) e.nextElement();
            String pattern = ne.evalName(p);
            if (pattern != null && pattern.length() > 0) {
                tmpNames.addElement(pattern);
            }
        }

        String[] result = new String[tmpNames.size()];
        tmpNames.copyInto(result);
        return result;
    
private voidreadFiles(org.apache.tools.ant.Project p)
Read includesfile ot excludesfile if not already done so.

        if (includesFileList.size() > 0) {
            Enumeration e = includesFileList.elements();
            while (e.hasMoreElements()) {
                NameEntry ne = (NameEntry) e.nextElement();
                String fileName = ne.evalName(p);
                if (fileName != null) {
                    File inclFile = p.resolveFile(fileName);
                    if (!inclFile.exists()) {
                        throw new BuildException("Includesfile "
                                                 + inclFile.getAbsolutePath()
                                                 + " not found.");
                    }
                    readPatterns(inclFile, includeList, p);
                }
            }
            includesFileList.removeAllElements();
        }

        if (excludesFileList.size() > 0) {
            Enumeration e = excludesFileList.elements();
            while (e.hasMoreElements()) {
                NameEntry ne = (NameEntry) e.nextElement();
                String fileName = ne.evalName(p);
                if (fileName != null) {
                    File exclFile = p.resolveFile(fileName);
                    if (!exclFile.exists()) {
                        throw new BuildException("Excludesfile "
                                                 + exclFile.getAbsolutePath()
                                                 + " not found.");
                    }
                    readPatterns(exclFile, excludeList, p);
                }
            }
            excludesFileList.removeAllElements();
        }
    
private voidreadPatterns(java.io.File patternfile, java.util.Vector patternlist, org.apache.tools.ant.Project p)
Reads path matching patterns from a file and adds them to the includes or excludes list (as appropriate).


        BufferedReader patternReader = null;
        try {
            // Get a FileReader
            patternReader =
                new BufferedReader(new FileReader(patternfile));

            // Create one NameEntry in the appropriate pattern list for each
            // line in the file.
            String line = patternReader.readLine();
            while (line != null) {
                if (line.length() > 0) {
                    line = p.replaceProperties(line);
                    addPatternToList(patternlist).setName(line);
                }
                line = patternReader.readLine();
            }
        } catch (IOException ioe)  {
            String msg = "An error occurred while reading from pattern file: "
                + patternfile;
            throw new BuildException(msg, ioe);
        } finally {
            if (null != patternReader) {
                try {
                    patternReader.close();
                } catch (IOException ioe) {
                    //Ignore exception
                }
            }
        }
    
public 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();
        }
        if (excludes != null && excludes.length() > 0) {
            StringTokenizer tok = new StringTokenizer(excludes, ", ", false);
            while (tok.hasMoreTokens()) {
                createExclude().setName(tok.nextToken());
            }
        }
    
public voidsetExcludesfile(java.io.File excludesFile)
Sets the name of the file containing the excludes patterns.

param
excludesFile The file to fetch the exclude patterns from.
throws
BuildException on error.

         if (isReference()) {
             throw tooManyAttributes();
         }
         createExcludesFile().setName(excludesFile.getAbsolutePath());
     
public 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();
        }
        if (includes != null && includes.length() > 0) {
            StringTokenizer tok = new StringTokenizer(includes, ", ", false);
            while (tok.hasMoreTokens()) {
                createInclude().setName(tok.nextToken());
            }
        }
    
public voidsetIncludesfile(java.io.File includesFile)
Sets the name of the file containing the includes patterns.

param
includesFile The file to fetch the include patterns from.
throws
BuildException on error.

         if (isReference()) {
             throw tooManyAttributes();
         }
         createIncludesFile().setName(includesFile.getAbsolutePath());
     
public voidsetRefid(Reference r)
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.

param
r the reference to another patternset.
throws
BuildException on error.

        if (!includeList.isEmpty() || !excludeList.isEmpty()) {
            throw tooManyAttributes();
        }
        super.setRefid(r);
    
public java.lang.StringtoString()

return
a printable form of this object.

        return "patternSet{ includes: " + includeList
                + " excludes: " + excludeList + " }";