提交 39136804 编写于 作者: A Andrew Bayer

Rework to solo RunWithSCM interface

上级 e6f60646
......@@ -30,7 +30,7 @@ import hudson.EnvVars;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import jenkins.scm.RunWithSCMMixIn;
import jenkins.scm.RunWithSCM;
import jenkins.util.SystemProperties;
import hudson.console.ModelHyperlinkNote;
import hudson.model.Fingerprint.BuildPtr;
......@@ -100,7 +100,7 @@ import jenkins.model.lazy.LazyBuildMixIn;
* @author Kohsuke Kawaguchi
* @see AbstractProject
*/
public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Run<P,R> implements Queue.Executable, LazyBuildMixIn.LazyLoadingRun<P,R>, RunWithSCMMixIn.RunWithSCM<P,R> {
public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Run<P,R> implements Queue.Executable, LazyBuildMixIn.LazyLoadingRun<P,R>, RunWithSCM<P,R> {
/**
* Set if we want the blame information to flow from upstream to downstream build.
......@@ -181,21 +181,16 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
return runMixIn;
}
@SuppressWarnings("unchecked") // untypable
@Override
public RunWithSCMMixIn<P,R> getRunWithSCMMixIn() {
return new RunWithSCMMixIn<P, R>() {
@SuppressWarnings("unchecked") // untypable
@Override protected R asRun() {
return (R) AbstractBuild.this;
}
@Override
@Nonnull public List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets() {
ChangeLogSet<? extends Entry> cs = getChangeSet();
return cs.isEmptySet() ? Collections.<ChangeLogSet<? extends ChangeLogSet.Entry>>emptyList() : Collections.<ChangeLogSet<? extends ChangeLogSet.Entry>>singletonList(cs);
}
public R asRun() {
return (R) AbstractBuild.this;
}
};
@Override
@Nonnull public List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets() {
ChangeLogSet<? extends Entry> cs = getChangeSet();
return cs.isEmptySet() ? Collections.emptyList() : Collections.singletonList(cs);
}
@Override protected final BuildReference<R> createReference() {
......@@ -336,37 +331,11 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
return getParent().getScm().getModuleRoots(ws, this);
}
/**
* List of users who committed a change since the last non-broken build till now.
*
* <p>
* This list at least always include people who made changes in this build, but
* if the previous build was a failure it also includes the culprit list from there.
*
* @return
* can be empty but never null.
*/
@Override
@Exported
@Nonnull public Set<User> getCulprits() {
return getRunWithSCMMixIn().getCulprits();
}
@Override
@CheckForNull public Set<String> getCulpritIds() {
return culprits;
}
/**
* Returns true if this user has made a commit to this build.
*
* @since 1.191
*/
@Override
public boolean hasParticipant(User user) {
return getRunWithSCMMixIn().hasParticipant(user);
}
/**
* Gets the version of Hudson that was used to build this job.
*
......@@ -857,11 +826,6 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
return cs;
}
@Override
@Nonnull public List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets() {
return getRunWithSCMMixIn().getChangeSets();
}
/**
* Returns true if the changelog is already computed.
*/
......
......@@ -91,7 +91,7 @@ import jenkins.model.ModelObjectWithChildren;
import jenkins.model.ProjectNamingStrategy;
import jenkins.model.RunIdMigrator;
import jenkins.model.lazy.LazyBuildMixIn;
import jenkins.scm.RunWithSCMMixIn;
import jenkins.scm.RunWithSCM;
import jenkins.security.HexStringConfidentialKey;
import jenkins.triggers.SCMTriggerItem;
import net.sf.json.JSONException;
......@@ -1079,8 +1079,8 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
for (RunT r = getLastBuild(); r != null; r = r.getPreviousBuild()) {
int idx = 0;
if (r instanceof RunWithSCMMixIn.RunWithSCM) {
for (ChangeLogSet<? extends ChangeLogSet.Entry> c : ((RunWithSCMMixIn.RunWithSCM<?,?>) r).getChangeSets()) {
if (r instanceof RunWithSCM) {
for (ChangeLogSet<? extends ChangeLogSet.Entry> c : ((RunWithSCM<?,?>) r).getChangeSets()) {
for (ChangeLogSet.Entry e : c) {
entries.add(new FeedItem(e, idx++));
}
......
......@@ -63,6 +63,7 @@ import jenkins.model.ModelObjectWithContextMenu;
import jenkins.model.item_category.Categories;
import jenkins.model.item_category.Category;
import jenkins.model.item_category.ItemCategory;
import jenkins.scm.RunWithSCM;
import jenkins.triggers.SCMTriggerItem;
import jenkins.util.ProgressiveRendering;
import jenkins.util.xml.XMLUtils;
......@@ -116,7 +117,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static jenkins.scm.RunWithSCMMixIn.*;
import static jenkins.scm.RunWithSCM.*;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
......
......@@ -33,7 +33,6 @@ import hudson.model.Run;
import hudson.model.User;
import hudson.scm.ChangeLogSet;
import hudson.util.AdaptedIterator;
import jenkins.triggers.SCMTriggerItem;
import jenkins.util.SystemProperties;
import org.kohsuke.stapler.export.Exported;
......@@ -51,16 +50,16 @@ import java.util.logging.Logger;
/**
* @since FIXME
*/
public abstract class RunWithSCMMixIn<JobT extends Job<JobT, RunT> & Queue.Task,
RunT extends Run<JobT, RunT> & RunWithSCMMixIn.RunWithSCM<JobT, RunT> & Queue.Executable> {
public interface RunWithSCM<JobT extends Job<JobT, RunT> & Queue.Task,
RunT extends Run<JobT, RunT> & RunWithSCM<JobT,RunT> & Queue.Executable> {
/**
* Set if we want the blame information to flow from upstream to downstream build.
*/
private static final boolean upstreamCulprits = SystemProperties.getBoolean("hudson.upstreamCulprits");
boolean upstreamCulprits = SystemProperties.getBoolean("hudson.upstreamCulprits");
protected abstract RunT asRun();
RunT asRun();
public abstract List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets();
List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets();
/**
* List of users who committed a change since the last non-broken build till now.
......@@ -73,8 +72,8 @@ public abstract class RunWithSCMMixIn<JobT extends Job<JobT, RunT> & Queue.Task,
* can be empty but never null.
*/
@Exported
@Nonnull public Set<User> getCulprits() {
if (asRun().getCulpritIds() == null) {
@Nonnull default Set<User> getCulprits() {
if (getCulpritIds() == null) {
Set<User> r = new HashSet<User>();
RunT p = asRun().getPreviousCompletedBuild();
if (p != null && asRun().isBuilding()) {
......@@ -112,7 +111,7 @@ public abstract class RunWithSCMMixIn<JobT extends Job<JobT, RunT> & Queue.Task,
return new AbstractSet<User>() {
public Iterator<User> iterator() {
return new AdaptedIterator<String,User>(asRun().getCulpritIds().iterator()) {
return new AdaptedIterator<String,User>(getCulpritIds().iterator()) {
protected User adapt(String id) {
return User.get(id);
}
......@@ -120,7 +119,7 @@ public abstract class RunWithSCMMixIn<JobT extends Job<JobT, RunT> & Queue.Task,
}
public int size() {
return asRun().getCulpritIds().size();
return getCulpritIds().size();
}
};
}
......@@ -128,7 +127,7 @@ public abstract class RunWithSCMMixIn<JobT extends Job<JobT, RunT> & Queue.Task,
/**
* Returns true if this user has made a commit to this build.
*/
public boolean hasParticipant(User user) {
default boolean hasParticipant(User user) {
for (ChangeLogSet<? extends ChangeLogSet.Entry> c : getChangeSets()) {
for (ChangeLogSet.Entry e : c)
try {
......@@ -141,21 +140,8 @@ public abstract class RunWithSCMMixIn<JobT extends Job<JobT, RunT> & Queue.Task,
return false;
}
public interface RunWithSCM<JobT extends Job<JobT, RunT> & Queue.Task,
RunT extends Run<JobT, RunT> & RunWithSCM<JobT,RunT> & Queue.Executable> {
@Nonnull
List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets();
@CheckForNull
Set<String> getCulpritIds();
@Nonnull
Set<User> getCulprits();
@CheckForNull
Set<String> getCulpritIds();
RunWithSCMMixIn<JobT,RunT> getRunWithSCMMixIn();
boolean hasParticipant(User user);
}
private static final Logger LOGGER = Logger.getLogger(RunWithSCMMixIn.class.getName());
Logger LOGGER = Logger.getLogger(RunWithSCM.class.getName());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册