From f1bc629e34874c4d641b159e31a55ed2cab6ca20 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 9 May 2003 12:10:36 +0000 Subject: [PATCH] A new task that allows users to modify the list of default excludes. PR: 12700 Submitted by: Gus Heck git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274554 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 + docs/manual/CoreTasks/defaultexcludes.html | 73 +++++++++ docs/manual/coretasklist.html | 1 + docs/manual/dirtasks.html | 10 +- .../testcases/taskdefs/defaultexcludes.xml | 19 +++ .../apache/tools/ant/DirectoryScanner.java | 92 ++++++++---- .../tools/ant/taskdefs/DefaultExcludes.java | 139 ++++++++++++++++++ .../tools/ant/taskdefs/defaults.properties | 1 + .../ant/taskdefs/DefaultExcludesTest.java | 129 ++++++++++++++++ 9 files changed, 439 insertions(+), 28 deletions(-) create mode 100644 docs/manual/CoreTasks/defaultexcludes.html create mode 100644 src/etc/testcases/taskdefs/defaultexcludes.xml create mode 100644 src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java create mode 100644 src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java diff --git a/WHATSNEW b/WHATSNEW index 6a47bc8e2..eae9c772a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -302,6 +302,9 @@ Other changes: in 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 =================================== diff --git a/docs/manual/CoreTasks/defaultexcludes.html b/docs/manual/CoreTasks/defaultexcludes.html new file mode 100644 index 000000000..930426d8e --- /dev/null +++ b/docs/manual/CoreTasks/defaultexcludes.html @@ -0,0 +1,73 @@ + + + + +DefaultExcludes Task + + + + +

DefaultExcludes

+ +

since Ant 1.6

+ +

Description

+

Alters the default excludes for all subsequent processing in the +build, and prints out the current default excludes if desired. + +

Parameters

+ + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
echowhether or not to print out the default excludes.(defaults to false)atribute "true" required if no + other argument specified
addthe pattern to add to the default excludesif no other atribute is specified
removeremove the specified pattern from the default excludesif no other atribute is specified
+ +

Examples

+ +

Print out the default excludes

+ +
  <defaultexcludes echo="true"/>
+ +

Print out the default excludes and exclude all *.bak files in +all further processing

+ +
  <defaultexcludes echo="true" add="**/*.bak"/>
+ +

Silently allow several fileset based tasks to operate on emacs +backup files and then restore normal behavior

+ +
+  <defaultexcludes remove="**/*~"/>
+
+  (do several fileset based tasks here)
+
+  <defaultexcludes add="**/*~"/>
+
+ + +
+ +

Copyright © 2003 Apache Software Foundation. All rights +Reserved.

+ + + + diff --git a/docs/manual/coretasklist.html b/docs/manual/coretasklist.html index b665c0c6f..d17f4f9e5 100644 --- a/docs/manual/coretasklist.html +++ b/docs/manual/coretasklist.html @@ -36,6 +36,7 @@ CvsChangeLog
CVSPass
CvsTagDiff
+Defaultexcludes
Delete
Deltree
Dependset
diff --git a/docs/manual/dirtasks.html b/docs/manual/dirtasks.html index 997f311db..b73e1c2aa 100644 --- a/docs/manual/dirtasks.html +++ b/docs/manual/dirtasks.html @@ -261,8 +261,14 @@ directory-based tasks. They are:

**/.svn/** **/.DS_Store -

If you do not want these default excludes applied, you may disable them -with the defaultexcludes="no" attribute.

+

If you do not want these default excludes applied, you may disable +them with the defaultexcludes="no" +attribute.

+ +

This is the default list, note that you can modify the list of +default excludes by using the defaultexcludes task.

+

Copyright © 2000-2003 Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/defaultexcludes.xml b/src/etc/testcases/taskdefs/defaultexcludes.xml new file mode 100644 index 000000000..cf608e851 --- /dev/null +++ b/src/etc/testcases/taskdefs/defaultexcludes.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/DirectoryScanner.java b/src/main/org/apache/tools/ant/DirectoryScanner.java index 2522924a4..6048263b1 100644 --- a/src/main/org/apache/tools/ant/DirectoryScanner.java +++ b/src/main/org/apache/tools/ant/DirectoryScanner.java @@ -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 String based on the current + * contents of the defaultExcludes + * Vector. + */ + 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 true if the string was added + * false 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 true if s was a default + * exclude (and thus was removed), + * false if s 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; } diff --git a/src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java b/src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java new file mode 100644 index 000000000..f7131d1e0 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java @@ -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 + * . + */ + +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 entire 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(" 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. + */ + +package org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileTest; + +/** + * @author Gus Heck + */ +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"); + } +}