diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index 7e7fcac5e4c17ba068d56c760e422fdcae7ee4f5..47b52a0cd5e16bd959121062cd56656d433b4d8a 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -2,7 +2,7 @@ package hudson.maven; import hudson.FilePath; import hudson.Util; -import hudson.maven.agent.Main; +import hudson.maven.agent.*; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.BuildListener; @@ -22,6 +22,7 @@ import hudson.tasks.test.AbstractTestResultAction; import hudson.util.ArgumentListBuilder; import hudson.util.IOException2; import org.codehaus.classworlds.NoSuchRealmException; +import org.apache.maven.lifecycle.LifecycleExecutorInterceptor; import java.io.File; import java.io.FilenameFilter; @@ -100,8 +101,6 @@ public class MavenBuild extends AbstractBuild { /** * Runs Maven and builds the project. - * - * This code is executed on the remote machine. */ private static final class Builder implements Callable { private final BuildListener listener; @@ -116,8 +115,15 @@ public class MavenBuild extends AbstractBuild { this.goals = goals; } + /** + * This code is executed inside the maven jail process. + */ public Result call() throws IOException { try { + PluginManagerInterceptor pmi = new PluginManagerInterceptor(buildProxy, reporters, listener); + hudson.maven.agent.PluginManagerInterceptor.setListener(pmi); + LifecycleExecutorInterceptor.setListener(pmi); + int r = Main.launch(goals.toArray(new String[goals.size()])); return r==0 ? Result.SUCCESS : Result.FAILURE; } catch (NoSuchMethodException e) { @@ -131,71 +137,6 @@ public class MavenBuild extends AbstractBuild { } catch (ClassNotFoundException e) { throw new IOException2(e); } - //MavenProject p=null; - //try { - // MavenEmbedder embedder = MavenUtil.createEmbedder(listener); - // File pom = new File("pom.xml").getAbsoluteFile(); // MavenEmbedder only works if it's absolute - // if(!pom.exists()) { - // listener.error("No POM: "+pom); - // return Result.FAILURE; - // } - // - // // event monitor is mostly useless. It only provides a few strings - // EventMonitor eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new EmbedderLoggerImpl(listener) ) ); - // - // p = embedder.readProject(pom); - // PluginManagerInterceptor interceptor; - // - // try { - // interceptor = (PluginManagerInterceptor)embedder.getContainer().lookup(PluginManager.class.getName()); - // interceptor.setBuilder(buildProxy,reporters,listener); - // } catch (ComponentLookupException e) { - // throw new Error(e); // impossible - // } - // - // for (MavenReporter r : reporters) - // r.preBuild(buildProxy,p,listener); - // - // embedder.execute(p, goals, eventMonitor, - // new TransferListenerImpl(listener), - // null, // TODO: allow additional properties to be specified - // pom.getParentFile()); - // - // interceptor.fireLeaveModule(); - // - // return null; - //} catch (MavenEmbedderException e) { - // buildProxy.setResult(Result.FAILURE); - // e.printStackTrace(listener.error(e.getMessage())); - //} catch (ProjectBuildingException e) { - // buildProxy.setResult(Result.FAILURE); - // e.printStackTrace(listener.error(e.getMessage())); - //} catch (CycleDetectedException e) { - // buildProxy.setResult(Result.FAILURE); - // e.printStackTrace(listener.error(e.getMessage())); - //} catch (LifecycleExecutionException e) { - // buildProxy.setResult(Result.FAILURE); - // e.printStackTrace(listener.error(e.getMessage())); - //} catch (BuildFailureException e) { - // buildProxy.setResult(Result.FAILURE); - // e.printStackTrace(listener.error(e.getMessage())); - //} catch (DuplicateProjectException e) { - // buildProxy.setResult(Result.FAILURE); - // e.printStackTrace(listener.error(e.getMessage())); - //} catch (AbortException e) { - // listener.error("build aborted"); - //} catch (InterruptedException e) { - // listener.error("build aborted"); - //} finally { - // // this should happen after a build is marked as a failure - // try { - // if(p!=null) - // for (MavenReporter r : reporters) - // r.postBuild(buildProxy,p,listener); - // } catch (InterruptedException e) { - // buildProxy.setResult(Result.FAILURE); - // } - //} } } @@ -300,7 +241,7 @@ public class MavenBuild extends AbstractBuild { ArgumentListBuilder args = new ArgumentListBuilder(); args.add(launcher.getChannel().call(new getJavaExe())); - // args.add("-Xrunjdwp:transport=dt_socket,server=y,address=8002"); + args.add("-Xrunjdwp:transport=dt_socket,server=y,address=8002"); args.add("-cp"); args.add( diff --git a/core/src/main/java/hudson/maven/PluginManagerInterceptor.java b/core/src/main/java/hudson/maven/PluginManagerInterceptor.java index 7d2e48e356007370a3cdd2e44e542fb798239f52..31751fc2ea451206e470db815096d64bb07ebcca 100644 --- a/core/src/main/java/hudson/maven/PluginManagerInterceptor.java +++ b/core/src/main/java/hudson/maven/PluginManagerInterceptor.java @@ -2,6 +2,12 @@ package hudson.maven; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.ReactorManager; +import org.apache.maven.monitor.event.EventDispatcher; +import org.apache.maven.BuildFailureException; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.LifecycleExecutorListener; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.configuration.PlexusConfiguration; @@ -17,11 +23,11 @@ import hudson.maven.agent.AbortException; * * @author Kohsuke Kawaguchi */ -public class PluginManagerInterceptor implements PluginManagerListener { +public class PluginManagerInterceptor implements PluginManagerListener, LifecycleExecutorListener { - private MavenBuildProxy buildProxy; - private MavenReporter[] reporters; - private BuildListener listener; + private final MavenBuildProxy buildProxy; + private final MavenReporter[] reporters; + private final BuildListener listener; /** * Used to detect when to fire {@link MavenReporter#enterModule} @@ -36,12 +42,41 @@ public class PluginManagerInterceptor implements PluginManagerListener { * We can't do this in the constructor because this object is created by * Plexus along with the rest of Maven objects. */ - /*package*/ void setBuilder(MavenBuildProxy buildProxy, MavenReporter[] reporters, BuildListener listener) { + public PluginManagerInterceptor(MavenBuildProxy buildProxy, MavenReporter[] reporters, BuildListener listener) { this.buildProxy = buildProxy; this.reporters = reporters; this.listener = listener; } + /** + * Called before the whole build. + */ + public void preBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException { + try { + for (MavenReporter r : reporters) + r.preBuild(buildProxy,rm.getTopLevelProject(),listener); + } catch (InterruptedException e) { + throw new BuildFailureException("aborted",e); + } catch (IOException e) { + throw new BuildFailureException(e.getMessage(),e); + } + } + + + public void postBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException { + try { + fireLeaveModule(); + for (MavenReporter r : reporters) + r.postBuild(buildProxy,rm.getTopLevelProject(),listener); + } catch (InterruptedException e) { + throw new BuildFailureException("aborted",e); + } catch (IOException e) { + throw new BuildFailureException(e.getMessage(),e); + } catch (AbortException e) { + throw new BuildFailureException("aborted",e); + } + } + public void preExecute(MavenProject project, MojoExecution exec, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException, AbortException { if(lastModule!=project) { // module change diff --git a/maven-interceptor/src/main/java/hudson/maven/agent/LifecycleExecutorInterceptor.java b/maven-interceptor/src/main/java/org/apache/maven/lifecycle/LifecycleExecutorInterceptor.java similarity index 72% rename from maven-interceptor/src/main/java/hudson/maven/agent/LifecycleExecutorInterceptor.java rename to maven-interceptor/src/main/java/org/apache/maven/lifecycle/LifecycleExecutorInterceptor.java index 30226fe11d35153fbd4c96fd85e13a8546470f56..39f8ca2ccb88240a8e4ff2cbe21bb98fb570dbd9 100644 --- a/maven-interceptor/src/main/java/hudson/maven/agent/LifecycleExecutorInterceptor.java +++ b/maven-interceptor/src/main/java/org/apache/maven/lifecycle/LifecycleExecutorInterceptor.java @@ -1,13 +1,18 @@ -package hudson.maven.agent; +package org.apache.maven.lifecycle; -import org.apache.maven.lifecycle.DefaultLifecycleExecutor; -import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.BuildFailureException; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; import org.apache.maven.monitor.event.EventDispatcher; -import org.apache.maven.BuildFailureException; /** + * {@link LifecycleExecutor} interceptor. + * + *

+ * This class is in the same package as in {@link DefaultLifecycleExecutor}, + * because Plexus requires the class and its subordinates (like {@link Lifecycle}, + * which is referenced in components.xml + * * @author Kohsuke Kawaguchi */ public class LifecycleExecutorInterceptor extends DefaultLifecycleExecutor { @@ -19,8 +24,8 @@ public class LifecycleExecutorInterceptor extends DefaultLifecycleExecutor { private static LifecycleExecutorListener listener; - public static void setListener(LifecycleExecutorListener listener) { - LifecycleExecutorInterceptor.listener = listener; + public static void setListener(LifecycleExecutorListener _listener) { + listener = _listener; } public void execute(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException { diff --git a/maven-interceptor/src/main/java/hudson/maven/agent/LifecycleExecutorListener.java b/maven-interceptor/src/main/java/org/apache/maven/lifecycle/LifecycleExecutorListener.java similarity index 90% rename from maven-interceptor/src/main/java/hudson/maven/agent/LifecycleExecutorListener.java rename to maven-interceptor/src/main/java/org/apache/maven/lifecycle/LifecycleExecutorListener.java index dd2f6a5d2b0d06450df311ba21e34adfc53455ed..413d074a639904631f2c2d706252eb0cfeb82bda 100644 --- a/maven-interceptor/src/main/java/hudson/maven/agent/LifecycleExecutorListener.java +++ b/maven-interceptor/src/main/java/org/apache/maven/lifecycle/LifecycleExecutorListener.java @@ -1,10 +1,9 @@ -package hudson.maven.agent; +package org.apache.maven.lifecycle; +import org.apache.maven.BuildFailureException; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; import org.apache.maven.monitor.event.EventDispatcher; -import org.apache.maven.BuildFailureException; -import org.apache.maven.lifecycle.LifecycleExecutionException; /** * Event notification for the start/end of the maven execution. diff --git a/maven-interceptor/src/main/resources/META-INF/plexus/components.xml b/maven-interceptor/src/main/resources/META-INF/plexus/components.xml index eb1b295764b6c35900d1bddd77f24f41a18f7eea..5a6bae24520bc8f46b3aecb348de9b13c76a9818 100644 --- a/maven-interceptor/src/main/resources/META-INF/plexus/components.xml +++ b/maven-interceptor/src/main/resources/META-INF/plexus/components.xml @@ -39,109 +39,108 @@ - - - - org.apache.maven.lifecycle.LifecycleExecutor - hudson.maven.agent.LifecycleExecutorInterceptor - - - org.apache.maven.plugin.PluginManager - - - org.apache.maven.extension.ExtensionManager - - - org.apache.maven.artifact.handler.manager.ArtifactHandlerManager - - - - - - default - - - validate - initialize - generate-sources - process-sources - generate-resources - process-resources - compile - process-classes - generate-test-sources - process-test-sources - generate-test-resources - process-test-resources - test-compile - test - package - pre-integration-test - integration-test - post-integration-test - verify - install - deploy - - - - - clean - - pre-clean - clean - post-clean - - - org.apache.maven.plugins:maven-clean-plugin:clean - - - - site - - pre-site - site - post-site - site-deploy - - - org.apache.maven.plugins:maven-site-plugin:site - org.apache.maven.plugins:maven-site-plugin:deploy - - - - - - org.apache.maven.plugins:maven-project-info-reports-plugin - + + validate + initialize + generate-sources + process-sources + generate-resources + process-resources + compile + process-classes + generate-test-sources + process-test-sources + generate-test-resources + process-test-resources + test-compile + test + package + pre-integration-test + integration-test + post-integration-test + verify + install + deploy + + + + + clean + + pre-clean + clean + post-clean + + + org.apache.maven.plugins:maven-clean-plugin:clean + + + + site + + pre-site + site + post-site + site-deploy + + + org.apache.maven.plugins:maven-site-plugin:site + org.apache.maven.plugins:maven-site-plugin:deploy + + + + + + org.apache.maven.plugins:maven-project-info-reports-plugin + + + + + - - - - - - - + + + +