You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/09/03 23:32:24 UTC
svn commit: r691788 -
/maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java
Author: bentmann
Date: Wed Sep 3 14:32:24 2008
New Revision: 691788
URL: http://svn.apache.org/viewvc?rev=691788&view=rev
Log:
[MCLEAN-31] Always resolve relative path against the project's base directory
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/viewvc/maven/plugins/trunk/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanMojo.java?rev=691788&r1=691787&r2=691788&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 Wed Sep 3 14:32:24 2008
@@ -24,7 +24,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.shared.model.fileset.util.FileSetManager;
-import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
@@ -200,31 +199,9 @@
{
for ( Iterator it = filesets.iterator(); it.hasNext(); )
{
- Fileset fileset = (Fileset) it.next();
+ FileSet fileset = (FileSet) it.next();
- try
- {
- getLog().info( "Deleting " + fileset );
-
- if ( !project.isExecutionRoot() )
- {
- String projectBasedir = StringUtils.replace( project.getBasedir().getAbsolutePath(),
- "\\", "/" );
- String filesetDir = StringUtils.replace( fileset.getDirectory(), "\\", "/" );
-
- if ( filesetDir.indexOf( projectBasedir ) == -1 )
- {
- fileset.setDirectory( projectBasedir + "/" + filesetDir );
- }
- }
-
- fileSetManager.delete( fileset, failOnError );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Failed to delete directory: " + fileset.getDirectory()
- + ". Reason: " + e.getMessage(), e );
- }
+ removeFileSet( fileset );
}
}
}
@@ -250,27 +227,45 @@
throw new MojoExecutionException( dir + " is not a directory." );
}
- FileSet fs = new FileSet();
+ FileSet fs = new Fileset();
fs.setDirectory( dir.getPath() );
- fs.addInclude( "**/**" );
+ fs.addInclude( "**" );
fs.setFollowSymlinks( followSymLinks );
- try
- {
- getLog().info( "Deleting directory " + dir.getAbsolutePath() );
- fileSetManager.delete( fs, failOnError );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Failed to delete directory: " + dir + ". Reason: " + e.getMessage(),
- e );
- }
- catch ( IllegalStateException e )
+ removeFileSet( fs );
+ }
+ }
+
+ /**
+ * Deletes the specified file set. If the base directory of the file set is relative, it will be resolved against
+ * the base directory of the current project.
+ *
+ * @param fileset The file set to delete, must not be <code>null</code>.
+ * @throws MojoExecutionException When the file set failed to get deleted.
+ */
+ private void removeFileSet( FileSet fileset )
+ throws MojoExecutionException
+ {
+ try
+ {
+ if ( !new File( fileset.getDirectory() ).isAbsolute() )
{
- // TODO: IOException from plexus-utils should be acceptable here
- throw new MojoExecutionException( "Failed to delete directory: " + dir + ". Reason: " + e.getMessage(),
- e );
+ fileset.setDirectory( new File( project.getBasedir(), fileset.getDirectory() ).getPath() );
}
+
+ getLog().info( "Deleting " + fileset );
+ fileSetManager.delete( fileset, failOnError );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Failed to delete directory: " + fileset.getDirectory() + ". Reason: "
+ + e.getMessage(), e );
+ }
+ catch ( IllegalStateException e )
+ {
+ // TODO: IOException from plexus-utils should be acceptable here
+ throw new MojoExecutionException( "Failed to delete directory: " + fileset.getDirectory() + ". Reason: "
+ + e.getMessage(), e );
}
}