diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index c195d9855f7a2f7fddfbb57b607f919a581aa2ea..aec68e72efee334306e237b8c4e112f346c6e9bd 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -605,7 +605,7 @@ public abstract class AbstractBuild

,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

,R extends Abs build.scm = scm.createChangeLogParser(); build.changeSet = new WeakReference>(build.calcChangeSet()); - for (SCMListener l : Jenkins.getInstance().getSCMListeners()) + for (SCMListener l : SCMListener.all()) try { l.onChangeLogParsed(build,listener,build.getChangeSet()); } catch (Exception e) { diff --git a/core/src/main/java/hudson/model/listeners/SCMListener.java b/core/src/main/java/hudson/model/listeners/SCMListener.java index ee66d354b7c1720f4996db8bbcece2e6b5cd09e6..b2f56a8f411b4228ad7e7d58cbe5b5908c28ad54 100644 --- a/core/src/main/java/hudson/model/listeners/SCMListener.java +++ b/core/src/main/java/hudson/model/listeners/SCMListener.java @@ -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 all() { + Jenkins j = Jenkins.getInstance(); + if (j == null) { + return Collections.emptySet(); + } + List r = new ArrayList(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. - * - *

- * 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; + } } } diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 556660c495ff9f6db7f7f4cada4d29fa03eea1b3..139dc5501ce6c773faa37d7205dda7c91511740c 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -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 getSCMListeners() { return scmListeners; }