From 26574c6d52e2b64fdb040bdc0f4df62a08a3f71a Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 1 Feb 2007 06:47:06 +0000 Subject: [PATCH] downstream/upstream computation can be moved up to AbstractBuild. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2016 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/maven/MavenBuild.java | 12 ------ .../hudson/maven/MavenModuleSetBuild.java | 12 ------ .../main/java/hudson/model/AbstractBuild.java | 33 ++++++++++++++++- core/src/main/java/hudson/model/Build.java | 37 ------------------- 4 files changed, 31 insertions(+), 63 deletions(-) diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index 015b105d9e..51f650b2b2 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -58,18 +58,6 @@ public class MavenBuild extends AbstractBuild { run(new RunnerImpl()); } - @Override - public RangeSet getDownstreamRelationship(AbstractProject that) { - // TODO - throw new UnsupportedOperationException(); - } - - @Override - public int getUpstreamRelationship(AbstractProject that) { - // TODO - throw new UnsupportedOperationException(); - } - /** * Runs Maven and builds the project. * diff --git a/core/src/main/java/hudson/maven/MavenModuleSetBuild.java b/core/src/main/java/hudson/maven/MavenModuleSetBuild.java index 6585c45239..8e4fa8aa47 100644 --- a/core/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/core/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -2,10 +2,8 @@ package hudson.maven; import hudson.FilePath.FileCallable; import hudson.model.AbstractBuild; -import hudson.model.AbstractProject; import hudson.model.Build; import hudson.model.BuildListener; -import hudson.model.Fingerprint.RangeSet; import hudson.model.Hudson; import hudson.model.Result; import hudson.remoting.VirtualChannel; @@ -52,16 +50,6 @@ public final class MavenModuleSetBuild extends AbstractBuild,R extends Abs * range of build numbers that represent which downstream builds are using this build. * The range will be empty if no build of that project matches this. */ - public abstract RangeSet getDownstreamRelationship(AbstractProject that); + public RangeSet getDownstreamRelationship(AbstractProject that) { + RangeSet rs = new RangeSet(); + + FingerprintAction f = getAction(FingerprintAction.class); + if(f==null) return rs; + + // look for fingerprints that point to this build as the source, and merge them all + for (Fingerprint e : f.getFingerprints().values()) { + BuildPtr o = e.getOriginal(); + if(o!=null && o.is(this)) + rs.add(e.getRangeSet(that)); + } + + return rs; + } /** * Gets the dependency relationship from this build (as the sink) @@ -256,7 +271,21 @@ public abstract class AbstractBuild

,R extends Abs * Build number of the upstream build that feed into this build, * or -1 if no record is available. */ - public abstract int getUpstreamRelationship(AbstractProject that); + public int getUpstreamRelationship(AbstractProject that) { + FingerprintAction f = getAction(FingerprintAction.class); + if(f==null) return -1; + + int n = -1; + + // look for fingerprints that point to the given project as the source, and merge them all + for (Fingerprint e : f.getFingerprints().values()) { + BuildPtr o = e.getOriginal(); + if(o!=null && o.is(that)) + n = Math.max(n,o.getNumber()); + } + + return n; + } /** * Gets the downstream builds of this build, which are the builds of the diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java index c1de26296c..371c21d61d 100644 --- a/core/src/main/java/hudson/model/Build.java +++ b/core/src/main/java/hudson/model/Build.java @@ -1,12 +1,9 @@ package hudson.model; -import hudson.model.Fingerprint.BuildPtr; -import hudson.model.Fingerprint.RangeSet; import hudson.tasks.BuildStep; import hudson.tasks.BuildWrapper; import hudson.tasks.BuildWrapper.Environment; import hudson.tasks.Builder; -import hudson.tasks.Fingerprinter.FingerprintAction; import hudson.tasks.Publisher; import hudson.tasks.test.AbstractTestResultAction; import hudson.triggers.SCMTrigger; @@ -50,40 +47,6 @@ public final class Build extends AbstractBuild { return getAction(AbstractTestResultAction.class); } - @Override - public RangeSet getDownstreamRelationship(AbstractProject that) { - RangeSet rs = new RangeSet(); - - FingerprintAction f = getAction(FingerprintAction.class); - if(f==null) return rs; - - // look for fingerprints that point to this build as the source, and merge them all - for (Fingerprint e : f.getFingerprints().values()) { - BuildPtr o = e.getOriginal(); - if(o!=null && o.is(this)) - rs.add(e.getRangeSet(that)); - } - - return rs; - } - - @Override - public int getUpstreamRelationship(AbstractProject that) { - FingerprintAction f = getAction(FingerprintAction.class); - if(f==null) return -1; - - int n = -1; - - // look for fingerprints that point to the given project as the source, and merge them all - for (Fingerprint e : f.getFingerprints().values()) { - BuildPtr o = e.getOriginal(); - if(o!=null && o.is(that)) - n = Math.max(n,o.getNumber()); - } - - return n; - } - /** * During the build this field remembers {@link Environment}s created by * {@link BuildWrapper}. This design is bit ugly but forced due to compatibility.