提交 7672f00b 编写于 作者: J Jesse Glick

Modernizing SCMListener registration.

上级 bda00bdb
......@@ -605,7 +605,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
if (project.checkout(build, launcher,listener, changeLogFile)) {
// check out succeeded
SCM scm = project.getScm();
for (SCMListener l : Jenkins.getInstance().getSCMListeners()) {
for (SCMListener l : SCMListener.all()) {
try {
l.onCheckout(build, scm, build.getWorkspace(), listener, changeLogFile, project.pollingBaseline);
} catch (Exception e) {
......@@ -616,7 +616,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
build.scm = scm.createChangeLogParser();
build.changeSet = new WeakReference<ChangeLogSet<? extends Entry>>(build.calcChangeSet());
for (SCMListener l : Jenkins.getInstance().getSCMListeners())
for (SCMListener l : SCMListener.all())
try {
l.onChangeLogParsed(build,listener,build.getChangeSet());
} catch (Exception e) {
......
......@@ -23,6 +23,7 @@
*/
package hudson.model.listeners;
import hudson.Extension;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Launcher;
......@@ -36,6 +37,10 @@ import hudson.scm.ChangeLogSet;
import hudson.scm.SCM;
import hudson.scm.SCMRevisionState;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.CheckForNull;
import jenkins.model.Jenkins;
......@@ -113,20 +118,36 @@ public abstract class SCMListener implements ExtensionPoint {
onChangeLogParsed((Run) build, build.getProject().getScm(), listener, changelog);
}
/**
* Registers this {@link SCMListener} so that it will start receiving events.
*/
@SuppressWarnings("deprecation")
public static Collection<? extends SCMListener> all() {
Jenkins j = Jenkins.getInstance();
if (j == null) {
return Collections.emptySet();
}
List<SCMListener> r = new ArrayList<SCMListener>(j.getExtensionList(SCMListener.class));
for (SCMListener l : j.getSCMListeners()) {
r.add(l);
}
return r;
}
/** @deprecated Use {@link Extension} instead. */
@Deprecated
public final void register() {
Jenkins.getInstance().getSCMListeners().add(this);
Jenkins j = Jenkins.getInstance();
if (j != null) {
j.getSCMListeners().add(this);
}
}
/**
* Unregisters this {@link SCMListener} so that it will never receive further events.
*
* <p>
* Unless {@link SCMListener} is unregistered, it will never be a subject of GC.
*/
/** @deprecated Use {@link Extension} instead. */
@Deprecated
public final boolean unregister() {
return Jenkins.getInstance().getSCMListeners().remove(this);
Jenkins j = Jenkins.getInstance();
if (j != null) {
return j.getSCMListeners().remove(this);
} else {
return false;
}
}
}
......@@ -1220,9 +1220,8 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
updateComputerList(AUTOMATIC_SLAVE_LAUNCH);
}
/**
* Gets all the installed {@link SCMListener}s.
*/
/** @deprecated Use {@link SCMListener#all} instead. */
@Deprecated
public CopyOnWriteList<SCMListener> getSCMListeners() {
return scmListeners;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册