You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2006/02/14 22:34:20 UTC
svn commit: r377838 - in /maven/plugins/trunk/maven-clean-plugin: pom.xml
src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
src/main/java/org/apache/maven/plugin/clean/Fileset.java
Author: jdcasey
Date: Tue Feb 14 13:34:18 2006
New Revision: 377838
URL: http://svn.apache.org/viewcvs?rev=377838&view=rev
Log:
Adding support for filesets using maven/shared/file-management.
Added:
maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java (with props)
Modified:
maven/plugins/trunk/maven-clean-plugin/pom.xml
maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
Modified: maven/plugins/trunk/maven-clean-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clean-plugin/pom.xml?rev=377838&r1=377837&r2=377838&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clean-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-clean-plugin/pom.xml Tue Feb 14 13:34:18 2006
@@ -10,4 +10,19 @@
<name>Maven Clean Plugin</name>
<version>2.0.1-SNAPSHOT</version>
<inceptionYear>2001</inceptionYear>
-</project>
\ No newline at end of file
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>file-management</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin><artifactId>maven-clean-plugin</artifactId>
+ <configuration><filesets><fileset><directory>${basedir}/test</directory></fileset></filesets></configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
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=377838&r1=377837&r2=377838&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 13:34:18 2006
@@ -18,9 +18,13 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.shared.model.fileset.FileSet;
+import org.apache.maven.shared.model.fileset.util.FileSetUtils;
import java.io.File;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
/**
* Goal which cleans the build.
@@ -32,8 +36,6 @@
public class CleanMojo
extends AbstractMojo
{
- private static final int DELETE_RETRY_SLEEP_MILLIS = 10;
-
/**
* This is where build results go.
*
@@ -67,6 +69,12 @@
* @parameter default=value="false" expression="${clean.verbose}"
*/
private boolean verbose;
+
+ /**
+ * The list of filesets to delete, in addition to the default directories.
+ * @parameter
+ */
+ private List filesets;
/**
* Should we follow symbolically linked files?
@@ -81,132 +89,48 @@
removeDirectory( directory );
removeDirectory( outputDirectory );
removeDirectory( testOutputDirectory );
+
+ removeAdditionalFilesets();
}
- private void removeDirectory( File dir )
- throws MojoExecutionException
- {
- if ( dir != null )
- {
- if ( dir.exists() && dir.isDirectory() )
- {
- getLog().info( "Deleting directory " + dir.getAbsolutePath() );
- removeDir( dir );
- }
- }
- }
-
- /**
- * Accommodate Windows bug encountered in both Sun and IBM JDKs.
- * Others possible. If the delete does not work, call System.gc(),
- * wait a little and try again.
- */
- private boolean delete( File f )
+ private void removeAdditionalFilesets() throws MojoExecutionException
{
- if ( !f.delete() )
+ if ( filesets != null && !filesets.isEmpty() )
{
- 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
+ for ( Iterator it = filesets.iterator(); it.hasNext(); )
{
- if ( verbose )
+ Fileset fileset = (Fileset) it.next();
+
+ try
{
- getLog().debug( "Waiting: " + DELETE_RETRY_SLEEP_MILLIS + "ms to retry delete." );
+ getLog().info( "Deleting " + fileset );
+ FileSetUtils.delete( fileset );
}
-
- Thread.sleep( DELETE_RETRY_SLEEP_MILLIS );
- return f.delete();
- }
- catch ( InterruptedException ex )
- {
- return f.delete();
- }
- }
- return true;
- }
-
- /**
- * Delete a directory
- *
- * @param d the directory to delete
- */
- protected void removeDir( File d )
- throws MojoExecutionException
- {
- if ( verbose )
- {
- getLog().debug( "Deleting directory: " + d + ". Traversing children first." );
- }
-
- String[] list = d.list();
- if ( list == null )
- {
- list = new String[0];
- }
- for ( int i = 0; i < list.length; i++ )
- {
- String s = list[i];
- File f = new File( d, s );
-
- if ( verbose )
- {
- getLog().debug( "Deleting: " + f + "." );
- }
-
- if ( f.isDirectory() && ( followSymLinks || !isSymLink( f ) ) )
- {
- removeDir( f );
- }
- else
- {
- if ( !delete( f ) )
+ catch ( IOException e )
{
- String message = "Unable to delete file " + f.getAbsolutePath();
-// TODO:...
-// if ( failOnError )
-// {
- throw new MojoExecutionException( message );
-// }
-// else
-// {
-// getLog().info( message );
-// }
+ throw new MojoExecutionException( "Failed to delete directory: " + fileset.getDirectory() + ". Reason: " + e.getMessage(), e );
}
}
}
-
- if ( !delete( d ) )
- {
- String message = "Unable to delete directory " + d.getAbsolutePath();
-// TODO:...
-// if ( failOnError )
-// {
- throw new MojoExecutionException( message );
-// }
-// else
-// {
-// getLog().info( message );
-// }
- }
}
- private boolean isSymLink( File file ) throws MojoExecutionException
+ private void removeDirectory( File dir )
+ throws MojoExecutionException
{
- File dir = file.getParentFile();
+ FileSet fs = new FileSet();
+ fs.setDirectory( dir.getPath() );
+ fs.addInclude( "**/**" );
+ fs.setFollowSymlinks( followSymLinks );
+
try
{
- return !file.getCanonicalPath().startsWith( dir.getCanonicalPath() );
+ getLog().info( "Deleting directory " + dir.getAbsolutePath() );
+ FileSetUtils.delete( fs );
}
catch ( IOException e )
{
- throw new MojoExecutionException( "Error checking whether file: " + file + " is a symbolic link. Error: " + e.getMessage(), e );
+ throw new MojoExecutionException( "Failed to delete directory: " + dir + ". Reason: " + e.getMessage(), e );
}
}
+
}
Added: maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java?rev=377838&view=auto
==============================================================================
--- maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java (added)
+++ maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java Tue Feb 14 13:34:18 2006
@@ -0,0 +1,14 @@
+package org.apache.maven.plugin.clean;
+
+import org.apache.maven.shared.model.fileset.FileSet;
+
+public class Fileset
+ extends FileSet
+{
+
+ public String toString()
+ {
+ return "file-set: " + getDirectory() + " (included: " + getIncludes() + ", excluded: " + getExcludes() + ")";
+ }
+
+}
Propchange: maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/Fileset.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"