mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
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
This commit is contained in:
1 parent
a38165c19e
commit
34a07739f3
6 files changed
+116
-115
No files matched your search
@@ -54,11 +54,18 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -207,22 +207,6 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,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<AbstractProject,RangeSet> getDownstreamBuilds() {
|
||||
Map<AbstractProject,RangeSet> r = new HashMap<AbstractProject,RangeSet>();
|
||||
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<P extends AbstractProject<P,R>,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<AbstractProject,RangeSet> getDownstreamBuilds() {
|
||||
Map<AbstractProject,RangeSet> r = new HashMap<AbstractProject,RangeSet>();
|
||||
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<AbstractProject,Integer> getUpstreamBuilds() {
|
||||
Map<AbstractProject,Integer> r = new HashMap<AbstractProject,Integer>();
|
||||
for (AbstractProject p : getParent().getUpstreamProjects()) {
|
||||
int n = getUpstreamRelationship(p);
|
||||
if(n>=0)
|
||||
r.put(p,n);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// web methods
|
||||
|
||||
@@ -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<P extends AbstractProject<P,R>,R extends A
|
||||
*/
|
||||
public abstract List<? extends AbstractProject> getDownstreamProjects();
|
||||
|
||||
public List<AbstractProject> getUpstreamProjects() {
|
||||
List<AbstractProject> r = new ArrayList<AbstractProject>();
|
||||
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<Integer, RangeSet> getRelationship(AbstractProject that) {
|
||||
TreeMap<Integer,RangeSet> r = new TreeMap<Integer,RangeSet>(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<Integer, RangeSet> r, Collection<R> 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<P extends AbstractProject<P,R>,R extends A
|
||||
String nearest = EditDistance.findNearest(name, names);
|
||||
return (AbstractProject)Hudson.getInstance().getItem(nearest);
|
||||
}
|
||||
|
||||
private static final Comparator<Integer> REVERSE_INTEGER_COMPARATOR = new Comparator<Integer>() {
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return o2-o1;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -69,15 +69,8 @@ public final class Build extends AbstractBuild<Project,Build> {
|
||||
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<Project,Build> {
|
||||
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<Project,Integer> getUpstreamBuilds() {
|
||||
Map<Project,Integer> r = new HashMap<Project,Integer>();
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -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<Project,Build> 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<Integer,RangeSet> getRelationship(Project that) {
|
||||
TreeMap<Integer,RangeSet> r = new TreeMap<Integer,RangeSet>(REVERSE_INTEGER_COMPARATOR);
|
||||
|
||||
checkAndRecord(that, r, this.getBuilds());
|
||||
// checkAndRecord(that, r, that.getBuilds());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
public List<AbstractProject> getDownstreamProjects() {
|
||||
BuildTrigger buildTrigger = (BuildTrigger) getPublishers().get(BuildTrigger.DESCRIPTOR);
|
||||
if(buildTrigger==null)
|
||||
@@ -148,43 +126,6 @@ public class Project extends AbstractProject<Project,Build> implements TopLevelI
|
||||
return buildTrigger.getChildProjects();
|
||||
}
|
||||
|
||||
public List<Project> getUpstreamProjects() {
|
||||
List<Project> r = new ArrayList<Project>();
|
||||
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<Integer, RangeSet> r, Collection<? extends Build> 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<Project,Build> implements TopLevelI
|
||||
@Deprecated
|
||||
private transient String slave;
|
||||
|
||||
private static final Comparator<Integer> REVERSE_INTEGER_COMPARATOR = new Comparator<Integer>() {
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return o2-o1;
|
||||
}
|
||||
};
|
||||
|
||||
public TopLevelItemDescriptor getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
@@ -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<Project, Integer> upstreams = ((Build) build).getUpstreamBuilds(); // TODO: define them at AbstractBuild level
|
||||
Map<AbstractProject, Integer> upstreams = build.getUpstreamBuilds(); // TODO: define them at AbstractBuild level
|
||||
|
||||
while(e.hasMoreElements()) {
|
||||
String upName = (String) e.nextElement();
|
||||
|
||||
Reference in new issue
Block a user