[MSHARED-62] Excludes are ignored for deletion if followSymlinks=false
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@693981 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 84a2386..8043bd2 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
@@ -427,7 +427,7 @@
.addInfoMessage( "Adding symbolic link dirs which were previously excluded to the list being deleted." ).flush();
}
- // we need to see which entries were excluded because they're symlinks...
+ // we need to see which entries were only excluded because they're symlinks...
scanner.setFollowSymlinks( true );
scanner.scan();
@@ -437,17 +437,17 @@
messages.addDebugMessage( "Marked for preserve (with followSymlinks == false): " + excludes ).flush();
}
- List notSymlinks = Arrays.asList( scanner.getIncludedDirectories() );
+ List includedDirsAndSymlinks = Arrays.asList( scanner.getIncludedDirectories() );
linksForDeletion.addAll( excludes );
- linksForDeletion.retainAll( notSymlinks );
+ linksForDeletion.retainAll( includedDirsAndSymlinks );
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Symlinks marked for deletion (originally mismarked): " + linksForDeletion ).flush();
}
- excludes.removeAll( notSymlinks );
+ excludes.removeAll( includedDirsAndSymlinks );
}
excludeParentDirectoriesOfExcludedPaths( excludedDirs, includes );
@@ -487,7 +487,7 @@
.addInfoMessage( "Adding symbolic link files which were previously excluded to the list being deleted." ).flush();
}
- // we need to see which entries were excluded because they're symlinks...
+ // we need to see which entries were only excluded because they're symlinks...
scanner.setFollowSymlinks( true );
scanner.scan();
@@ -497,17 +497,17 @@
messages.addDebugMessage( "Marked for preserve (with followSymlinks == false): " + excludes ).flush();
}
- List notSymlinks = Arrays.asList( scanner.getExcludedFiles() );
+ List includedFilesAndSymlinks = Arrays.asList( scanner.getIncludedFiles() );
linksForDeletion.addAll( excludes );
- linksForDeletion.retainAll( notSymlinks );
+ linksForDeletion.retainAll( includedFilesAndSymlinks );
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Symlinks marked for deletion (originally mismarked): " + linksForDeletion ).flush();
}
- excludes.removeAll( notSymlinks );
+ excludes.removeAll( includedFilesAndSymlinks );
}
excludeParentDirectoriesOfExcludedPaths( excludedFiles, includes );
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 80f6f74..9de6001 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
@@ -236,6 +236,50 @@
}
/**
+ * @throws Exception if any
+ */
+ public void testDeleteExcludeFollowSymlinks()
+ throws Exception
+ {
+ File directory = setupTestDirectory( "testDeleteExcludeFollowSymlinks" );
+
+ 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() );
+ Assert.assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
+ Assert.assertFalse( "included file has not been deleted", new File( directory, "included.txt" ).exists() );
+ }
+
+ /**
+ * @throws Exception if any
+ */
+ public void testDeleteExcludeDontFollowSymlinks()
+ throws Exception
+ {
+ File directory = setupTestDirectory( "testDeleteExcludeDontFollowSymlinks" );
+
+ FileSet set = new FileSet();
+ set.setDirectory( directory.getPath() );
+ set.addExclude( "*excluded*" );
+ set.setFollowSymlinks( false );
+
+ FileSetManager fileSetManager = new FileSetManager();
+
+ fileSetManager.delete( set );
+
+ Assert.assertTrue( "excluded file has been deleted", new File( directory, "excluded.txt" ).exists() );
+ Assert.assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
+ Assert.assertFalse( "included file has not been deleted", new File( directory, "included.txt" ).exists() );
+ }
+
+ /**
* @param from
* @param to
* @return
diff --git a/src/test/resources/testDeleteExcludeDontFollowSymlinks/excluded.txt b/src/test/resources/testDeleteExcludeDontFollowSymlinks/excluded.txt
new file mode 100644
index 0000000..6233267
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeDontFollowSymlinks/excluded.txt
@@ -0,0 +1 @@
+Should not be deleted.
\ No newline at end of file
diff --git a/src/test/resources/testDeleteExcludeDontFollowSymlinks/excluded/dummy.txt b/src/test/resources/testDeleteExcludeDontFollowSymlinks/excluded/dummy.txt
new file mode 100644
index 0000000..b93cdcf
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeDontFollowSymlinks/excluded/dummy.txt
@@ -0,0 +1 @@
+The Resources Plugin won't copy empty directories...
\ No newline at end of file
diff --git a/src/test/resources/testDeleteExcludeDontFollowSymlinks/included.txt b/src/test/resources/testDeleteExcludeDontFollowSymlinks/included.txt
new file mode 100644
index 0000000..2587ca1
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeDontFollowSymlinks/included.txt
@@ -0,0 +1 @@
+Should be deleted.
\ No newline at end of file
diff --git a/src/test/resources/testDeleteExcludeFollowSymlinks/excluded.txt b/src/test/resources/testDeleteExcludeFollowSymlinks/excluded.txt
new file mode 100644
index 0000000..6233267
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeFollowSymlinks/excluded.txt
@@ -0,0 +1 @@
+Should not be deleted.
\ No newline at end of file
diff --git a/src/test/resources/testDeleteExcludeFollowSymlinks/excluded/dummy.txt b/src/test/resources/testDeleteExcludeFollowSymlinks/excluded/dummy.txt
new file mode 100644
index 0000000..b93cdcf
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeFollowSymlinks/excluded/dummy.txt
@@ -0,0 +1 @@
+The Resources Plugin won't copy empty directories...
\ No newline at end of file
diff --git a/src/test/resources/testDeleteExcludeFollowSymlinks/included.txt b/src/test/resources/testDeleteExcludeFollowSymlinks/included.txt
new file mode 100644
index 0000000..2587ca1
--- /dev/null
+++ b/src/test/resources/testDeleteExcludeFollowSymlinks/included.txt
@@ -0,0 +1 @@
+Should be deleted.
\ No newline at end of file