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);
+ }
+ }
}