also delete .wtpmodules files + some code cleanup

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@315062 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fabrizio Giustina 2005-10-12 22:26:50 +00:00
parent 9f1c9f225a
commit 9769ca45a5
1 changed files with 43 additions and 35 deletions

View File

@ -16,50 +16,58 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File; import java.io.File;
import java.text.MessageFormat;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
/** /**
* A Maven2 plugin to delete the .project and .classpath files needed for Eclipse * A Maven2 plugin to delete the .project, .classpath and .wtpmodules files needed for Eclipse.
* *
* @goal clean * @goal clean
*/ */
public class EclipseCleanMojo extends AbstractMojo public class EclipseCleanMojo
extends AbstractMojo
{ {
/** /**
* @parameter expression="${project.basedir}" * @parameter expression="${project.basedir}"
*/ */
private String basedir; private File basedir;
public void execute() throws MojoExecutionException public void execute()
throws MojoExecutionException
{ {
File f = new File( basedir, ".project" ); delete( new File( basedir, ".project" ) );
delete( new File( basedir, ".classpath" ) );
delete( new File( basedir, ".wtpmodules" ) );
}
/**
* Delete a file, handling log messages and exceptions
* @param f File to be deleted
* @throws MojoExecutionException only if a file exists and can't be deleted
*/
private void delete( File f )
throws MojoExecutionException
{
getLog().info( MessageFormat.format( "Deleting {0} file...", new Object[] { f.getName() } ) );
getLog().info( "Deleting project file..." );
if ( f.exists() ) if ( f.exists() )
{ {
if ( !f.delete() ) if ( !f.delete() )
{ {
throw new MojoExecutionException( "Failed to delete project file: " + f.getAbsolutePath() ); throw new MojoExecutionException( MessageFormat.format( "Failed to delete {0} file: {0}", new Object[] {
f.getName(),
f.getAbsolutePath() } ) )
{
};
} }
} }
else else
getLog().info( "No .project file found." );
f = new File( basedir, ".classpath" );
getLog().info( "Deleting classpath file..." );
if ( f.exists() )
{ {
if ( !f.delete() ) getLog().info( MessageFormat.format( "No {0} file found", new Object[] { f.getName() } ) );
{
throw new MojoExecutionException( "Failed to delete classpath file: " + f.getAbsolutePath() );
} }
} }
else
getLog().info( "No .classpath file found." );
}
} }