maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r694311 - in /maven/shared/trunk/file-management/src: main/java/org/apache/maven/shared/model/fileset/util/ test/java/org/apache/maven/shared/model/fileset/util/ test/resources/testDeleteDontFollowSymlinksButDeleteThem/ test/resources/testD...
Date Thu, 11 Sep 2008 15:40:07 GMT
Author: bentmann
Date: Thu Sep 11 08:40:04 2008
New Revision: 694311

URL: http://svn.apache.org/viewvc?rev=694311&view=rev
Log:
[MSHARED-64] FileSetManager.delete() does not delete empty directories if they contained symlink
that was deleted

Added:
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt
  (with props)
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt
  (with props)
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt
  (with props)
    maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt
  (with props)
Modified:
    maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
    maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java

Modified: maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?rev=694311&r1=694310&r2=694311&view=diff
==============================================================================
--- maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
(original)
+++ maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
Thu Sep 11 08:40:04 2008
@@ -37,6 +37,7 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -450,7 +451,7 @@
             excludes.removeAll( includedDirsAndSymlinks );
         }
 
-        excludeParentDirectoriesOfExcludedPaths( excludedDirs, includes );
+        excludeParentDirectoriesOfExcludedPaths( excludes, includes );
 
         includes.addAll( linksForDeletion );
 
@@ -510,7 +511,7 @@
             excludes.removeAll( includedFilesAndSymlinks );
         }
 
-        excludeParentDirectoriesOfExcludedPaths( excludedFiles, includes );
+        excludeParentDirectoriesOfExcludedPaths( excludes, includes );
 
         includes.addAll( linksForDeletion );
 
@@ -526,11 +527,11 @@
      * @param deletablePaths The relative paths to files/directories which are scheduled
for deletion, must not be
      *            <code>null</code>.
      */
-    private void excludeParentDirectoriesOfExcludedPaths( String excludedPaths[], Set deletablePaths
)
+    private void excludeParentDirectoriesOfExcludedPaths( Collection excludedPaths, Set deletablePaths
)
     {
-        for ( int i = 0; i < excludedPaths.length; i++ )
+        for ( Iterator it = excludedPaths.iterator(); it.hasNext(); )
         {
-            String path = excludedPaths[i];
+            String path = (String) it.next();
 
             String parentPath = new File( path ).getParent();
 
@@ -553,7 +554,7 @@
             }
         }
 
-        if ( excludedPaths.length > 0 )
+        if ( !excludedPaths.isEmpty() )
         {
             if ( messages != null && messages.isDebugEnabled() )
             {

Modified: maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java?rev=694311&r1=694310&r2=694311&view=diff
==============================================================================
--- maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
(original)
+++ maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
Thu Sep 11 08:40:04 2008
@@ -280,29 +280,55 @@
     }
 
     /**
-     * @param from
-     * @param to
+     * @throws Exception if any
+     */
+    public void testDeleteDontFollowSymlinksButDeleteThem()
+        throws Exception
+    {
+        File directory = setupTestDirectory( "testDeleteDontFollowSymlinksButDeleteThem"
);
+
+        createSymlink( new File( directory, "excluded" ), new File( directory, "dir0/dirlink"
) );
+        createSymlink( new File( directory, "excluded.txt" ), new File( directory, "dir1/filelink"
) );
+
+        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 directory has not been deleted", new File( directory,
"dir0" ).exists() );
+        Assert.assertFalse( "included directory has not been deleted", new File( directory,
"dir1" ).exists() );
+    }
+
+    /**
+     * @param target The target file/directory of the symlink, must not be <code>null</code>.
+     * @param link The link to create, must not be <code>null</code>.
      * @return
      * @throws InterruptedException
      * @throws CommandLineException
      */
-    private boolean createSymlink( File from, File to )
+    private boolean createSymlink( File target, File link )
         throws InterruptedException, CommandLineException
     {
-        if ( to.exists() )
+        if ( link.exists() )
         {
-            to.delete();
+            link.delete();
         }
 
         Commandline cli = new Commandline();
         cli.setExecutable( "ln" );
-        cli.createArg().setLine( "-s" );
-        cli.createArg().setLine( from.getPath() );
-        cli.createArg().setLine( to.getPath() );
+        cli.createArg().setValue( "-s" );
+        cli.createArg().setValue( target.getPath() );
+        cli.createArg().setValue( link.getPath() );
 
         int result = cli.execute().waitFor();
 
-        linkFiles.add( to );
+        linkFiles.add( link );
 
         return result == 0;
     }

Added: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt?rev=694311&view=auto
==============================================================================
--- maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt
(added)
+++ maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt
Thu Sep 11 08:40:04 2008
@@ -0,0 +1 @@
+The Resources Plugin won't copy empty directories...
\ No newline at end of file

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir0/dummy.txt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt?rev=694311&view=auto
==============================================================================
--- maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt
(added)
+++ maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt
Thu Sep 11 08:40:04 2008
@@ -0,0 +1 @@
+The Resources Plugin won't copy empty directories...
\ No newline at end of file

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/dir1/dummy.txt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt?rev=694311&view=auto
==============================================================================
--- maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt
(added)
+++ maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt
Thu Sep 11 08:40:04 2008
@@ -0,0 +1 @@
+Serves as the target for a symlink and should not be deleted.
\ No newline at end of file

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded.txt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt?rev=694311&view=auto
==============================================================================
--- maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt
(added)
+++ maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt
Thu Sep 11 08:40:04 2008
@@ -0,0 +1 @@
+The Resources Plugin won't copy empty directories...
\ No newline at end of file

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/file-management/src/test/resources/testDeleteDontFollowSymlinksButDeleteThem/excluded/dummy.txt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message