[MSHARED-61] Base directory of file set is not excluded from deletion if it contains excluded paths
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@692879 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java b/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
index 578aa3d..84a2386 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
@@ -552,6 +552,22 @@
parentPath = new File( parentPath ).getParent();
}
}
+
+ if ( excludedPaths.length > 0 )
+ {
+ if ( messages != null && messages.isDebugEnabled() )
+ {
+ messages.addDebugMessage( "Verifying path " + "."
+ + " is not present; contains file which is excluded." ).flush();
+ }
+
+ boolean removed = deletablePaths.remove( "" );
+
+ if ( removed && messages != null && messages.isDebugEnabled() )
+ {
+ messages.addDebugMessage( "Path " + "." + " was removed from delete list." ).flush();
+ }
+ }
}
/**
diff --git a/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java b/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
index 1b8b0c1..80f6f74 100644
--- a/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
@@ -196,6 +196,46 @@
}
/**
+ * @throws Exception if any
+ */
+ public void testDeleteExcludeParentOfExcludedFile()
+ throws Exception
+ {
+ File directory = setupTestDirectory( "testDeleteExcludeParentOfExcludedFile" );
+
+ FileSet set = new FileSet();
+ set.setDirectory( directory.getPath() );
+ set.addExclude( "*excluded*" );
+ set.setFollowSymlinks( true );
+
+ FileSetManager fileSetManager = new FileSetManager();
+
+ fileSetManager.delete( set );
+
+ Assert.assertTrue( "excluded file has been deleted", new File( directory, "excluded.txt" ).exists() );
+ }
+
+ /**
+ * @throws Exception if any
+ */
+ public void testDeleteExcludeParentOfExcludedDir()
+ throws Exception
+ {
+ File directory = setupTestDirectory( "testDeleteExcludeParentOfExcludedDir" );
+
+ FileSet set = new FileSet();
+ set.setDirectory( directory.getPath() );
+ set.addExclude( "*excluded*" );
+ set.setFollowSymlinks( true );
+
+ FileSetManager fileSetManager = new FileSetManager();
+
+ fileSetManager.delete( set );
+
+ Assert.assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
+ }
+
+ /**
* @param from
* @param to
* @return
diff --git a/src/test/resources/testDeleteExcludeParentOfExcludedDir/excluded/dummy.txt b/src/test/resources/testDeleteExcludeParentOfExcludedDir/excluded/dummy.txt
new file mode 100644
index 0000000..b083ccd
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeParentOfExcludedDir/excluded/dummy.txt
@@ -0,0 +1 @@
+Empty directories are apparently excluded by the Resources Plugin, so we use this little dummy file as a workaround.
\ No newline at end of file
diff --git a/src/test/resources/testDeleteExcludeParentOfExcludedFile/excluded.txt b/src/test/resources/testDeleteExcludeParentOfExcludedFile/excluded.txt
new file mode 100644
index 0000000..97ade0b
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeParentOfExcludedFile/excluded.txt
@@ -0,0 +1 @@
+Excluded File
\ No newline at end of file