most basic of field based plugins

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-21 03:49:17 +00:00
parent e452a9ca52
commit dab33490a5
3 changed files with 109 additions and 62 deletions

View File

@ -56,6 +56,7 @@ import org.codehaus.plexus.util.CollectionUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -382,7 +383,7 @@ public class DefaultPluginManager
if ( plugin.supportsNewMojoParadigm() )
{
// TODO: construct request
populateParameters( plugin, mojoDescriptor, session );
}
else
{
@ -468,6 +469,52 @@ public class DefaultPluginManager
// Mojo Parameter Handling
// ----------------------------------------------------------------------
private void populateParameters( Plugin plugin, MojoDescriptor mojoDescriptor, MavenSession session )
throws PluginConfigurationException
{
// TODO: merge eventually, just to avoid reuse
// TODO: probably want to use the plexus component configurator... then do the additional processing in
// createParameters afterwards. Not sure how we might find files that are nested in other objects... perhaps
// we add a "needs translation" to the mojo so such types can be translated (implementing some interface) and
// address their own file objects
Map values = createParameters( mojoDescriptor, session );
List parameters = mojoDescriptor.getParameters();
for ( Iterator i = parameters.iterator(); i.hasNext(); )
{
Parameter param = (Parameter) i.next();
String name = param.getName();
Object value = values.get( name );
Class clazz = plugin.getClass();
try
{
Field f = clazz.getDeclaredField( name );
boolean accessible = f.isAccessible();
if ( !accessible )
{
f.setAccessible( true );
}
f.set( plugin, value );
if ( !accessible )
{
f.setAccessible( false );
}
}
catch ( NoSuchFieldException e )
{
throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
}
catch ( IllegalAccessException e )
{
throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
}
}
}
public Map createParameters( MojoDescriptor goal, MavenSession session )
throws PluginConfigurationException
{

View File

@ -55,8 +55,12 @@ public abstract class AbstractPlugin
/**
* @deprecated
*/
public abstract void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception;
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
throw new UnsupportedOperationException(
"If you are using the old technioque, you must override execute(req,resp)" );
}
public void setLog( Log log )
{
@ -80,8 +84,10 @@ public abstract class AbstractPlugin
throws PluginExecutionException
{
if ( supportsNewMojoParadigm() )
{
throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" );
}
}
public boolean supportsNewMojoParadigm()
{

View File

@ -17,26 +17,21 @@ package org.apache.maven.plugin.clean;
*/
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.plugin.PluginExecutionException;
import java.io.File;
/**
* @author <a href="mailto:evenisse@maven.org">Emmanuel Venisse</a>
* @version $Id$
* @goal clean
*
* @description Goal which cleans the build
*
* @parameter
* name="outputDirectory"
* @parameter name="outputDirectory"
* type="String"
* required="true"
* validator=""
* expression="#project.build.directory"
* description=""
*
* @author <a href="mailto:evenisse@maven.org">Emmanuel Venisse</a>
* @version $Id$
*/
public class CleanPlugin
extends AbstractPlugin
@ -45,17 +40,16 @@ public class CleanPlugin
private String outputDirectory;
private boolean failOnError;
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
// TODO: not in the descriptor previously
// private boolean failOnError;
public boolean supportsNewMojoParadigm()
{
try
return true;
}
public void execute()
throws PluginExecutionException
{
outputDirectory = (String) request.getParameter( "outputDirectory" );
failOnError = Boolean.valueOf( (String) request.getParameter( "failedOnError" ) ).booleanValue();
if ( outputDirectory != null )
{
File dir = new File( outputDirectory );
@ -63,15 +57,15 @@ public class CleanPlugin
if ( dir.exists() && dir.isDirectory() )
{
getLog().info( "Deleting directory " + dir.getAbsolutePath() );
try
{
removeDir( dir );
}
}
}
finally
catch ( Exception e )
{
// clean up state.
failOnError = false;
outputDirectory = null;
throw new PluginExecutionException( "Unable to delete directory", e );
}
}
}
}
@ -106,7 +100,8 @@ public class CleanPlugin
*
* @param d the directory to delete
*/
protected void removeDir( File d ) throws Exception
protected void removeDir( File d )
throws Exception
{
String[] list = d.list();
if ( list == null )
@ -123,36 +118,35 @@ public class CleanPlugin
}
else
{
//log("Deleting " + f.getAbsolutePath());
if ( !delete( f ) )
{
String message = "Unable to delete file "
+ f.getAbsolutePath();
if ( failOnError )
{
throw new Exception( message );
}
else
{
getLog().info( message );
}
}
}
}
//log("Deleting directory " + d.getAbsolutePath());
if ( !delete( d ) )
{
String message = "Unable to delete directory "
+ d.getAbsolutePath();
if ( failOnError )
{
throw new Exception( message );
}
else
{
String message = "Unable to delete file " + f.getAbsolutePath();
// TODO:...
// if ( failOnError )
// {
// throw new Exception( message );
// }
// else
// {
getLog().info( message );
// }
}
}
}
if ( !delete( d ) )
{
String message = "Unable to delete directory " + d.getAbsolutePath();
// TODO:...
// if ( failOnError )
// {
// throw new Exception( message );
// }
// else
// {
getLog().info( message );
// }
}
}
}