From 7b02693fb1734bbf821720b6b85aa77ff284df3d Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sun, 26 Aug 2007 18:33:08 +0000 Subject: [PATCH] first cut at the aggregated build. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4440 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/maven/MavenBuild.java | 46 ++++++++++++++++++- .../java/hudson/maven/MavenBuildProxy2.java | 20 ++++++++ .../hudson/maven/MavenModuleSetBuild.java | 41 +++++++++++++---- 3 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 core/src/main/java/hudson/maven/MavenBuildProxy2.java diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index 161ad456f1..c82de11568 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -197,7 +197,7 @@ public class MavenBuild extends AbstractBuild { /** * {@link MavenBuildProxy} implementation. */ - final class ProxyImpl implements MavenBuildProxy, Serializable { + class ProxyImpl implements MavenBuildProxy, Serializable { public V execute(BuildCallable program) throws T, IOException, InterruptedException { return program.call(MavenBuild.this); } @@ -227,7 +227,49 @@ public class MavenBuild extends AbstractBuild { } private Object writeReplace() { - return Channel.current().export(MavenBuildProxy.class, new ProxyImpl()); + return Channel.current().export(MavenBuildProxy.class,this); + } + } + + class ProxyImpl2 extends ProxyImpl implements MavenBuildProxy2 { + long startTime; + public void start() { + onStartBuilding(); + startTime = System.currentTimeMillis(); + } + + public void end() { + if(result==null) + setResult(Result.SUCCESS); + onEndBuilding(); + duration = System.currentTimeMillis()- startTime; + try { + save(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Mark the build as aborted. This method is used when the aggregated build + * failed before it didn't even get to this module. + */ + protected void abortIfNotStarted() { + if(hasntStartedYet()) { + run(new Runner() { + public Result run(BuildListener listener) throws Exception, RunnerAbortedException { + listener.getLogger().println("Build failed before it gets to this module"); + return Result.ABORTED; + } + + public void post(BuildListener listener) throws Exception { + } + }); + } + } + + private Object writeReplace() { + return Channel.current().export(MavenBuildProxy2.class,this); } } diff --git a/core/src/main/java/hudson/maven/MavenBuildProxy2.java b/core/src/main/java/hudson/maven/MavenBuildProxy2.java new file mode 100644 index 0000000000..1c346f6df1 --- /dev/null +++ b/core/src/main/java/hudson/maven/MavenBuildProxy2.java @@ -0,0 +1,20 @@ +package hudson.maven; + +/** + * A part of {@link MavenBuildProxy} that's used internally + * for aggregated build. Fired and consumed internally and + * not exposed to plugins. + * + * @author Kohsuke Kawaguchi + */ +interface MavenBuildProxy2 extends MavenBuildProxy { + /** + * Notifies that the build has entered a module. + */ + void start(); + + /** + * Notifies that the build has left a module. + */ + void end(); +} diff --git a/core/src/main/java/hudson/maven/MavenModuleSetBuild.java b/core/src/main/java/hudson/maven/MavenModuleSetBuild.java index a341a038a9..b9bb6bff3b 100644 --- a/core/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/core/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -1,6 +1,7 @@ package hudson.maven; import hudson.AbortException; +import hudson.maven.MavenBuild.ProxyImpl2; import hudson.FilePath.FileCallable; import hudson.model.AbstractBuild; import hudson.model.Action; @@ -277,9 +278,9 @@ public final class MavenModuleSetBuild extends AbstractBuild proxies = new HashMap(); + Map proxies = new HashMap(); for (MavenModule m : modules.values()) - proxies.put(m.getModuleName(),m.newBuild().new ProxyImpl()); + proxies.put(m.getModuleName(),m.newBuild().new ProxyImpl2()); // run the complete build here Map envVars = getEnvVars(); @@ -288,13 +289,15 @@ public final class MavenModuleSetBuild extends AbstractBuild buildProxy; + private final Map buildProxy; private final Map> reporters = new HashMap>(); - public Builder(BuildListener listener,Map buildProxy, Collection modules, List goals, Map systemProps) { + public Builder(BuildListener listener,Map buildProxy, Collection modules, List goals, Map systemProps) { super(listener,goals,systemProps); this.buildProxy = buildProxy; @@ -347,19 +350,39 @@ public final class MavenModuleSetBuild extends AbstractBuild