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

@ -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() } ) );
}
}
}