提交 4f9510a0 编写于 作者: K kohsuke

pushed getCause() up to Run.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20718 71c3de6d-444a-0410-be80-ed276b4c234a
上级 23ce8b70
......@@ -282,23 +282,6 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
};
}
/**
* Returns the {@link Cause}s that tirggered a build.
*
* <p>
* If a build sits in the queue for a long time, multiple build requests made during this period
* are all rolled up into one build, hence this method may return a list.
*
* @return
* can be empty but never null. read-only.
* @since 1.321
*/
public List<Cause> getCauses() {
CauseAction a = getAction(CauseAction.class);
if (a==null) return Collections.emptyList();
return Collections.unmodifiableList(a.getCauses());
}
/**
* Returns true if this user has made a commit to this build.
*
......
......@@ -34,6 +34,9 @@ public interface BuildListener extends TaskListener {
/**
* Called when a build is started.
*
* @param causes
* Causes that started a build. See {@link Run#getCauses()}.
*/
void started(List<Cause> causes);
......
......@@ -26,7 +26,6 @@ package hudson.model;
import java.util.ArrayList;
import java.util.List;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
......@@ -36,7 +35,7 @@ import org.kohsuke.stapler.export.ExportedBean;
* CauseAction object.
*
* @author Michael Donohue
* @see AbstractBuild#getCauses()
* @see Run#getCauses()
*/
@ExportedBean
public abstract class Cause {
......@@ -60,7 +59,7 @@ public abstract class Cause {
private int upstreamBuild;
@Deprecated
private transient Cause upstreamCause;
private List<Cause> upstreamCauses = new ArrayList<Cause>();
private List<Cause> upstreamCauses;
// for backward bytecode compatibility
public UpstreamCause(AbstractBuild<?,?> up) {
......@@ -71,8 +70,7 @@ public abstract class Cause {
upstreamBuild = up.getNumber();
upstreamProject = up.getParent().getName();
upstreamUrl = up.getParent().getUrl();
CauseAction ca = up.getAction(CauseAction.class);
upstreamCauses = ca == null ? null : ca.getCauses();
upstreamCauses = new ArrayList<Cause>(up.getCauses());
}
public String getUpstreamProject() {
......
......@@ -372,6 +372,23 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return Charset.forName(charset);
}
/**
* Returns the {@link Cause}s that tirggered a build.
*
* <p>
* If a build sits in the queue for a long time, multiple build requests made during this period
* are all rolled up into one build, hence this method may return a list.
*
* @return
* can be empty but never null. read-only.
* @since 1.321
*/
public List<Cause> getCauses() {
CauseAction a = getAction(CauseAction.class);
if (a==null) return Collections.emptyList();
return Collections.unmodifiableList(a.getCauses());
}
/**
* Returns true if this log file should be kept and not deleted.
*
......@@ -1079,8 +1096,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
this.charset = charset.name();
listener = new StreamBuildListener(new PrintStream(new CloseProofOutputStream(log)),charset);
CauseAction causeAction = getAction(CauseAction.class);
listener.started(causeAction!=null ? causeAction.getCauses() : null);
listener.started(getCauses());
RunListener.fireStarted(this,listener);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册