Add corresponding functionality in <defaultexcludes> Update tests git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274877 13f79535-47bb-0310-9956-ffa450edef68master
@@ -25,18 +25,24 @@ build, and prints out the current default excludes if desired. | |||||
<tr> | <tr> | ||||
<td valign="top">echo</td> | <td valign="top">echo</td> | ||||
<td valign="top">whether or not to print out the default excludes.(defaults to false)</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> | |||||
<td valign="top" align="center">attribute "true" required if no | |||||
other attribute specified</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">default</td> | |||||
<td valign="top">go back to hard wired default excludes</td> | |||||
<td valign="top" align="center">attribute "true" required if no | |||||
if no other attribute is specified</td> | |||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
<td valign="top">add</td> | <td valign="top">add</td> | ||||
<td valign="top">the pattern to add to the default excludes</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> | |||||
<td valign="top" align="center">if no other attribute is specified</td> | |||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
<td valign="top">remove</td> | <td valign="top">remove</td> | ||||
<td valign="top">remove the specified pattern from the default excludes</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> | |||||
<td valign="top" align="center">if no other attribute is specified</td> | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
@@ -59,7 +65,7 @@ backup files and then restore normal behavior</p> | |||||
(do several fileset based tasks here) | (do several fileset based tasks here) | ||||
<defaultexcludes add="**/*~"/> | |||||
<defaultexcludes default="true"/> | |||||
</pre> | </pre> | ||||
@@ -7,13 +7,11 @@ | |||||
</target> | </target> | ||||
<target name="test2"> | <target name="test2"> | ||||
<defaultexcludes add="foo" echo="true"/> | |||||
<defaultexcludes remove="foo" echo="false"/> | |||||
<defaultexcludes default="true" add="foo" echo="true"/> | |||||
</target> | </target> | ||||
<target name="test3"> | <target name="test3"> | ||||
<defaultexcludes remove="**/CVS" echo="true"/> | |||||
<defaultexcludes add="**/CVS" echo="false"/> | |||||
<defaultexcludes default="true" remove="**/CVS" echo="true"/> | |||||
</target> | </target> | ||||
</project> | </project> |
@@ -205,11 +205,8 @@ public class DirectoryScanner | |||||
* @see #addDefaultExcludes() | * @see #addDefaultExcludes() | ||||
*/ | */ | ||||
private static Vector defaultExcludes = new Vector(); | private static Vector defaultExcludes = new Vector(); | ||||
static { | static { | ||||
for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { | |||||
defaultExcludes.add(DEFAULTEXCLUDES[i]); | |||||
} | |||||
resetDefaultExcludes(); | |||||
} | } | ||||
/** The base directory to be scanned. */ | /** The base directory to be scanned. */ | ||||
@@ -454,6 +451,19 @@ public class DirectoryScanner | |||||
return defaultExcludes.remove(s); | return defaultExcludes.remove(s); | ||||
} | } | ||||
/** | |||||
* Go back to the hard wired default exclude patterns | |||||
* | |||||
* @since Ant 1.6 | |||||
*/ | |||||
public static void resetDefaultExcludes() { | |||||
defaultExcludes = new Vector(); | |||||
for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { | |||||
defaultExcludes.add(DEFAULTEXCLUDES[i]); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Sets the base directory to be scanned. This is the directory which is | * Sets the base directory to be scanned. This is the directory which is | ||||
* scanned recursively. All '/' and '\' characters are replaced by | * scanned recursively. All '/' and '\' characters are replaced by | ||||
@@ -71,7 +71,7 @@ import org.apache.tools.ant.DirectoryScanner; | |||||
public class DefaultExcludes extends Task { | public class DefaultExcludes extends Task { | ||||
private String add = ""; | private String add = ""; | ||||
private String remove = ""; | private String remove = ""; | ||||
private boolean defaultrequested = false; | |||||
private boolean echo = false; | private boolean echo = false; | ||||
// by default, messages are always displayed | // by default, messages are always displayed | ||||
@@ -83,11 +83,14 @@ public class DefaultExcludes extends Task { | |||||
* @exception BuildException if someting goes wrong with the build | * @exception BuildException if someting goes wrong with the build | ||||
*/ | */ | ||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
if (add.equals("") && remove.equals("") && (echo == false)) { | |||||
if (defaultrequested == false && add.equals("") && remove.equals("") && (echo == false)) { | |||||
throw new BuildException("<defaultexcludes> task must set " | throw new BuildException("<defaultexcludes> task must set " | ||||
+ "at least one atribute (echo=\"false\"" | |||||
+ "at least one attribute (echo=\"false\"" | |||||
+ " doesn't count since that is the default"); | + " doesn't count since that is the default"); | ||||
} | } | ||||
if (defaultrequested == true) { | |||||
DirectoryScanner.resetDefaultExcludes(); | |||||
} | |||||
if (!add.equals("")) { | if (!add.equals("")) { | ||||
DirectoryScanner.addDefaultExclude(add); | DirectoryScanner.addDefaultExclude(add); | ||||
} | } | ||||
@@ -105,6 +108,14 @@ public class DefaultExcludes extends Task { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* go back to standard default patterns | |||||
* | |||||
* @param def if true go back to default patterns | |||||
*/ | |||||
public void setDefault(boolean def) { | |||||
defaultrequested = def; | |||||
} | |||||
/** | /** | ||||
* Pattern to add to the default excludes | * Pattern to add to the default excludes | ||||
* | * | ||||
@@ -55,6 +55,7 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import org.apache.tools.ant.BuildFileTest; | import org.apache.tools.ant.BuildFileTest; | ||||
import org.apache.tools.ant.DirectoryScanner; | |||||
/** | /** | ||||
* @author Gus Heck <gus.heck@olin.edu> | * @author Gus Heck <gus.heck@olin.edu> | ||||
@@ -71,59 +72,73 @@ public class DefaultExcludesTest extends BuildFileTest { | |||||
// Output the default excludes | // Output the default excludes | ||||
public void test1() { | 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"); | |||||
String[] expected = { | |||||
"**/*~", | |||||
"**/#*#", | |||||
"**/.#*", | |||||
"**/%*%", | |||||
"**/._*", | |||||
"**/CVS", | |||||
"**/CVS/**", | |||||
"**/.cvsignore", | |||||
"**/SCCS", | |||||
"**/SCCS/**", | |||||
"**/vssver.scc", | |||||
"**/.svn", | |||||
"**/.svn/**", | |||||
"**/.DS_Store"}; | |||||
project.executeTarget("test1"); | |||||
assertEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||||
} | } | ||||
// adding something to the excludes' | // adding something to the excludes' | ||||
public void test2() { | 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"); // foo added | |||||
String[] expected = { | |||||
"**/*~", | |||||
"**/#*#", | |||||
"**/.#*", | |||||
"**/%*%", | |||||
"**/._*", | |||||
"**/CVS", | |||||
"**/CVS/**", | |||||
"**/.cvsignore", | |||||
"**/SCCS", | |||||
"**/SCCS/**", | |||||
"**/vssver.scc", | |||||
"**/.svn", | |||||
"**/.svn/**", | |||||
"**/.DS_Store", | |||||
"foo"}; | |||||
project.executeTarget("test2"); | |||||
assertEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||||
} | } | ||||
// removing something from the defaults | // removing something from the defaults | ||||
public void test3() { | 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"); | |||||
String[] expected = { | |||||
"**/*~", | |||||
"**/#*#", | |||||
"**/.#*", | |||||
"**/%*%", | |||||
"**/._*", | |||||
//CVS missing | |||||
"**/CVS/**", | |||||
"**/.cvsignore", | |||||
"**/SCCS", | |||||
"**/SCCS/**", | |||||
"**/vssver.scc", | |||||
"**/.svn", | |||||
"**/.svn/**", | |||||
"**/.DS_Store"}; | |||||
project.executeTarget("test3"); | |||||
assertEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||||
} | |||||
private void assertEquals(String message, String[] expected, String[] actual) { | |||||
// check that both arrays have the same size | |||||
assertEquals(message + " : string array length match", expected.length, actual.length); | |||||
for (int counter=0; counter <expected.length; counter++) { | |||||
assertEquals(message + " : " + counter + "th element in array match", expected[counter], actual[counter]); | |||||
} | |||||
} | } | ||||
} | } |