From 34a07739f359b2ec173ffebeadab50ce667d4c24 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 20 Jan 2007 06:44:14 +0000 Subject: [PATCH] moving more fingerprint stuff up the inheritance chain to AbstractProject/Build. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1828 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/maven/MavenBuild.java | 7 ++ .../main/java/hudson/model/AbstractBuild.java | 57 ++++++++++----- .../java/hudson/model/AbstractProject.java | 72 +++++++++++++++++-- core/src/main/java/hudson/model/Build.java | 25 +------ core/src/main/java/hudson/model/Project.java | 65 ----------------- core/src/main/java/hudson/scm/CVSSCM.java | 5 +- 6 files changed, 116 insertions(+), 115 deletions(-) diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index fb5f1d1a2f..19425a1ac5 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -54,11 +54,18 @@ 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/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index 5dbf6d9f58..cb60b99a26 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -207,22 +207,6 @@ public abstract class AbstractBuild

,R extends Abs // fingerprint related stuff // // - /** - * Gets the downstream builds of this build, which are the builds of the - * downstream projects that use artifacts of this build. - * - * @return - * For each project with fingerprinting enabled, returns the range - * of builds (which can be empty if no build uses the artifact from this build.) - */ - public Map getDownstreamBuilds() { - Map r = new HashMap(); - for (AbstractProject p : getParent().getDownstreamProjects()) { - if(p.isFingerprintConfigured()) - r.put(p,getDownstreamRelationship(p)); - } - return r; - } @Override public String getWhyKeepLog() { @@ -252,6 +236,47 @@ public abstract class AbstractBuild

,R extends Abs */ public abstract RangeSet getDownstreamRelationship(AbstractProject that); + /** + * Gets the dependency relationship from this build (as the sink) + * and that project (as the source.) + * + * @return + * Build number of the upstream build that feed into this build, + * or -1 if no record is available. + */ + public abstract int getUpstreamRelationship(AbstractProject that); + + /** + * Gets the downstream builds of this build, which are the builds of the + * downstream projects that use artifacts of this build. + * + * @return + * For each project with fingerprinting enabled, returns the range + * of builds (which can be empty if no build uses the artifact from this build.) + */ + public Map getDownstreamBuilds() { + Map r = new HashMap(); + for (AbstractProject p : getParent().getDownstreamProjects()) { + if(p.isFingerprintConfigured()) + r.put(p,getDownstreamRelationship(p)); + } + return r; + } + + /** + * Gets the upstream builds of this build, which are the builds of the + * upstream projects whose artifacts feed into this build. + */ + public Map getUpstreamBuilds() { + Map r = new HashMap(); + for (AbstractProject p : getParent().getUpstreamProjects()) { + int n = getUpstreamRelationship(p); + if(n>=0) + r.put(p,n); + } + return r; + } + // // // web methods diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 14a616a18c..e4b491f4ab 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -2,26 +2,31 @@ package hudson.model; import hudson.FilePath; import hudson.Launcher; -import hudson.util.EditDistance; -import hudson.model.RunMap.Constructor; -import hudson.model.Descriptor.FormException; -import hudson.triggers.Trigger; -import hudson.triggers.Triggers; import hudson.Launcher.LocalLauncher; import hudson.maven.MavenModule; +import hudson.model.Descriptor.FormException; +import hudson.model.Fingerprint.RangeSet; +import hudson.model.RunMap.Constructor; import hudson.scm.NullSCM; import hudson.scm.SCM; import hudson.scm.SCMS; +import hudson.triggers.Trigger; +import hudson.triggers.Triggers; +import hudson.util.EditDistance; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import javax.servlet.ServletException; import java.io.File; import java.io.IOException; -import java.util.SortedMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; import java.util.List; -import java.util.Vector; import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.Vector; /** * Base implementation of {@link Job}s that build software. @@ -358,6 +363,53 @@ public abstract class AbstractProject

