maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r377796 - /maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
Date Tue, 14 Feb 2006 18:20:58 GMT
Author: jdcasey
Date: Tue Feb 14 10:20:56 2006
New Revision: 377796

URL: http://svn.apache.org/viewcvs?rev=377796&view=rev
Log:
[MCLEAN-4] Adding flag followSymLinks which defaults to false, and will cause the clean mojo
to detect symbolic links and either traverse them when deleting, or (by default) simply delete
the links.

Modified:
    maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java

Modified: maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java?rev=377796&r1=377795&r2=377796&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
(original)
+++ maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
Tue Feb 14 10:20:56 2006
@@ -20,6 +20,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 
 import java.io.File;
+import java.io.IOException;
 
 /**
  * Goal which cleans the build.
@@ -59,6 +60,20 @@
      * @readonly
      */
     private File testOutputDirectory;
+    
+    /**
+     * Be verbose in the debug log-level?
+     * 
+     * @parameter default=value="false" expression="${clean.verbose}"
+     */
+    private boolean verbose;
+
+    /**
+     * Should we follow symbolically linked files?
+     * 
+     * @parameter default=value="false" expression="${clean.followSymLinks}"
+     */
+    private boolean followSymLinks;
 
     public void execute()
         throws MojoExecutionException
@@ -90,12 +105,22 @@
     {
         if ( !f.delete() )
         {
+            if ( verbose )
+            {
+                getLog().debug( "Failed to delete: " + f + " on first pass. Taking evasive
actions." );
+            }
+            
             if ( System.getProperty( "os.name" ).toLowerCase().indexOf( "windows" ) >
-1 )
             {
                 System.gc();
             }
             try
             {
+                if ( verbose )
+                {
+                    getLog().debug( "Waiting: " + DELETE_RETRY_SLEEP_MILLIS + "ms to retry
delete." );
+                }
+                
                 Thread.sleep( DELETE_RETRY_SLEEP_MILLIS );
                 return f.delete();
             }
@@ -115,6 +140,11 @@
     protected void removeDir( File d )
         throws MojoExecutionException
     {
+        if ( verbose )
+        {
+            getLog().debug( "Deleting directory: " + d + ". Traversing children first." );
+        }
+        
         String[] list = d.list();
         if ( list == null )
         {
@@ -124,7 +154,13 @@
         {
             String s = list[i];
             File f = new File( d, s );
-            if ( f.isDirectory() )
+
+            if ( verbose )
+            {
+                getLog().debug( "Deleting: " + f + "." );
+            }
+            
+            if ( f.isDirectory() && ( followSymLinks || !isSymLink( f ) ) )
             {
                 removeDir( f );
             }
@@ -158,6 +194,19 @@
 //            {
 //                getLog().info( message );
 //            }
+        }
+    }
+
+    private boolean isSymLink( File file ) throws MojoExecutionException
+    {
+        File dir = file.getParentFile();
+        try
+        {
+            return !file.getCanonicalPath().startsWith( dir.getCanonicalPath() );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error checking whether file: " + file + "
is a symbolic link. Error: " + e.getMessage(), e );
         }
     }
 }



Mime
View raw message