git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@896787 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,34 +0,0 @@ | |||||
| Selector API | |||||
| ============ | |||||
| Currently our filesets allow us to select a set of files based on name patterns. | |||||
| For instance we could create a set of all the files that end with ".java". | |||||
| However there are cases when you wish to select files based on their other | |||||
| attributes, such as if they are read only or if they are older than a specified | |||||
| date etc. | |||||
| The selector API is one such mechanism to do this. The selector API will allow | |||||
| you to build file sets based on criteria other than name. Some possible criteria | |||||
| would be | |||||
| Is the file readable? | |||||
| Is the file writeable? | |||||
| What date was the file modified on? | |||||
| What size is the file? | |||||
| Does the contents contain the string "magic"? | |||||
| If we end up supporting a VFS then we could expand the number of selectors | |||||
| considerably. A mock representation that has been proposed before is the | |||||
| following. Of course this is subject to change as soon as someone wants to | |||||
| tackle this action ;) | |||||
| <include name="**/*.java"> | |||||
| <selector type="permission" value="r"/> | |||||
| <!-- could optionally be directory/or some other system specific features --> | |||||
| <selector type="type" value="file"/> | |||||
| <selector type="modify-time" | |||||
| operation="greater-than" | |||||
| value="29th Feb 2003"/> | |||||
| </include> | |||||
| @@ -1,175 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant; | |||||
| import java.io.File; | |||||
| import org.apache.tools.ant.types.Pattern; | |||||
| /** | |||||
| * An interface used to describe the actions required by any type of | |||||
| * directory scanner. | |||||
| */ | |||||
| public interface FileScanner { | |||||
| /** | |||||
| * Adds an array with default exclusions to the current exclusions set. | |||||
| * | |||||
| */ | |||||
| void addDefaultExcludes(); | |||||
| /** | |||||
| * Gets the basedir that is used for scanning. This is the directory that | |||||
| * is scanned recursively. | |||||
| * | |||||
| * @return the basedir that is used for scanning | |||||
| */ | |||||
| File getBasedir(); | |||||
| /** | |||||
| * Get the names of the directories that matched at least one of the include | |||||
| * patterns, an matched also at least one of the exclude patterns. | |||||
| * The names are relative to the basedir. | |||||
| * | |||||
| * @return the names of the directories | |||||
| */ | |||||
| String[] getExcludedDirectories(); | |||||
| /** | |||||
| * Get the names of the files that matched at least one of the include | |||||
| * patterns, an matched also at least one of the exclude patterns. | |||||
| * The names are relative to the basedir. | |||||
| * | |||||
| * @return the names of the files | |||||
| */ | |||||
| String[] getExcludedFiles(); | |||||
| /** | |||||
| * Get the names of the directories that matched at least one of the include | |||||
| * patterns, an matched none of the exclude patterns. | |||||
| * The names are relative to the basedir. | |||||
| * | |||||
| * @return the names of the directories | |||||
| */ | |||||
| String[] getIncludedDirectories(); | |||||
| /** | |||||
| * Get the names of the files that matched at least one of the include | |||||
| * patterns, an matched none of the exclude patterns. | |||||
| * The names are relative to the basedir. | |||||
| * | |||||
| * @return the names of the files | |||||
| */ | |||||
| String[] getIncludedFiles(); | |||||
| /** | |||||
| * Get the names of the directories that matched at none of the include | |||||
| * patterns. | |||||
| * The names are relative to the basedir. | |||||
| * | |||||
| * @return the names of the directories | |||||
| */ | |||||
| String[] getNotIncludedDirectories(); | |||||
| /** | |||||
| * Get the names of the files that matched at none of the include patterns. | |||||
| * The names are relative to the basedir. | |||||
| * | |||||
| * @return the names of the files | |||||
| */ | |||||
| String[] getNotIncludedFiles(); | |||||
| /** | |||||
| * Scans the base directory for files that match at least one include | |||||
| * pattern, and don't match any exclude patterns. | |||||
| * | |||||
| * @exception IllegalStateException when basedir was set incorrecly | |||||
| */ | |||||
| void scan(); | |||||
| /** | |||||
| * Sets the basedir for scanning. This is the directory that is scanned | |||||
| * recursively. | |||||
| * | |||||
| * @param basedir the (non-null) basedir for scanning | |||||
| */ | |||||
| void setBasedir(String basedir); | |||||
| /** | |||||
| * Sets the basedir for scanning. This is the directory that is scanned | |||||
| * recursively. | |||||
| * | |||||
| * @param basedir the basedir for scanning | |||||
| */ | |||||
| void setBasedir(File basedir); | |||||
| /** | |||||
| * Sets the set of exclude patterns to use. | |||||
| * | |||||
| * @param excludes list of exclude patterns | |||||
| */ | |||||
| void setExcludes(String[] excludes); | |||||
| /** | |||||
| * Sets the set of include patterns to use. | |||||
| * | |||||
| * @param includes list of include patterns | |||||
| */ | |||||
| void setIncludes(String[] includes); | |||||
| /** | |||||
| * Sets the set of exclude patterns to use. | |||||
| * | |||||
| * @param excludes list of exclude patterns | |||||
| */ | |||||
| void setExcludes(Pattern[] excludes); | |||||
| /** | |||||
| * Sets the set of include patterns to use. | |||||
| * | |||||
| * @param includes list of include patterns | |||||
| */ | |||||
| void setIncludes(Pattern[] includes); | |||||
| /** | |||||
| * Sets the case sensitivity of the file system | |||||
| * | |||||
| * @param specifies if the filesystem is case sensitive | |||||
| */ | |||||
| void setCaseSensitive(boolean isCaseSensitive); | |||||
| } | |||||
| @@ -1,66 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2002 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.selectors; | |||||
| import java.io.File; | |||||
| /** | |||||
| * File Selector API. | |||||
| * | |||||
| */ | |||||
| public interface FileSelector { | |||||
| public void setValue(final String value); | |||||
| public void setOperation(final String operation); | |||||
| public boolean isSelected(final String file); | |||||
| } | |||||
| @@ -1,127 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2002 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.selectors; | |||||
| import java.io.File; | |||||
| /** | |||||
| * File selector that performs selection based on | |||||
| * file type - file and directory. | |||||
| * | |||||
| */ | |||||
| public class FileTypeSelector implements FileSelector { | |||||
| private String value = null; | |||||
| private String operation = "equals"; | |||||
| private boolean cached = false; | |||||
| private boolean negate = false; | |||||
| private boolean checkForFile = false; | |||||
| private boolean checkForDir = false; | |||||
| public void setCached(final boolean cached) { | |||||
| this.cached = cached; | |||||
| } | |||||
| public boolean isCached() { | |||||
| return cached; | |||||
| } | |||||
| public void setValue(final String value) { | |||||
| this.value = value; | |||||
| setCached(false); | |||||
| } | |||||
| public void setOperation(final String operation) { | |||||
| this.operation = operation; | |||||
| setCached(false); | |||||
| } | |||||
| public void doCache() { | |||||
| if (!isCached()) { | |||||
| if (value == null) { | |||||
| throw new NullPointerException("value must not be null."); | |||||
| } | |||||
| if (value.equalsIgnoreCase("file")) { | |||||
| checkForFile = true; | |||||
| checkForDir = false; | |||||
| } else if (value.equalsIgnoreCase("directory")) { | |||||
| checkForDir = true; | |||||
| checkForFile = false; | |||||
| } | |||||
| if (!operation.equalsIgnoreCase("equals")) { | |||||
| negate = true; | |||||
| } else { | |||||
| negate = false; | |||||
| } | |||||
| setCached(true); | |||||
| } | |||||
| } | |||||
| public boolean isSelected(final String file) { | |||||
| doCache(); | |||||
| if (file == null) { | |||||
| throw new NullPointerException("file must not be null."); | |||||
| } | |||||
| boolean retValue = false; | |||||
| File f = new File(file); | |||||
| if (checkForFile) { | |||||
| retValue = f.isFile(); | |||||
| } else if (checkForDir) { | |||||
| retValue = f.isDirectory(); | |||||
| } | |||||
| if (negate) { | |||||
| retValue = !retValue; | |||||
| } | |||||
| return retValue; | |||||
| } | |||||
| } | |||||
| @@ -1 +0,0 @@ | |||||
| type=org.apache.tools.ant.selectors.FileTypeSelector | |||||
| @@ -1,335 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.FileScanner; | |||||
| import org.apache.tools.ant.DirectoryScanner; | |||||
| import org.apache.tools.ant.Project; | |||||
| import java.io.File; | |||||
| import java.util.Stack; | |||||
| import java.util.Vector; | |||||
| /** | |||||
| * Moved out of MatchingTask to make it a standalone object that could | |||||
| * be referenced (by scripts for example). | |||||
| * | |||||
| */ | |||||
| public class FileSet extends DataType implements Cloneable { | |||||
| private PatternSet defaultPatterns = new PatternSet(); | |||||
| private Vector additionalPatterns = new Vector(); | |||||
| private File dir; | |||||
| private boolean useDefaultExcludes = true; | |||||
| private boolean isCaseSensitive = true; | |||||
| public FileSet() { | |||||
| super(); | |||||
| } | |||||
| protected FileSet(FileSet fileset) { | |||||
| this.dir = fileset.dir; | |||||
| this.defaultPatterns = fileset.defaultPatterns; | |||||
| this.additionalPatterns = fileset.additionalPatterns; | |||||
| this.useDefaultExcludes = fileset.useDefaultExcludes; | |||||
| this.isCaseSensitive = fileset.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 whether default exclusions should be used or not. | |||||
| * | |||||
| * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||||
| * should be used, "false"|"off"|"no" when they | |||||
| * shouldn't be used. | |||||
| */ | |||||
| public void setDefaultexcludes(boolean useDefaultExcludes) { | |||||
| if (isReference()) { | |||||
| throw tooManyAttributes(); | |||||
| } | |||||
| this.useDefaultExcludes = useDefaultExcludes; | |||||
| } | |||||
| /** | |||||
| * 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 files to process. | |||||
| */ | |||||
| public DirectoryScanner getDirectoryScanner(Project p) { | |||||
| if (isReference()) { | |||||
| return getRef(p).getDirectoryScanner(p); | |||||
| } | |||||
| if (dir == null) { | |||||
| throw new BuildException("No directory specified for fileset."); | |||||
| } | |||||
| 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(); | |||||
| return ds; | |||||
| } | |||||
| public void setupDirectoryScanner(FileScanner ds, Project p) { | |||||
| if (ds == null) { | |||||
| throw new IllegalArgumentException("ds cannot be null"); | |||||
| } | |||||
| ds.setBasedir(dir); | |||||
| for (int i=0; i<additionalPatterns.size(); i++) { | |||||
| Object o = additionalPatterns.elementAt(i); | |||||
| defaultPatterns.append2((PatternSet) o, p); | |||||
| } | |||||
| p.log( "FileSet: Setup file scanner in dir " + dir + | |||||
| " with " + defaultPatterns, p.MSG_DEBUG ); | |||||
| ds.setIncludes(defaultPatterns.getIncludePatterns2(p)); | |||||
| ds.setExcludes(defaultPatterns.getExcludePatterns2(p)); | |||||
| if (useDefaultExcludes) { | |||||
| ds.addDefaultExcludes(); | |||||
| } | |||||
| ds.setCaseSensitive(isCaseSensitive); | |||||
| } | |||||
| /** | |||||
| * Performs the check for circular references and returns the | |||||
| * referenced FileSet. | |||||
| */ | |||||
| protected FileSet getRef(Project p) { | |||||
| if (!checked) { | |||||
| Stack stk = new Stack(); | |||||
| stk.push(this); | |||||
| dieOnCircularReference(stk, p); | |||||
| } | |||||
| Object o = ref.getReferencedObject(p); | |||||
| if (!(o instanceof FileSet)) { | |||||
| String msg = ref.getRefId()+" doesn\'t denote a fileset"; | |||||
| throw new BuildException(msg); | |||||
| } else { | |||||
| return (FileSet) o; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Return a FileSet that has the same basedir and same patternsets | |||||
| * as this one. | |||||
| */ | |||||
| public Object clone() { | |||||
| if (isReference()) { | |||||
| return new FileSet(getRef(getProject())); | |||||
| } else { | |||||
| return new FileSet(this); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,103 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2002 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.types; | |||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.ProjectHelper; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import java.io.*; | |||||
| import java.util.Enumeration; | |||||
| import java.util.Stack; | |||||
| import java.util.StringTokenizer; | |||||
| import java.util.Vector; | |||||
| /** | |||||
| * Named collection of include/exclude tags. | |||||
| * | |||||
| */ | |||||
| public class Pattern { | |||||
| private String pattern = null; | |||||
| private Vector selectorList = null; | |||||
| /** | |||||
| * Set the pattern | |||||
| * @param pattern the pattern to match | |||||
| */ | |||||
| public void setPattern(String pattern) { | |||||
| this.pattern = pattern; | |||||
| } | |||||
| /** | |||||
| * Set the list of Selector entries | |||||
| * @param selectorList the vector list of 'SelectorEntry's | |||||
| */ | |||||
| public void setSelectorList(Vector selectorList) { | |||||
| this.selectorList = selectorList; | |||||
| } | |||||
| /** | |||||
| * Get the pattern | |||||
| */ | |||||
| public String getPattern() { | |||||
| return pattern; | |||||
| } | |||||
| /** | |||||
| * Get the list of Selector entries | |||||
| */ | |||||
| public Vector getSelectorList() { | |||||
| return selectorList; | |||||
| } | |||||
| } | |||||
| @@ -1,587 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.types; | |||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.ProjectHelper; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import java.io.File; | |||||
| import java.io.BufferedReader; | |||||
| import java.io.FileReader; | |||||
| import java.io.IOException; | |||||
| import java.util.Enumeration; | |||||
| import java.util.Stack; | |||||
| import java.util.StringTokenizer; | |||||
| import java.util.Vector; | |||||
| /** | |||||
| * Named collection of include/exclude tags. | |||||
| * | |||||
| * <p>Moved out of MatchingTask to make it a standalone object that | |||||
| * could be referenced (by scripts for example). | |||||
| * | |||||
| */ | |||||
| public class PatternSet extends DataType { | |||||
| private Vector includeList = new Vector(); | |||||
| private Vector excludeList = new Vector(); | |||||
| private Vector includesFileList = new Vector(); | |||||
| private Vector excludesFileList = new Vector(); | |||||
| /** | |||||
| * inner class to hold a selector list. A SelectorEntry | |||||
| * is made up of the pattern and selection detail. | |||||
| */ | |||||
| public static class SelectorEntry { | |||||
| private String type; | |||||
| private String value; | |||||
| private String operation; | |||||
| public void setType(String t) { | |||||
| this.type = t; | |||||
| } | |||||
| public void setValue(String val) { | |||||
| this.value = val; | |||||
| } | |||||
| public void setOperation(String op) { | |||||
| this.operation = op; | |||||
| } | |||||
| public String getType() { | |||||
| return type; | |||||
| } | |||||
| public String getValue() { | |||||
| return value; | |||||
| } | |||||
| public String getOperation() { | |||||
| return operation; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * inner class to hold a name on list. "If" and "Unless" attributes | |||||
| * may be used to invalidate the entry based on the existence of a | |||||
| * property (typically set thru the use of the Available task). | |||||
| */ | |||||
| public class NameEntry { | |||||
| private String name; | |||||
| private String ifCond; | |||||
| private String unlessCond; | |||||
| private Vector selectorList = new Vector(); | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| public void setIf(String cond) { | |||||
| ifCond = cond; | |||||
| } | |||||
| public void setUnless(String cond) { | |||||
| unlessCond = cond; | |||||
| } | |||||
| /** | |||||
| * Include/Exclude can contain nested selectors | |||||
| */ | |||||
| public SelectorEntry createSelector() { | |||||
| if (isReference()) { | |||||
| throw noChildrenAllowed(); | |||||
| } | |||||
| return addSelectorToList(selectorList); | |||||
| } | |||||
| /** | |||||
| * add a selector entry to the given list | |||||
| */ | |||||
| private SelectorEntry addSelectorToList(final Vector list) { | |||||
| final SelectorEntry result = new SelectorEntry(); | |||||
| list.addElement(result); | |||||
| return result; | |||||
| } | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public Vector getSelectorList() { | |||||
| return selectorList; | |||||
| } | |||||
| public String evalName(Project p) { | |||||
| return valid(p) ? name : null; | |||||
| } | |||||
| private boolean valid(Project p) { | |||||
| if (ifCond != null && p.getProperty(ifCond) == null) { | |||||
| return false; | |||||
| } else if (unlessCond != null && p.getProperty(unlessCond) != null) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| public String toString() { | |||||
| StringBuffer buf = new StringBuffer(name); | |||||
| if ((ifCond != null) || (unlessCond != null)) { | |||||
| buf.append(":"); | |||||
| String connector = ""; | |||||
| if (ifCond != null) { | |||||
| buf.append("if->"); | |||||
| buf.append(ifCond); | |||||
| connector = ";"; | |||||
| } | |||||
| if (unlessCond != null) { | |||||
| buf.append(connector); | |||||
| buf.append("unless->"); | |||||
| buf.append(unlessCond); | |||||
| } | |||||
| } | |||||
| return buf.toString(); | |||||
| } | |||||
| public void setSelectorList(Vector list) { | |||||
| this.selectorList = list; | |||||
| } | |||||
| } | |||||
| public PatternSet() { | |||||
| super(); | |||||
| } | |||||
| /** | |||||
| * 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 (!includeList.isEmpty() || !excludeList.isEmpty()) { | |||||
| throw tooManyAttributes(); | |||||
| } | |||||
| super.setRefid(r); | |||||
| } | |||||
| /** | |||||
| * add a name entry on the include list | |||||
| */ | |||||
| public NameEntry createInclude() { | |||||
| if (isReference()) { | |||||
| throw noChildrenAllowed(); | |||||
| } | |||||
| return addPatternToList(includeList); | |||||
| } | |||||
| /** | |||||
| * add a name entry on the include files list | |||||
| */ | |||||
| public NameEntry createIncludesFile() { | |||||
| if (isReference()) { | |||||
| throw noChildrenAllowed(); | |||||
| } | |||||
| return addPatternToList(includesFileList); | |||||
| } | |||||
| /** | |||||
| * add a name entry on the exclude list | |||||
| */ | |||||
| public NameEntry createExclude() { | |||||
| if (isReference()) { | |||||
| throw noChildrenAllowed(); | |||||
| } | |||||
| return addPatternToList(excludeList); | |||||
| } | |||||
| /** | |||||
| * add a name entry on the exclude files list | |||||
| */ | |||||
| public NameEntry createExcludesFile() { | |||||
| if (isReference()) { | |||||
| throw noChildrenAllowed(); | |||||
| } | |||||
| return addPatternToList(excludesFileList); | |||||
| } | |||||
| /** | |||||
| * 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(); | |||||
| } | |||||
| if (includes != null && includes.length() > 0) { | |||||
| StringTokenizer tok = new StringTokenizer(includes, ", ", false); | |||||
| while (tok.hasMoreTokens()) { | |||||
| createInclude().setName(tok.nextToken()); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 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(); | |||||
| } | |||||
| if (excludes != null && excludes.length() > 0) { | |||||
| StringTokenizer tok = new StringTokenizer(excludes, ", ", false); | |||||
| while (tok.hasMoreTokens()) { | |||||
| createExclude().setName(tok.nextToken()); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * add a name entry to the given list | |||||
| */ | |||||
| private NameEntry addPatternToList(Vector list) { | |||||
| NameEntry result = new NameEntry(); | |||||
| list.addElement(result); | |||||
| return result; | |||||
| } | |||||
| /** | |||||
| * Sets the name of the file containing the includes patterns. | |||||
| * | |||||
| * @param includesFile The file to fetch the include patterns from. | |||||
| */ | |||||
| public void setIncludesfile(File includesFile) throws BuildException { | |||||
| if (isReference()) { | |||||
| throw tooManyAttributes(); | |||||
| } | |||||
| createIncludesFile().setName(includesFile.getAbsolutePath()); | |||||
| } | |||||
| /** | |||||
| * Sets the name of the file containing the excludes patterns. | |||||
| * | |||||
| * @param excludesFile The file to fetch the exclude patterns from. | |||||
| */ | |||||
| public void setExcludesfile(File excludesFile) throws BuildException { | |||||
| if (isReference()) { | |||||
| throw tooManyAttributes(); | |||||
| } | |||||
| createExcludesFile().setName(excludesFile.getAbsolutePath()); | |||||
| } | |||||
| /** | |||||
| * Reads path matching patterns from a file and adds them to the | |||||
| * includes or excludes list (as appropriate). | |||||
| */ | |||||
| private void readPatterns(File patternfile, Vector patternlist, Project p) | |||||
| throws BuildException { | |||||
| 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 occured while reading from pattern file: " | |||||
| + patternfile; | |||||
| throw new BuildException(msg, ioe); | |||||
| } finally { | |||||
| if( null != patternReader ) { | |||||
| try { | |||||
| patternReader.close(); | |||||
| } catch(IOException ioe) { | |||||
| //Ignore exception | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| public void append2(PatternSet other, Project p) { | |||||
| if (isReference()) { | |||||
| throw new BuildException("Cannot append to a reference"); | |||||
| } | |||||
| Pattern[] incl = other.getIncludePatterns2(p); | |||||
| if (incl != null) { | |||||
| for (int i=0; i<incl.length; i++) { | |||||
| NameEntry ne = createInclude(); | |||||
| ne.setName(incl[i].getPattern()); | |||||
| ne.setSelectorList(incl[i].getSelectorList()); | |||||
| } | |||||
| } | |||||
| Pattern[] excl = other.getExcludePatterns2(p); | |||||
| if (excl != null) { | |||||
| for (int i=0; i<excl.length; i++) { | |||||
| NameEntry ne = createExclude(); | |||||
| ne.setName(excl[i].getPattern()); | |||||
| ne.setSelectorList(incl[i].getSelectorList()); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Adds the patterns of the other instance to this set. | |||||
| */ | |||||
| public void append(PatternSet other, Project p) { | |||||
| 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]); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Returns the filtered include patterns as an array of Patterns | |||||
| */ | |||||
| public Pattern[] getIncludePatterns2(Project p) { | |||||
| if (isReference()) { | |||||
| return getRef(p).getIncludePatterns2(p); | |||||
| } else { | |||||
| readFiles(p); | |||||
| return makeArray2(includeList, p); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Returns the filtered exclude patterns as an array of Patterns | |||||
| */ | |||||
| public Pattern[] getExcludePatterns2(Project p) { | |||||
| if (isReference()) { | |||||
| return getRef(p).getExcludePatterns2(p); | |||||
| } else { | |||||
| readFiles(p); | |||||
| return makeArray2(excludeList, p); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Returns the filtered include patterns. | |||||
| */ | |||||
| public String[] getIncludePatterns(Project p) { | |||||
| if (isReference()) { | |||||
| return getRef(p).getIncludePatterns(p); | |||||
| } else { | |||||
| readFiles(p); | |||||
| return makeArray(includeList, p); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Returns the filtered include patterns. | |||||
| */ | |||||
| public String[] getExcludePatterns(Project p) { | |||||
| if (isReference()) { | |||||
| return getRef(p).getExcludePatterns(p); | |||||
| } else { | |||||
| readFiles(p); | |||||
| return makeArray(excludeList, p); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * helper for FileSet. | |||||
| */ | |||||
| boolean hasPatterns() { | |||||
| return includesFileList.size() > 0 || excludesFileList.size() > 0 | |||||
| || includeList.size() > 0 || excludeList.size() > 0; | |||||
| } | |||||
| /** | |||||
| * Performs the check for circular references and returns the | |||||
| * referenced PatternSet. | |||||
| */ | |||||
| private PatternSet getRef(Project p) { | |||||
| if (!checked) { | |||||
| Stack stk = new Stack(); | |||||
| stk.push(this); | |||||
| dieOnCircularReference(stk, p); | |||||
| } | |||||
| Object o = ref.getReferencedObject(p); | |||||
| if (!(o instanceof PatternSet)) { | |||||
| String msg = ref.getRefId()+" doesn\'t denote a patternset"; | |||||
| throw new BuildException(msg); | |||||
| } else { | |||||
| return (PatternSet) o; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Convert a vector of NameEntry elements into an array of Patterns | |||||
| */ | |||||
| private Pattern[] makeArray2(Vector list, Project p) { | |||||
| if (list.size() == 0) return null; | |||||
| Vector tmpPatterns = 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) { | |||||
| Pattern pat = new Pattern(); | |||||
| pat.setPattern(pattern); | |||||
| pat.setSelectorList(ne.getSelectorList()); | |||||
| tmpPatterns.addElement(pat); | |||||
| } | |||||
| } | |||||
| Pattern result[] = new Pattern[tmpPatterns.size()]; | |||||
| tmpPatterns.copyInto(result); | |||||
| return result; | |||||
| } | |||||
| /** | |||||
| * Convert a vector of NameEntry elements into an array of Strings. | |||||
| */ | |||||
| private String[] makeArray(Vector list, Project p) { | |||||
| 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; | |||||
| } | |||||
| /** | |||||
| * Read includesfile ot excludesfile if not already done so. | |||||
| */ | |||||
| private void readFiles(Project p) { | |||||
| 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(); | |||||
| } | |||||
| } | |||||
| public String toString() | |||||
| { | |||||
| return "patternSet{ includes: " + includeList + | |||||
| " excludes: " + excludeList + " }"; | |||||
| } | |||||
| } | |||||
| @@ -1,139 +0,0 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.types; | |||||
| import org.apache.tools.ant.DirectoryScanner; | |||||
| import org.apache.tools.ant.types.Pattern; | |||||
| import java.io.File; | |||||
| /** | |||||
| * ZipScanner accesses the pattern matching algorithm in DirectoryScanner, | |||||
| * which are protected methods that can only be accessed by subclassing. | |||||
| * | |||||
| * This implementation of FileScanner defines getIncludedFiles to return | |||||
| * only the Zip File which is being scanned, not the matching Zip entries. | |||||
| * Arguably, it should return the matching entries, however this would | |||||
| * complicate existing code which assumes that FileScanners return a | |||||
| * set of file system files that can be accessed directly. | |||||
| * | |||||
| */ | |||||
| public class ZipScanner extends DirectoryScanner { | |||||
| /** | |||||
| * The zip file which should be scanned. | |||||
| */ | |||||
| protected File srcFile; | |||||
| /** | |||||
| * Sets the srcFile for scanning. This is the jar or zip file that is scanned | |||||
| * for matching entries. | |||||
| * | |||||
| * @param srcFile the (non-null) zip file name for scanning | |||||
| */ | |||||
| public void setSrc(File srcFile) { | |||||
| this.srcFile = srcFile; | |||||
| } | |||||
| /** | |||||
| * Returns the zip file itself, not the matching entries within the zip file. | |||||
| * This keeps the uptodate test in the Zip task simple; otherwise we'd need | |||||
| * to treat zip filesets specially. | |||||
| * | |||||
| * @return the source file from which entries will be extracted. | |||||
| */ | |||||
| public String[] getIncludedFiles() { | |||||
| String[] result = new String[1]; | |||||
| result[0] = srcFile.getAbsolutePath(); | |||||
| return result; | |||||
| } | |||||
| /** | |||||
| * Returns an empty list of directories to create. | |||||
| */ | |||||
| public String[] getIncludedDirectories() { | |||||
| return new String[0]; | |||||
| } | |||||
| /** | |||||
| * Initialize DirectoryScanner data structures. | |||||
| */ | |||||
| public void init() { | |||||
| if (includes == null) { | |||||
| // No includes supplied, so set it to 'matches all' | |||||
| includes = new Pattern[1]; | |||||
| includes[0] = new Pattern(); | |||||
| includes[0].setPattern("**"); | |||||
| } | |||||
| if (excludes == null) { | |||||
| excludes = new Pattern[0]; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Matches a jar entry against the includes/excludes list, | |||||
| * normalizing the path separator. | |||||
| * | |||||
| * @param path the (non-null) path name to test for inclusion | |||||
| * | |||||
| * @return <code>true</code> if the path should be included | |||||
| * <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean match(String path) { | |||||
| String vpath = path.replace('/', File.separatorChar). | |||||
| replace('\\', File.separatorChar); | |||||
| return isIncluded(vpath) && !isExcluded(vpath); | |||||
| } | |||||
| } | |||||