Browse Source

Add a method in DirectoryScanner to reset the default exclude patterns

Add corresponding functionality in <defaultexcludes>
Update tests


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274877 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
5ac6359a7a
5 changed files with 102 additions and 62 deletions
  1. +11
    -5
      docs/manual/CoreTasks/defaultexcludes.html
  2. +2
    -4
      src/etc/testcases/taskdefs/defaultexcludes.xml
  3. +14
    -4
      src/main/org/apache/tools/ant/DirectoryScanner.java
  4. +14
    -3
      src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java
  5. +61
    -46
      src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java

+ 11
- 5
docs/manual/CoreTasks/defaultexcludes.html View File

@@ -25,18 +25,24 @@ build, and prints out the current default excludes if desired.
<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>
<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>
<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>
<td valign="top" align="center">if no other attribute 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>
<td valign="top" align="center">if no other attribute is specified</td>
</tr>
</table>

@@ -59,7 +65,7 @@ backup files and then restore normal behavior</p>

(do several fileset based tasks here)

&lt;defaultexcludes add=&quot;**/*~&quot;/&gt;
&lt;defaultexcludes default=&quot;true&quot;/&gt;
</pre>




+ 2
- 4
src/etc/testcases/taskdefs/defaultexcludes.xml View File

@@ -7,13 +7,11 @@
</target>

<target name="test2">
<defaultexcludes add="foo" echo="true"/>
<defaultexcludes remove="foo" echo="false"/>
<defaultexcludes default="true" add="foo" echo="true"/>
</target>

<target name="test3">
<defaultexcludes remove="**/CVS" echo="true"/>
<defaultexcludes add="**/CVS" echo="false"/>
<defaultexcludes default="true" remove="**/CVS" echo="true"/>
</target>

</project>

+ 14
- 4
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -205,11 +205,8 @@ public class DirectoryScanner
* @see #addDefaultExcludes()
*/
private static Vector defaultExcludes = new Vector();

static {
for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
defaultExcludes.add(DEFAULTEXCLUDES[i]);
}
resetDefaultExcludes();
}

/** The base directory to be scanned. */
@@ -454,6 +451,19 @@ public class DirectoryScanner
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
* scanned recursively. All '/' and '\' characters are replaced by


+ 14
- 3
src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java View File

@@ -71,7 +71,7 @@ import org.apache.tools.ant.DirectoryScanner;
public class DefaultExcludes extends Task {
private String add = "";
private String remove = "";
private boolean defaultrequested = false;
private boolean echo = false;

// by default, messages are always displayed
@@ -83,11 +83,14 @@ public class DefaultExcludes extends Task {
* @exception BuildException if someting goes wrong with the build
*/
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 "
+ "at least one atribute (echo=\"false\""
+ "at least one attribute (echo=\"false\""
+ " doesn't count since that is the default");
}
if (defaultrequested == true) {
DirectoryScanner.resetDefaultExcludes();
}
if (!add.equals("")) {
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
*


+ 61
- 46
src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java View File

@@ -55,6 +55,7 @@
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.DirectoryScanner;

/**
* @author Gus Heck <gus.heck@olin.edu>
@@ -71,59 +72,73 @@ public class DefaultExcludesTest extends BuildFileTest {

// 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");
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'
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
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]);
}

}
}

Loading…
Cancel
Save