提交 6e1e9e4d 编写于 作者: K kohsuke

MavenReporter should be able to intercept the postExecute callback even if the mojo fails.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2794 71c3de6d-444a-0410-be80-ed276b4c234a
上级 9b1cd862
......@@ -10,6 +10,8 @@ import hudson.model.Build;
import hudson.tasks.BuildStep;
import hudson.tasks.Publisher;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.IOException;
import java.io.Serializable;
......@@ -122,8 +124,14 @@ public abstract class MavenReporter implements Describable<MavenReporter>, Exten
* Called after execution of a single mojo.
* <p>
* See {@link #preExecute} for the contract.
*
* @param error
* If mojo execution failed with {@link MojoFailureException} or
* {@link MojoExecutionException}, this method is still invoked
* with those error objects.
* If mojo executed successfully, this parameter is null.
*/
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException, IOException {
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException {
return true;
}
......
......@@ -90,11 +90,11 @@ public class PluginManagerInterceptor implements PluginManagerListener, Lifecycl
throw new AbortException(r+" failed");
}
public void postExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException, AbortException {
public void postExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval, Exception exception) throws IOException, InterruptedException, AbortException {
MojoInfo info = new MojoInfo(exec, mergedConfig, eval);
for (MavenReporter r : reporters)
if(!r.postExecute(buildProxy,project, info,listener))
if(!r.postExecute(buildProxy,project,info,listener,exception))
throw new AbortException(r+" failed");
}
......
......@@ -47,7 +47,7 @@ public class MavenFingerprinter extends MavenReporter {
return true;
}
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException, IOException {
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException {
boolean updated = false;
// really nice if we can do this in preExecute,
......
......@@ -24,7 +24,7 @@ import java.io.IOException;
*/
public class MavenJavadocArchiver extends MavenReporter {
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException, IOException {
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException {
if(!mojo.pluginName.matches("org.apache.maven.plugins","maven-javadoc-plugin"))
return true;
......
......@@ -36,7 +36,7 @@ public class SurefireArchiver extends MavenReporter {
return true;
}
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, final BuildListener listener) throws InterruptedException, IOException {
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, final BuildListener listener, Throwable error) throws InterruptedException, IOException {
if (!isSurefireTest(mojo)) return true;
File reportsDir;
......
......@@ -28,7 +28,7 @@ public class RunCommand implements Callable {
System.out.println("***** "+exec.getMojoDescriptor().getGoal());
}
public void postExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException, AbortException {
public void postExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval, Exception exception) throws IOException, InterruptedException, AbortException {
System.out.println("==== "+exec.getMojoDescriptor().getGoal());
}
});
......
......@@ -93,9 +93,17 @@ public class PluginManagerInterceptor extends DefaultPluginManager {
try {
if(listener!=null)
listener.preExecute(project,mojoExecution,mergedConfiguration,eval);
super.executeMojo(project, mojoExecution, session);
if(listener!=null)
listener.postExecute(project,mojoExecution,mergedConfiguration,eval);
try {
super.executeMojo(project, mojoExecution, session);
if(listener!=null)
listener.postExecute(project,mojoExecution,mergedConfiguration,eval,null);
} catch (MojoExecutionException e) {
if(listener!=null)
listener.postExecute(project,mojoExecution,mergedConfiguration,eval,e);
} catch (MojoFailureException e) {
if(listener!=null)
listener.postExecute(project,mojoExecution,mergedConfiguration,eval,e);
}
} catch (InterruptedException e) {
// orderly abort
throw new AbortException("Execution aborted",e);
......
package hudson.maven.agent;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
......@@ -8,11 +10,30 @@ import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
import java.io.IOException;
/**
* Receives notification from {@link PluginManagerInterceptor}.
* Receives notification from {@link PluginManagerInterceptor},
* before and after a mojo is executed.
*
* @author Kohsuke Kawaguchi
*/
public interface PluginManagerListener {
void preExecute(MavenProject project,MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException, AbortException;
void postExecute(MavenProject project,MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException, AbortException;
/**
* Called after the mojo has finished executing.
*
* @param project
* Same object as passed to {@link #preExecute}.
* @param exec
* Same object as passed to {@link #preExecute}.
* @param mergedConfig
* Same object as passed to {@link #preExecute}.
* @param eval
* Same object as passed to {@link #preExecute}.
* @param exception
* If mojo execution failed with {@link MojoFailureException} or
* {@link MojoExecutionException}, this method is still invoked
* with those error objects.
* If mojo executed successfully, this parameter is null.
*/
void postExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval, Exception exception) throws IOException, InterruptedException, AbortException;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册