From 87bb29d14ec317d07770a014d505d8a4e9134192 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 4 Nov 2008 01:11:51 +0000 Subject: [PATCH] Fixed a race condition in the ScmTest test case. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@12974 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/model/AbstractProject.java | 2 +- core/src/main/java/hudson/model/Run.java | 1 + .../hudson/model/listeners/RunListener.java | 21 ++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 7173bad2d1..4893d3f17b 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -423,7 +423,7 @@ public abstract class AbstractProject

,R extends A Future f = new AsyncFutureImpl() { final RunListener r = new RunListener(AbstractBuild.class) { - public void onCompleted(AbstractBuild r, TaskListener listener) { + public void onFinalized(AbstractBuild r) { if(r.getProject()==AbstractProject.this && r.getNumber()>n) { set((R)r); unregister(); diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 0c465fd9a8..c54463db65 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -920,6 +920,7 @@ public abstract class Run ,RunT extends Run implements ExtensionPoint { * the build is considered completed, so its status cannot be changed anymore. */ public void onCompleted(R r, TaskListener listener) {} - + + /** + * Called after a build is moved to the {@link Run.State#COMPLETED} state. + * + *

+ * At this point, all the records related to a build is written down to the disk. As such, + * {@link TaskListener} is no longer available. This happens later than {@link #onCompleted(Run, TaskListener)}. + */ + public void onFinalized(R r) {} + /** * Called when a build is started (i.e. it was in the queue, and will now start running * on an executor) @@ -89,4 +98,14 @@ public abstract class RunListener implements ExtensionPoint { l.onStarted(r,listener); } } + + /** + * Fires the {@link #onFinalized(Run)} event. + */ + public static void fireFinalized(Run r) { + for (RunListener l : LISTENERS) { + if(l.targetType.isInstance(r)) + l.onFinalized(r); + } + } }