PR: 12700 Submitted by: Gus Heck <gus dot heck at olin dot edu> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274554 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -302,6 +302,9 @@ Other changes: | |||
| in <vajload> by using special wildcard characters. Also fixes | |||
| Bugzilla Report 2236. | |||
| * Users can now modify the list of default excludes using the new | |||
| defaultexcludes task. Bugzilla Report 12700. | |||
| Changes from Ant 1.5.2 to Ant 1.5.3 | |||
| =================================== | |||
| @@ -0,0 +1,73 @@ | |||
| <html> | |||
| <head> | |||
| <meta http-equiv="Content-Language" content="en-us"> | |||
| <title>DefaultExcludes Task</title> | |||
| </head> | |||
| <body> | |||
| <h2><a name="echo">DefaultExcludes</a></h2> | |||
| <p><em>since Ant 1.6</em></p> | |||
| <h3>Description</h3> | |||
| <p>Alters the default excludes for all subsequent processing in the | |||
| build, and prints out the current default excludes if desired. | |||
| <h3>Parameters</h3> | |||
| <table border="1" cellpadding="2" cellspacing="0"> | |||
| <tr> | |||
| <td valign="top"><b>Attribute</b></td> | |||
| <td valign="top"><b>Description</b></td> | |||
| <td align="center" valign="top"><b>Required</b></td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">echo</td> | |||
| <td valign="top">whether or not to print out the default excludes.(defaults to false)</td> | |||
| <td valign="top" align="center">atribute "true" required if no | |||
| other argument specified</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">add</td> | |||
| <td valign="top">the pattern to add to the default excludes</td> | |||
| <td valign="top" align="center">if no other atribute is specified</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">remove</td> | |||
| <td valign="top">remove the specified pattern from the default excludes</td> | |||
| <td valign="top" align="center">if no other atribute is specified</td> | |||
| </tr> | |||
| </table> | |||
| <h3>Examples</h3> | |||
| <p>Print out the default excludes</p> | |||
| <pre> <defaultexcludes echo="true"/></pre> | |||
| <p>Print out the default excludes and exclude all *.bak files in | |||
| <strong>all</strong> further processing</p> | |||
| <pre> <defaultexcludes echo="true" add="**/*.bak"/></pre> | |||
| <p>Silently allow several fileset based tasks to operate on emacs | |||
| backup files and then restore normal behavior</p> | |||
| <pre> | |||
| <defaultexcludes remove="**/*~"/> | |||
| (do several fileset based tasks here) | |||
| <defaultexcludes add="**/*~"/> | |||
| </pre> | |||
| <hr> | |||
| <p align="center">Copyright © 2003 Apache Software Foundation. All rights | |||
| Reserved.</p> | |||
| </body> | |||
| </html> | |||
| @@ -36,6 +36,7 @@ | |||
| <a href="CoreTasks/changelog.html">CvsChangeLog</a><br> | |||
| <a href="CoreTasks/cvspass.html">CVSPass</a><br> | |||
| <a href="CoreTasks/cvstagdiff.html">CvsTagDiff</a><br> | |||
| <a href="CoreTasks/defaultexcludes.html">Defaultexcludes</a><br> | |||
| <a href="CoreTasks/delete.html">Delete</a><br> | |||
| <a href="CoreTasks/deltree.html"><i>Deltree</i></a><br> | |||
| <a href="CoreTasks/dependset.html">Dependset</a><br> | |||
| @@ -261,8 +261,14 @@ directory-based tasks. They are:</p> | |||
| **/.svn/** | |||
| **/.DS_Store | |||
| </pre> | |||
| <p>If you do not want these default excludes applied, you may disable them | |||
| with the <code>defaultexcludes="no"</code> attribute.</p> | |||
| <p>If you do not want these default excludes applied, you may disable | |||
| them with the <code>defaultexcludes="no"</code> | |||
| attribute.</p> | |||
| <p>This is the default list, note that you can modify the list of | |||
| default excludes by using the <a | |||
| href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p> | |||
| <hr> | |||
| <p align="center">Copyright © 2000-2003 Apache Software Foundation. All | |||
| rights Reserved.</p> | |||
| @@ -0,0 +1,19 @@ | |||
| <?xml version="1.0"?> | |||
| <project name="echo-test" basedir="." default="test1"> | |||
| <target name="test1"> | |||
| <defaultexcludes echo="true"/> | |||
| </target> | |||
| <target name="test2"> | |||
| <defaultexcludes add="foo" echo="true"/> | |||
| <defaultexcludes remove="foo" echo="false"/> | |||
| </target> | |||
| <target name="test3"> | |||
| <defaultexcludes remove="**/CVS" echo="true"/> | |||
| <defaultexcludes add="**/CVS" echo="false"/> | |||
| </target> | |||
| </project> | |||
| @@ -155,38 +155,34 @@ import org.apache.tools.ant.util.FileUtils; | |||
| public class DirectoryScanner | |||
| implements FileScanner, SelectorScanner, ResourceFactory { | |||
| /** | |||
| * Patterns which should be excluded by default. | |||
| * | |||
| * @see #addDefaultExcludes() | |||
| */ | |||
| protected static final String[] DEFAULTEXCLUDES = { | |||
| // Miscellaneous typical temporary files | |||
| "**/*~", | |||
| "**/#*#", | |||
| "**/.#*", | |||
| "**/%*%", | |||
| "**/._*", | |||
| private static Vector defaultExcludes = new Vector(); | |||
| // CVS | |||
| "**/CVS", | |||
| "**/CVS/**", | |||
| "**/.cvsignore", | |||
| static { | |||
| defaultExcludes.add("**/*~"); | |||
| defaultExcludes.add("**/#*#"); | |||
| defaultExcludes.add("**/.#*"); | |||
| defaultExcludes.add("**/%*%"); | |||
| defaultExcludes.add("**/._*"); | |||
| // SCCS | |||
| "**/SCCS", | |||
| "**/SCCS/**", | |||
| defaultExcludes.add("**/CVS"); | |||
| defaultExcludes.add("**/CVS/**"); | |||
| defaultExcludes.add("**/.cvsignore"); | |||
| // Visual SourceSafe | |||
| "**/vssver.scc", | |||
| defaultExcludes.add("**/SCCS"); | |||
| defaultExcludes.add("**/SCCS/**"); | |||
| // Subversion | |||
| "**/.svn", | |||
| "**/.svn/**", | |||
| defaultExcludes.add("**/vssver.scc"); | |||
| // Mac | |||
| "**/.DS_Store" | |||
| }; | |||
| defaultExcludes.add("**/.svn"); | |||
| defaultExcludes.add("**/.svn/**"); | |||
| defaultExcludes.add("**/.DS_Store"); | |||
| } | |||
| /** The base directory to be scanned. */ | |||
| protected File basedir; | |||
| @@ -381,6 +377,48 @@ public class DirectoryScanner | |||
| return SelectorUtils.match(pattern, str, isCaseSensitive); | |||
| } | |||
| /** | |||
| * Get the list of patterns that should be excluded by default. | |||
| * | |||
| * @return An array of <code>String</code> based on the current | |||
| * contents of the <code>defaultExcludes</code> | |||
| * <code>Vector</code>. | |||
| */ | |||
| public static String[] getDefaultExcludes() { | |||
| return (String[]) defaultExcludes.toArray(new String[defaultExcludes.size()]); | |||
| } | |||
| /** | |||
| * Add a pattern to the default excludes unless it is already a | |||
| * default exclude. | |||
| * | |||
| * @param s A string to add as an exclude pattern. | |||
| * @return <code>true</code> if the string was added | |||
| * <code>false</code> if it already | |||
| * existed. | |||
| */ | |||
| public static boolean addDefaultExclude(String s){ | |||
| if (defaultExcludes.indexOf(s) == -1) { | |||
| defaultExcludes.add(s); | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| /** | |||
| * Remove a string if it is a default exclude. | |||
| * | |||
| * @param s The string to attempt to remove. | |||
| * @return <code>true</code> if <code>s</code> was a default | |||
| * exclude (and thus was removed), | |||
| * <code>false</code> if <code>s</code> was not | |||
| * in the default excludes list to begin with | |||
| */ | |||
| public static boolean removeDefaultExclude(String s) { | |||
| return defaultExcludes.remove(s); | |||
| } | |||
| /** | |||
| * Sets the base directory to be scanned. This is the directory which is | |||
| * scanned recursively. All '/' and '\' characters are replaced by | |||
| @@ -938,13 +976,15 @@ public class DirectoryScanner | |||
| public void addDefaultExcludes() { | |||
| int excludesLength = excludes == null ? 0 : excludes.length; | |||
| String[] newExcludes; | |||
| newExcludes = new String[excludesLength + DEFAULTEXCLUDES.length]; | |||
| newExcludes = new String[excludesLength + defaultExcludes.size()]; | |||
| if (excludesLength > 0) { | |||
| System.arraycopy(excludes, 0, newExcludes, 0, excludesLength); | |||
| } | |||
| for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { | |||
| newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i].replace('/', | |||
| File.separatorChar).replace('\\', File.separatorChar); | |||
| String[] defaultExcludesTemp = getDefaultExcludes(); | |||
| for (int i = 0; i < defaultExcludesTemp.length; i++) { | |||
| newExcludes[i + excludesLength] = defaultExcludesTemp[i]. | |||
| replace('/', File.separatorChar). | |||
| replace('\\', File.separatorChar); | |||
| } | |||
| excludes = newExcludes; | |||
| } | |||
| @@ -0,0 +1,139 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2003 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 "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.taskdefs; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| /** | |||
| * Alters the default excludes for the <strong>entire</strong> build.. | |||
| * | |||
| * @author Gus Heck <gus.heck@olin.edu> | |||
| * | |||
| * @since Ant 1.6 | |||
| * | |||
| * @ant.task category="utility" | |||
| */ | |||
| public class DefaultExcludes extends Task { | |||
| private String add = ""; | |||
| private String remove = ""; | |||
| private boolean echo = false; | |||
| // by default, messages are always displayed | |||
| private int logLevel = Project.MSG_WARN; | |||
| /** | |||
| * Does the work. | |||
| * | |||
| * @exception BuildException if someting goes wrong with the build | |||
| */ | |||
| public void execute() throws BuildException { | |||
| if (add.equals("") && remove.equals("") && (echo == false)) { | |||
| throw new BuildException("<defaultexcludes> task must set "+ | |||
| "at least one atribute (echo=\"false\""+ | |||
| " doesn't count since that is the "+ | |||
| "default"); | |||
| } | |||
| if (!add.equals("")) { | |||
| DirectoryScanner.addDefaultExclude(add); | |||
| } | |||
| if (!remove.equals("")) { | |||
| DirectoryScanner.removeDefaultExclude(remove); | |||
| } | |||
| if (echo == true) { | |||
| StringBuffer message = new StringBuffer("Current Default "+ | |||
| "Excludes:\n"); | |||
| String[] excludes = DirectoryScanner.getDefaultExcludes(); | |||
| for (int i=0;i<excludes.length;i++) { | |||
| message.append(" " + excludes[i] + "\n"); | |||
| } | |||
| log(message.toString(), logLevel); | |||
| } | |||
| } | |||
| /** | |||
| * Pattern to add to the default excludes | |||
| * | |||
| * @param add Sets the value for the pattern to exclude. | |||
| */ | |||
| public void setAdd(String add) { | |||
| this.add = add; | |||
| } | |||
| /** | |||
| * Pattern to remove from the default excludes. | |||
| * | |||
| * @param msg Sets the value for the pattern that | |||
| * should nolonger be excluded. | |||
| */ | |||
| public void setRemove(String remove) { | |||
| this.remove = remove; | |||
| } | |||
| /** | |||
| * If true, echo the default excludes. | |||
| * | |||
| * @param echo whether or not to echo the contents of | |||
| * the default excludes. | |||
| */ | |||
| public void setEcho(boolean echo) { | |||
| this.echo = echo; | |||
| } | |||
| } | |||
| @@ -75,6 +75,7 @@ import=org.apache.tools.ant.taskdefs.ImportTask | |||
| whichresource=org.apache.tools.ant.taskdefs.WhichResource | |||
| subant=org.apache.tools.ant.taskdefs.SubAnt | |||
| sync=org.apache.tools.ant.taskdefs.Sync | |||
| defaultexcludes=org.apache.tools.ant.taskdefs.DefaultExcludes | |||
| # optional tasks | |||
| image=org.apache.tools.ant.taskdefs.optional.image.Image | |||
| @@ -0,0 +1,129 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2003 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 "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.taskdefs; | |||
| import org.apache.tools.ant.BuildFileTest; | |||
| /** | |||
| * @author Gus Heck <gus.heck@olin.edu> | |||
| */ | |||
| public class DefaultExcludesTest extends BuildFileTest { | |||
| public DefaultExcludesTest(String name) { | |||
| super(name); | |||
| } | |||
| public void setUp() { | |||
| configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml"); | |||
| } | |||
| // Output the default excludes | |||
| public void test1() { | |||
| expectLog("test1", "Current Default Excludes:\n"+ | |||
| " **/*~\n"+ | |||
| " **/#*#\n"+ | |||
| " **/.#*\n"+ | |||
| " **/%*%\n"+ | |||
| " **/._*\n"+ | |||
| " **/CVS\n"+ | |||
| " **/CVS/**\n"+ | |||
| " **/.cvsignore\n"+ | |||
| " **/SCCS\n"+ | |||
| " **/SCCS/**\n"+ | |||
| " **/vssver.scc\n"+ | |||
| " **/.svn\n"+ | |||
| " **/.svn/**\n"+ | |||
| " **/.DS_Store\n"); | |||
| } | |||
| // adding something to the excludes' | |||
| public void test2() { | |||
| expectLog("test2", "Current Default Excludes:\n"+ | |||
| " **/*~\n"+ | |||
| " **/#*#\n"+ | |||
| " **/.#*\n"+ | |||
| " **/%*%\n"+ | |||
| " **/._*\n"+ | |||
| " **/CVS\n"+ | |||
| " **/CVS/**\n"+ | |||
| " **/.cvsignore\n"+ | |||
| " **/SCCS\n"+ | |||
| " **/SCCS/**\n"+ | |||
| " **/vssver.scc\n"+ | |||
| " **/.svn\n"+ | |||
| " **/.svn/**\n"+ | |||
| " **/.DS_Store\n"+ | |||
| " foo\n"); // foo added | |||
| } | |||
| // removing something from the defaults | |||
| public void test3() { | |||
| expectLog("test3", "Current Default Excludes:\n"+ | |||
| " **/*~\n"+ | |||
| " **/#*#\n"+ | |||
| " **/.#*\n"+ | |||
| " **/%*%\n"+ | |||
| " **/._*\n"+ | |||
| //CVS missing | |||
| " **/CVS/**\n"+ | |||
| " **/.cvsignore\n"+ | |||
| " **/SCCS\n"+ | |||
| " **/SCCS/**\n"+ | |||
| " **/vssver.scc\n"+ | |||
| " **/.svn\n"+ | |||
| " **/.svn/**\n"+ | |||
| " **/.DS_Store\n"); | |||
| } | |||
| } | |||