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

Modernizing SCMListener registration.

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