Index: src/test/java/org/apache/maven/plugin/clean/CleanMojoTest.java
===================================================================
--- src/test/java/org/apache/maven/plugin/clean/CleanMojoTest.java (revision 696145)
+++ src/test/java/org/apache/maven/plugin/clean/CleanMojoTest.java (working copy)
@@ -103,6 +103,32 @@
}
/**
+ * Tests the removal and preservation of files in includes and excludes global filters.
+ *
+ * @throws Exception
+ */
+ public void testCleanWithGlobalFilters()
+ throws Exception
+ {
+ String pluginPom = getBasedir() + "/src/test/resources/unit/global-filter-test/plugin-pom.xml";
+
+ // safety
+ FileUtils.copyDirectory( new File( getBasedir(), "src/test/resources/unit/global-filter-test" ),
+ new File( getBasedir(), "target/test-classes/unit/global-filter-test" ), null, "**/.svn,**/.svn/**" );
+
+ CleanMojo mojo = (CleanMojo) lookupMojo( "clean", pluginPom );
+ assertNotNull( mojo );
+
+ mojo.execute();
+
+ assertTrue( checkExists( getBasedir() + "/target/test-classes/unit/global-filter-test/target" ) );
+ assertTrue( checkExists( getBasedir() + "/target/test-classes/unit/global-filter-test/target/subdir/exclude.txt" ) );
+ assertFalse( checkExists( getBasedir() + "/target/test-classes/unit/global-filter-test/target/subdir/include.txt" ) );
+ assertFalse( checkExists( getBasedir() + "/target/test-classes/unit/global-filter-test/target/test-classes" ) );
+ assertFalse( checkExists( getBasedir() + "/target/test-classes/unit/global-filter-test/target/classes" ) );
+ }
+
+ /**
* Tests that no exception is thrown when all internal variables are empty and that it doesn't
* just remove whats there
*
Index: src/test/resources/unit/global-filter-test/plugin-pom.xml
===================================================================
--- src/test/resources/unit/global-filter-test/plugin-pom.xml (revision 0)
+++ src/test/resources/unit/global-filter-test/plugin-pom.xml (revision 0)
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+ maven-clean-plugin
+
+
+ ${basedir}/target/test-classes/unit/global-filter-test/target
+ ${basedir}/target/test-classes/unit/global-filter-test/target/classes
+ ${basedir}/target/test-classes/unit/global-filter-test/target/test-classes
+ **/*.txt,test-classes,classes,subdir
+ **/exclude.*
+ true
+ true
+
+
+
+
+
Index: src/test/resources/unit/global-filter-test/target/subdir/include.txt
===================================================================
Index: src/test/resources/unit/global-filter-test/target/subdir/exclude.txt
===================================================================
Index: src/test/resources/unit/global-filter-test/target/test-classes/file.txt
===================================================================
Index: src/test/resources/unit/global-filter-test/target/classes/file.txt
===================================================================
Index: src/test/resources/unit/global-filter-test/target/file.txt
===================================================================
Index: src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/clean/CleanMojo.java (revision 696145)
+++ src/main/java/org/apache/maven/plugin/clean/CleanMojo.java (working copy)
@@ -101,6 +101,23 @@
private File reportDirectory;
/**
+ * The comma-delimited includes patterns to use when deleting the default directory locations.
+ *
+ * @parameter expression="${maven.clean.includes}"
+ * @since 2.3
+ */
+ private String includes = "**";
+
+
+ /**
+ * The comma-delimited excludes patterns to use when deleting the default directory locations.
+ *
+ * @parameter expression="${maven.clean.excludes}"
+ * @since 2.3
+ */
+ private String excludes;
+
+ /**
* Sets whether the plugin runs in verbose mode. As of plugin version 2.3, the default value is derived from Maven's
* global debug flag (compare command line switch -X).
*
@@ -242,13 +259,33 @@
{
FileSet fs = new Fileset();
fs.setDirectory( dir.getPath() );
- fs.addInclude( "**" );
+
+ addIncludesToFileSet(fs);
+ addExcludesToFileSet(fs);
+
fs.setFollowSymlinks( followSymLinks );
removeFileSet( fs );
}
}
+ private void addIncludesToFileSet(FileSet fs) {
+ final String[] include = includes.split(",");
+ for (int i = 0; i < include.length; i++) {
+ fs.addInclude( include[i] );
+ }
+ }
+
+ private void addExcludesToFileSet(FileSet fs) {
+ if (excludes == null) {
+ return;
+ }
+ final String[] exclude = excludes.split(",");
+ for (int i = 0; i < exclude.length; i++) {
+ fs.addExclude( exclude[i] );
+ }
+ }
+
/**
* Deletes the specified file set. If the base directory of the file set is relative, it will be resolved against
* the base directory of the current project.