,R extends A */ public abstract List getDownstreamProjects(); + public List getUpstreamProjects() { + List r = new ArrayList(); + for( AbstractProject p : Hudson.getInstance().getAllItems(AbstractProject.class) ) { + if(p.getDownstreamProjects().contains(this)) + r.add(p); + } + return r; + } + + /** + * Gets the dependency relationship map between this project (as the source) + * and that project (as the sink.) + * + * @return + * can be empty but not null. build number of this project to the build + * numbers of that project. + */ + public SortedMap getRelationship(AbstractProject that) { + TreeMap r = new TreeMap(REVERSE_INTEGER_COMPARATOR); + + checkAndRecord(that, r, this.getBuilds()); + // checkAndRecord(that, r, that.getBuilds()); + + return r; + } + + /** + * Helper method for getDownstreamRelationship. + * + * For each given build, find the build number range of the given project and put that into the map. + */ + private void checkAndRecord(AbstractProject that, TreeMap r, Collection builds) { + for (R build : builds) { + RangeSet rs = build.getDownstreamRelationship(that); + if(rs==null || rs.isEmpty()) + continue; + + int n = build.getNumber(); + + RangeSet value = r.get(n); + if(value==null) + r.put(n,rs); + else + value.add(rs); + } + } + // // // actions @@ -479,4 +531,10 @@ public abstract class AbstractProject

,R extends A String nearest = EditDistance.findNearest(name, names); return (AbstractProject)Hudson.getInstance().getItem(nearest); } + + private static final Comparator REVERSE_INTEGER_COMPARATOR = new Comparator() { + public int compare(Integer o1, Integer o2) { + return o2-o1; + } + }; } diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java index c1b4ed6914..9126d4d379 100644 --- a/core/src/main/java/hudson/model/Build.java +++ b/core/src/main/java/hudson/model/Build.java @@ -69,15 +69,8 @@ public final class Build extends AbstractBuild { return rs; } - /** - * Gets the dependency relationship from this build (as the sink) - * and that project (as the source.) - * - * @return - * Build number of the upstream build that feed into this build, - * or -1 if no record is available. - */ - public int getUpstreamRelationship(Project that) { + @Override + public int getUpstreamRelationship(AbstractProject that) { FingerprintAction f = getAction(FingerprintAction.class); if(f==null) return -1; @@ -93,20 +86,6 @@ public final class Build extends AbstractBuild { return n; } - /** - * Gets the upstream builds of this build, which are the builds of the - * upstream projects whose artifacts feed into this build. - */ - public Map getUpstreamBuilds() { - Map r = new HashMap(); - for (Project p : getParent().getUpstreamProjects()) { - int n = getUpstreamRelationship(p); - if(n>=0) - r.put(p,n); - } - return r; - } - /** * Gets the changes in the dependency between the given build and this build. */ diff --git a/core/src/main/java/hudson/model/Project.java b/core/src/main/java/hudson/model/Project.java index 552fdf5e87..75a7d55477 100644 --- a/core/src/main/java/hudson/model/Project.java +++ b/core/src/main/java/hudson/model/Project.java @@ -1,7 +1,6 @@ package hudson.model; import hudson.model.Descriptor.FormException; -import hudson.model.Fingerprint.RangeSet; import hudson.tasks.BuildStep; import hudson.tasks.BuildTrigger; import hudson.tasks.BuildWrapper; @@ -17,15 +16,11 @@ import javax.servlet.ServletException; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; import java.util.Vector; /** @@ -123,23 +118,6 @@ public class Project extends AbstractProject implements TopLevelI return new Build(this,dir); } - /** - * Gets the dependency relationship map between this project (as the source) - * and that project (as the sink.) - * - * @return - * can be empty but not null. build number of this project to the build - * numbers of that project. - */ - public SortedMap getRelationship(Project that) { - TreeMap r = new TreeMap(REVERSE_INTEGER_COMPARATOR); - - checkAndRecord(that, r, this.getBuilds()); - // checkAndRecord(that, r, that.getBuilds()); - - return r; - } - public List getDownstreamProjects() { BuildTrigger buildTrigger = (BuildTrigger) getPublishers().get(BuildTrigger.DESCRIPTOR); if(buildTrigger==null) @@ -148,43 +126,6 @@ public class Project extends AbstractProject implements TopLevelI return buildTrigger.getChildProjects(); } - public List getUpstreamProjects() { - List r = new ArrayList(); - for( Project p : Hudson.getInstance().getProjects() ) { - synchronized(p) { - for (BuildStep step : p.publishers) { - if (step instanceof BuildTrigger) { - BuildTrigger trigger = (BuildTrigger) step; - if(trigger.getChildProjects().contains(this)) - r.add(p); - } - } - } - } - return r; - } - - /** - * Helper method for getDownstreamRelationship. - * - * For each given build, find the build number range of the given project and put that into the map. - */ - private void checkAndRecord(Project that, TreeMap r, Collection builds) { - for (Build build : builds) { - RangeSet rs = build.getDownstreamRelationship(that); - if(rs==null || rs.isEmpty()) - continue; - - int n = build.getNumber(); - - RangeSet value = r.get(n); - if(value==null) - r.put(n,rs); - else - value.add(rs); - } - } - @Override public boolean isFingerprintConfigured() { synchronized(publishers) { @@ -308,12 +249,6 @@ public class Project extends AbstractProject implements TopLevelI @Deprecated private transient String slave; - private static final Comparator REVERSE_INTEGER_COMPARATOR = new Comparator() { - public int compare(Integer o1, Integer o2) { - return o2-o1; - } - }; - public TopLevelItemDescriptor getDescriptor() { return DESCRIPTOR; } diff --git a/core/src/main/java/hudson/scm/CVSSCM.java b/core/src/main/java/hudson/scm/CVSSCM.java index 7128815651..50f028e4f5 100644 --- a/core/src/main/java/hudson/scm/CVSSCM.java +++ b/core/src/main/java/hudson/scm/CVSSCM.java @@ -10,14 +10,12 @@ import hudson.model.AbstractBuild; import hudson.model.AbstractModelObject; import hudson.model.AbstractProject; import hudson.model.Action; -import hudson.model.Build; import hudson.model.BuildListener; import hudson.model.Descriptor; import hudson.model.Hudson; import hudson.model.Job; import hudson.model.LargeText; import hudson.model.ModelObject; -import hudson.model.Project; import hudson.model.Run; import hudson.model.TaskListener; import hudson.org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask; @@ -53,7 +51,6 @@ import java.io.PrintWriter; import java.io.Reader; import java.io.Serializable; import java.io.StringWriter; -import java.io.OutputStreamWriter; import java.lang.ref.WeakReference; import java.text.DateFormat; import java.util.ArrayList; @@ -1035,7 +1032,7 @@ public class CVSSCM extends AbstractCVSFamilySCM implements Serializable { if(req.getParameter("upstream")!=null) { // tag all upstream builds Enumeration e = req.getParameterNames(); - Map upstreams = ((Build) build).getUpstreamBuilds(); // TODO: define them at AbstractBuild level + Map upstreams = build.getUpstreamBuilds(); // TODO: define them at AbstractBuild level while(e.hasMoreElements()) { String upName = (String) e.nextElement();