diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 6c42ab0694..f263b0046d 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -56,6 +56,7 @@ 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 void executeMojo( MavenSession session, String goalName ) if ( plugin.supportsNewMojoParadigm() ) { - // TODO: construct request + populateParameters( plugin, mojoDescriptor, session ); } else { @@ -468,6 +469,52 @@ private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest requ // 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 { @@ -664,12 +711,12 @@ private void resolveTransitiveDependencies( MavenSession context, ArtifactResolv private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver ) throws ArtifactResolutionException { - for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); ) - { - Artifact artifact = (Artifact) it.next(); + for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); - artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() ); - } + artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() ); + } } } diff --git a/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java b/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java index 07275f6d10..6b053e6be9 100644 --- a/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java +++ b/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java @@ -55,8 +55,12 @@ public void execute( PluginExecutionRequest request ) /** * @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,7 +84,9 @@ public void execute() throws PluginExecutionException { if ( supportsNewMojoParadigm() ) + { throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" ); + } } public boolean supportsNewMojoParadigm() diff --git a/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java b/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java index d1b8e39542..02575c015a 100644 --- a/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java +++ b/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java @@ -17,26 +17,21 @@ */ 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; /** - * @goal clean - * - * @description Goal which cleans the build - * - * @parameter - * name="outputDirectory" - * type="String" - * required="true" - * validator="" - * expression="#project.build.directory" - * description="" - * * @author Emmanuel Venisse * @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 extends AbstractPlugin @@ -45,34 +40,33 @@ 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 + { + if ( outputDirectory != null ) { - outputDirectory = (String) request.getParameter( "outputDirectory" ); + File dir = new File( outputDirectory ); - failOnError = Boolean.valueOf( (String) request.getParameter( "failedOnError" ) ).booleanValue(); - - if ( outputDirectory != null ) + if ( dir.exists() && dir.isDirectory() ) { - File dir = new File( outputDirectory ); - - if ( dir.exists() && dir.isDirectory() ) + getLog().info( "Deleting directory " + dir.getAbsolutePath() ); + try { - getLog().info( "Deleting directory " + dir.getAbsolutePath() ); 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 @@ private boolean delete( File f ) * * @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,35 +118,34 @@ protected void removeDir( File d ) throws Exception } else { - //log("Deleting " + f.getAbsolutePath()); if ( !delete( f ) ) { - String message = "Unable to delete file " - + f.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 ); - } +// } } } } - //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 directory " + d.getAbsolutePath(); +// TODO:... +// if ( failOnError ) +// { +// throw new Exception( message ); +// } +// else +// { getLog().info( message ); - } +// } } }