mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
adding a new kind of listeners for Trac integration, CVS-NEWS integration, java.net issue tracker integration, etc, which all work with commit messages.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1639 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
1a96978af7
commit
fd7b5b919e
2 files changed
+103
-16
No files matched your search
@@ -12,6 +12,7 @@ import hudson.Util;
|
||||
import hudson.XmlFile;
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import hudson.model.listeners.JobListener;
|
||||
import hudson.model.listeners.SCMListener;
|
||||
import hudson.remoting.LocalChannel;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.scm.CVSSCM;
|
||||
@@ -25,6 +26,7 @@ import hudson.tasks.Mailer;
|
||||
import hudson.tasks.Publisher;
|
||||
import hudson.triggers.Trigger;
|
||||
import hudson.triggers.Triggers;
|
||||
import hudson.util.CopyOnWriteList;
|
||||
import hudson.util.FormFieldValidator;
|
||||
import hudson.util.XStream2;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
@@ -148,7 +150,12 @@ public final class Hudson extends JobCollection implements Node {
|
||||
/**
|
||||
* List of registered {@link JobListener}s.
|
||||
*/
|
||||
private transient final List<JobListener> jobListeners = new Vector<JobListener>();
|
||||
private transient final CopyOnWriteList<JobListener> jobListeners = new CopyOnWriteList<JobListener>();
|
||||
|
||||
/**
|
||||
* List of registered {@link SCMListener}s.
|
||||
*/
|
||||
private transient final CopyOnWriteList<SCMListener> scmListeners = new CopyOnWriteList<SCMListener>();
|
||||
|
||||
public static Hudson getInstance() {
|
||||
return theInstance;
|
||||
@@ -174,10 +181,8 @@ public final class Hudson extends JobCollection implements Node {
|
||||
|
||||
getQueue().load();
|
||||
|
||||
synchronized(jobListeners) {
|
||||
for (JobListener l : jobListeners)
|
||||
l.onLoaded();
|
||||
}
|
||||
for (JobListener l : jobListeners)
|
||||
l.onLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +244,8 @@ public final class Hudson extends JobCollection implements Node {
|
||||
/**
|
||||
* Adds a new {@link JobListener}.
|
||||
*
|
||||
* @see #removeListener(JobListener)
|
||||
* @deprecated
|
||||
* Use {@code getJobListners().add(l)} instead.
|
||||
*/
|
||||
public void addListener(JobListener l) {
|
||||
jobListeners.add(l);
|
||||
@@ -248,13 +254,27 @@ public final class Hudson extends JobCollection implements Node {
|
||||
/**
|
||||
* Deletes an existing {@link JobListener}.
|
||||
*
|
||||
* @return
|
||||
* true if the listener was indeed registered.
|
||||
* @deprecated
|
||||
* Use {@code getJobListners().remove(l)} instead.
|
||||
*/
|
||||
public boolean removeListener(JobListener l ) {
|
||||
return jobListeners.remove(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the installed {@link JobListener}s.
|
||||
*/
|
||||
public CopyOnWriteList<JobListener> getJobListeners() {
|
||||
return jobListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the installed {@link SCMListener}s.
|
||||
*/
|
||||
public CopyOnWriteList<SCMListener> getSCMListeners() {
|
||||
return scmListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin object from its short name.
|
||||
*
|
||||
@@ -607,10 +627,8 @@ public final class Hudson extends JobCollection implements Node {
|
||||
* Called in response to {@link Job#doDoDelete(StaplerRequest, StaplerResponse)}
|
||||
*/
|
||||
/*package*/ void deleteJob(Job job) throws IOException {
|
||||
synchronized(jobListeners) {
|
||||
for (JobListener l : jobListeners)
|
||||
l.onDeleted(job);
|
||||
}
|
||||
for (JobListener l : jobListeners)
|
||||
l.onDeleted(job);
|
||||
|
||||
jobs.remove(job.getName());
|
||||
if(views!=null) {
|
||||
@@ -892,10 +910,8 @@ public final class Hudson extends JobCollection implements Node {
|
||||
jobs.put(name,result);
|
||||
}
|
||||
|
||||
synchronized(jobListeners) {
|
||||
for (JobListener l : jobListeners)
|
||||
l.onCreated(result);
|
||||
}
|
||||
for (JobListener l : jobListeners)
|
||||
l.onCreated(result);
|
||||
|
||||
rsp.sendRedirect2(req.getContextPath()+'/'+result.getUrl()+"configure");
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package hudson.model.listeners;
|
||||
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.scm.SCM;
|
||||
import hudson.scm.ChangeLogSet;
|
||||
|
||||
/**
|
||||
* Receives notifications about SCM activities in Hudson.
|
||||
*
|
||||
* <p>
|
||||
* This is an abstract class so that methods added in the future won't break existing listeners.
|
||||
*
|
||||
* <p>
|
||||
* Once instanciated, use the {@link #register()} method to start receiving events.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @see Hudson#getSCMListeners()
|
||||
* @since 1.70
|
||||
*/
|
||||
public abstract class SCMListener {
|
||||
/**
|
||||
* Called once the changelog is determined.
|
||||
*
|
||||
* <p>
|
||||
* During a build, Hudson fetches the update of the workspace from SCM,
|
||||
* and determines the changelog (see {@link SCM#checkout}). Immediately
|
||||
* after that, a build will invoke this method on all registered
|
||||
* {@link SCMListener}s.
|
||||
*
|
||||
* <p>
|
||||
* This is an opportunity for SCM-related plugins to act on changelog.
|
||||
* A typical usage includes parsing commit messages and do cross-referencing
|
||||
* between other systems.
|
||||
*
|
||||
* <p>
|
||||
* If a build failed before we successfully determine changelog, this method
|
||||
* will not be invoked (for example, if "cvs update" failed.) OTOH, this method
|
||||
* is invoked before the actual build (like ant invocation) happens.
|
||||
*
|
||||
* <p>
|
||||
* TODO: once we have cvsnews plugin, refer to its usage.
|
||||
*
|
||||
* @param build
|
||||
* The build in progress, which just finished determining changelog.
|
||||
* At this point this build is still in progress. Never null.
|
||||
* @param changelog
|
||||
* Set of changes detected in this build. This is the same value
|
||||
* returned from {@link AbstractBuild#getChangeSet()} but passed
|
||||
* separately for convenience.
|
||||
*/
|
||||
public void onChangeLogParsed(AbstractBuild<?,?> build, ChangeLogSet<?> changelog) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this {@link SCMListener} so that it will start receiving events.
|
||||
*/
|
||||
public final void register() {
|
||||
Hudson.getInstance().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.
|
||||
*/
|
||||
public final boolean unregister() {
|
||||
return Hudson.getInstance().getSCMListeners().remove(this);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user