diff --git a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java index 55d98997ca..e21dc0b17a 100644 --- a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java +++ b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java @@ -2,13 +2,13 @@ package org.apache.maven.plugin.eclipse; /* * Copyright 2001-2005 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,50 +16,58 @@ package org.apache.maven.plugin.eclipse; * limitations under the License. */ - import java.io.File; +import java.text.MessageFormat; + import org.apache.maven.plugin.AbstractMojo; 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 */ -public class EclipseCleanMojo extends AbstractMojo +public class EclipseCleanMojo + extends AbstractMojo { /** * @parameter expression="${project.basedir}" */ - private String basedir; - - public void execute() throws MojoExecutionException + private File basedir; + + public void execute() + throws MojoExecutionException { - File f = new File( basedir, ".project" ); - - getLog().info( "Deleting project file..." ); - if ( f.exists() ) - { - if ( !f.delete() ) - { - throw new MojoExecutionException( "Failed to delete project file: " + f.getAbsolutePath() ); - } - } - else - getLog().info( "No .project file found." ); - - f = new File( basedir, ".classpath" ); - - getLog().info( "Deleting classpath file..." ); - if ( f.exists() ) - { - if ( !f.delete() ) - { - throw new MojoExecutionException( "Failed to delete classpath file: " + f.getAbsolutePath() ); - } - } - else - getLog().info( "No .classpath file found." ); + 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() } ) ); + + if ( f.exists() ) + { + if ( !f.delete() ) + { + throw new MojoExecutionException( MessageFormat.format( "Failed to delete {0} file: {0}", new Object[] { + f.getName(), + f.getAbsolutePath() } ) ) + { + }; + } + } + else + { + getLog().info( MessageFormat.format( "No {0} file found", new Object[] { f.getName() } ) ); + } + } + }