mirror of https://github.com/apache/maven.git
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:
parent
e452a9ca52
commit
dab33490a5
|
@ -56,6 +56,7 @@ import org.codehaus.plexus.util.CollectionUtils;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -382,7 +383,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
if ( plugin.supportsNewMojoParadigm() )
|
if ( plugin.supportsNewMojoParadigm() )
|
||||||
{
|
{
|
||||||
// TODO: construct request
|
populateParameters( plugin, mojoDescriptor, session );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -468,6 +469,52 @@ public class DefaultPluginManager
|
||||||
// Mojo Parameter Handling
|
// 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 )
|
public Map createParameters( MojoDescriptor goal, MavenSession session )
|
||||||
throws PluginConfigurationException
|
throws PluginConfigurationException
|
||||||
{
|
{
|
||||||
|
@ -664,12 +711,12 @@ public class DefaultPluginManager
|
||||||
private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver )
|
private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver )
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
|
for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) it.next();
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
|
||||||
artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
|
artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,12 @@ public abstract class AbstractPlugin
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public abstract void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
||||||
throws Exception;
|
throws Exception
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"If you are using the old technioque, you must override execute(req,resp)" );
|
||||||
|
}
|
||||||
|
|
||||||
public void setLog( Log log )
|
public void setLog( Log log )
|
||||||
{
|
{
|
||||||
|
@ -80,7 +84,9 @@ public abstract class AbstractPlugin
|
||||||
throws PluginExecutionException
|
throws PluginExecutionException
|
||||||
{
|
{
|
||||||
if ( supportsNewMojoParadigm() )
|
if ( supportsNewMojoParadigm() )
|
||||||
|
{
|
||||||
throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" );
|
throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsNewMojoParadigm()
|
public boolean supportsNewMojoParadigm()
|
||||||
|
|
|
@ -17,26 +17,21 @@ package org.apache.maven.plugin.clean;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.plugin.AbstractPlugin;
|
import org.apache.maven.plugin.AbstractPlugin;
|
||||||
import org.apache.maven.plugin.PluginExecutionRequest;
|
import org.apache.maven.plugin.PluginExecutionException;
|
||||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @goal clean
|
|
||||||
*
|
|
||||||
* @description Goal which cleans the build
|
|
||||||
*
|
|
||||||
* @parameter
|
|
||||||
* name="outputDirectory"
|
|
||||||
* type="String"
|
|
||||||
* required="true"
|
|
||||||
* validator=""
|
|
||||||
* expression="#project.build.directory"
|
|
||||||
* description=""
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:evenisse@maven.org">Emmanuel Venisse</a>
|
* @author <a href="mailto:evenisse@maven.org">Emmanuel Venisse</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
* @goal clean
|
||||||
|
* @description Goal which cleans the build
|
||||||
|
* @parameter name="outputDirectory"
|
||||||
|
* type="String"
|
||||||
|
* required="true"
|
||||||
|
* validator=""
|
||||||
|
* expression="#project.build.directory"
|
||||||
|
* description=""
|
||||||
*/
|
*/
|
||||||
public class CleanPlugin
|
public class CleanPlugin
|
||||||
extends AbstractPlugin
|
extends AbstractPlugin
|
||||||
|
@ -45,34 +40,33 @@ public class CleanPlugin
|
||||||
|
|
||||||
private String outputDirectory;
|
private String outputDirectory;
|
||||||
|
|
||||||
private boolean failOnError;
|
// TODO: not in the descriptor previously
|
||||||
|
// private boolean failOnError;
|
||||||
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
public boolean supportsNewMojoParadigm()
|
||||||
throws Exception
|
|
||||||
{
|
{
|
||||||
try
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute()
|
||||||
|
throws PluginExecutionException
|
||||||
|
{
|
||||||
|
if ( outputDirectory != null )
|
||||||
{
|
{
|
||||||
outputDirectory = (String) request.getParameter( "outputDirectory" );
|
File dir = new File( outputDirectory );
|
||||||
|
|
||||||
failOnError = Boolean.valueOf( (String) request.getParameter( "failedOnError" ) ).booleanValue();
|
if ( dir.exists() && dir.isDirectory() )
|
||||||
|
|
||||||
if ( outputDirectory != null )
|
|
||||||
{
|
{
|
||||||
File dir = new File( outputDirectory );
|
getLog().info( "Deleting directory " + dir.getAbsolutePath() );
|
||||||
|
try
|
||||||
if ( dir.exists() && dir.isDirectory() )
|
|
||||||
{
|
{
|
||||||
getLog().info( "Deleting directory " + dir.getAbsolutePath() );
|
|
||||||
removeDir( dir );
|
removeDir( dir );
|
||||||
}
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
throw new PluginExecutionException( "Unable to delete directory", e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
// clean up state.
|
|
||||||
failOnError = false;
|
|
||||||
outputDirectory = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,7 +100,8 @@ public class CleanPlugin
|
||||||
*
|
*
|
||||||
* @param d the directory to delete
|
* @param d the directory to delete
|
||||||
*/
|
*/
|
||||||
protected void removeDir( File d ) throws Exception
|
protected void removeDir( File d )
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
String[] list = d.list();
|
String[] list = d.list();
|
||||||
if ( list == null )
|
if ( list == null )
|
||||||
|
@ -123,35 +118,34 @@ public class CleanPlugin
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//log("Deleting " + f.getAbsolutePath());
|
|
||||||
if ( !delete( f ) )
|
if ( !delete( f ) )
|
||||||
{
|
{
|
||||||
String message = "Unable to delete file "
|
String message = "Unable to delete file " + f.getAbsolutePath();
|
||||||
+ f.getAbsolutePath();
|
// TODO:...
|
||||||
if ( failOnError )
|
// if ( failOnError )
|
||||||
{
|
// {
|
||||||
throw new Exception( message );
|
// throw new Exception( message );
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
getLog().info( message );
|
getLog().info( message );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//log("Deleting directory " + d.getAbsolutePath());
|
|
||||||
if ( !delete( d ) )
|
if ( !delete( d ) )
|
||||||
{
|
{
|
||||||
String message = "Unable to delete directory "
|
String message = "Unable to delete directory " + d.getAbsolutePath();
|
||||||
+ d.getAbsolutePath();
|
// TODO:...
|
||||||
if ( failOnError )
|
// if ( failOnError )
|
||||||
{
|
// {
|
||||||
throw new Exception( message );
|
// throw new Exception( message );
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
getLog().info( message );
|
getLog().info( message );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue