added a event callback interface for job creation/deletion.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1276 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2006-12-09 18:33:45 +00:00
1 parent 144f16ffb2
commit dc1afa8cdf
2 files changed
+64

No files matched your search

@@ -9,6 +9,7 @@ import hudson.PluginWrapper;
import hudson.Util;
import hudson.XmlFile;
import hudson.model.Descriptor.FormException;
import hudson.model.listeners.JobListener;
import hudson.scm.CVSSCM;
import hudson.scm.SCM;
import hudson.scm.SCMS;
@@ -141,6 +142,11 @@ public final class Hudson extends JobCollection implements Node {
*/
public transient final PluginManager pluginManager;
/**
* List of reigstered {@link JobListener}s.
*/
private transient List<JobListener> jobListeners = new Vector<JobListener>();
public static Hudson getInstance() {
return theInstance;
}
@@ -218,6 +224,25 @@ public final class Hudson extends JobCollection implements Node {
return null;
}
/**
* Adds a new {@link JobListener}.
*
* @see #removeListener(JobListener)
*/
public void addListener(JobListener l) {
jobListeners.add(l);
}
/**
* Deletes an existing {@link JobListener}.
*
* @return
* true if the listener was indeed registered.
*/
public boolean removeListener(JobListener l ) {
return jobListeners.remove(l);
}
/**
* Gets the plugin object from its short name.
*
@@ -570,6 +595,11 @@ 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);
}
jobs.remove(job.getName());
if(views!=null) {
for (View v : views) {
@@ -857,6 +887,11 @@ public final class Hudson extends JobCollection implements Node {
jobs.put(name,result);
}
synchronized(jobListeners) {
for (JobListener l : jobListeners)
l.onCreated(result);
}
rsp.sendRedirect2(req.getContextPath()+'/'+result.getUrl()+"configure");
return result;
}
@@ -0,0 +1,29 @@
package hudson.model.listeners;
import hudson.model.Job;
import hudson.model.Hudson;
/**
* Receives notifications about jobs.
*
* <p>
* This is an abstract class so that methods added in the future won't break existing listeners.
*
* @author Kohsuke Kawaguchi
* @see Hudson#addListener(JobListener)
*/
public abstract class JobListener {
/**
* Called after a new job is created and added to {@link Hudson}.
*/
public void onCreated(Job j) {
}
/**
* Called right before a job is going to be deleted.
*
* At this point the data files of the job is already gone.
*/
public void onDeleted(Job j) {
}
}