1 package hudson.maven; 2 3 import org.apache.maven.plugin.MojoExecution; 4 import org.apache.maven.project.MavenProject; 5 import org.apache.maven.execution.MavenSession; 6 import org.apache.maven.execution.ReactorManager; 7 import org.apache.maven.monitor.event.EventDispatcher; 8 import org.apache.maven.BuildFailureException; 9 import org.apache.maven.lifecycle.LifecycleExecutionException; 10 import org.apache.maven.lifecycle.LifecycleExecutorListener; 11 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; 12 import org.codehaus.plexus.configuration.PlexusConfiguration; 13 14 import java.io.IOException ; 15 16 import hudson.model.BuildListener; 17 import hudson.maven.agent.PluginManagerListener; 18 import hudson.maven.agent.AbortException; 19 20 26 public class PluginManagerInterceptor implements PluginManagerListener, LifecycleExecutorListener { 27 28 private final MavenBuildProxy buildProxy; 29 private final MavenReporter[] reporters; 30 private final BuildListener listener; 31 32 35 private MavenProject lastModule; 36 37 45 public PluginManagerInterceptor(MavenBuildProxy buildProxy, MavenReporter[] reporters, BuildListener listener) { 46 this.buildProxy = buildProxy; 47 this.reporters = reporters; 48 this.listener = listener; 49 } 50 51 54 public void preBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException { 55 try { 56 for (MavenReporter r : reporters) 57 r.preBuild(buildProxy,rm.getTopLevelProject(),listener); 58 } catch (InterruptedException e) { 59 throw new BuildFailureException("aborted",e); 60 } catch (IOException e) { 61 throw new BuildFailureException(e.getMessage(),e); 62 } 63 } 64 65 66 public void postBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException { 67 try { 68 fireLeaveModule(); 69 for (MavenReporter r : reporters) 70 r.postBuild(buildProxy,rm.getTopLevelProject(),listener); 71 } catch (InterruptedException e) { 72 throw new BuildFailureException("aborted",e); 73 } catch (IOException e) { 74 throw new BuildFailureException(e.getMessage(),e); 75 } catch (AbortException e) { 76 throw new BuildFailureException("aborted",e); 77 } 78 } 79 80 public void preExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException , InterruptedException , AbortException { 81 if(lastModule!=project) { 82 fireLeaveModule(); 84 fireEnterModule(project); 85 } 86 87 MojoInfo info = new MojoInfo(exec, mergedConfig, eval); 88 for (MavenReporter r : reporters) 89 if(!r.preExecute(buildProxy,project,info,listener)) 90 throw new AbortException(r+" failed"); 91 } 92 93 public void postExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException , InterruptedException , AbortException { 94 MojoInfo info = new MojoInfo(exec, mergedConfig, eval); 95 96 for (MavenReporter r : reporters) 97 if(!r.postExecute(buildProxy,project, info,listener)) 98 throw new AbortException(r+" failed"); 99 } 100 101 private void fireEnterModule(MavenProject project) throws InterruptedException , IOException , AbortException { 102 lastModule = project; 103 for (MavenReporter r : reporters) 104 if(!r.enterModule(buildProxy,project,listener)) 105 throw new AbortException(r+" failed"); 106 } 107 108 private void fireLeaveModule() throws InterruptedException , IOException , AbortException { 109 if(lastModule!=null) { 110 for (MavenReporter r : reporters) 111 if(!r.leaveModule(buildProxy,lastModule,listener)) 112 throw new AbortException(r+" failed"); 113 } 114 } 115 } 116 | Popular Tags |