diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java
index 2d1bc35d4e3081ee1190075ccb8f7cd419dd1fbf..72ea53596cfa7228a67da625f98f6d53966d5a40 100644
--- a/core/src/main/java/hudson/model/AbstractBuild.java
+++ b/core/src/main/java/hudson/model/AbstractBuild.java
@@ -62,6 +62,7 @@ import hudson.util.Iterators;
import hudson.util.LogTaskListener;
import hudson.util.VariableResolver;
import jenkins.model.Jenkins;
+import jenkins.model.lazy.AbstractLazyLoadRunMap.Direction;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -170,6 +171,26 @@ public abstract class AbstractBuild
,R extends Abs
return getParent();
}
+ private boolean previousBuildComputed, nextBuildComputed;
+
+ @Override
+ public R getPreviousBuild() {
+ if (previousBuild==null && !previousBuildComputed) {
+ previousBuild = getParent().builds.search(number-1, Direction.DESC);
+ previousBuildComputed = true;
+ }
+ return previousBuild;
+ }
+
+ @Override
+ public R getNextBuild() {
+ if (nextBuild==null && !nextBuildComputed) {
+ nextBuild = getParent().builds.search(number+1, Direction.ASC);
+ nextBuildComputed = true;
+ }
+ return nextBuild;
+ }
+
/**
* Returns a {@link Slave} on which this build was done.
*
diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java
index 046e3fc7bf02440675134cf75783d24a470fa693..aa039688f83c5d8e30996ab302437dddca9be90d 100644
--- a/core/src/main/java/hudson/model/AbstractProject.java
+++ b/core/src/main/java/hudson/model/AbstractProject.java
@@ -160,7 +160,7 @@ public abstract class AbstractProject
,R extends A
* {@link Run#getPreviousBuild()}
*/
@Restricted(NoExternalUse.class)
- protected transient /*almost final*/ RunMap builds = new RunMap();
+ protected transient RunMap builds = new RunMap();
/**
* The quiet period. Null to delegate to the system default.
@@ -269,9 +269,7 @@ public abstract class AbstractProject,R extends A
public void onLoad(ItemGroup extends Item> parent, String name) throws IOException {
super.onLoad(parent, name);
- if (this.builds==null)
- this.builds = new RunMap();
- this.builds.load(this,new Constructor() {
+ this.builds = new RunMap(getBuildDir(),new Constructor() {
public R create(File dir) throws IOException {
return loadBuild(dir);
}
diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java
index eb44e7c2f416ca0dd16c6c46b8670f96b7f6a44b..9c17f985182f64ce4218a577bf2509b6b9e53451 100644
--- a/core/src/main/java/hudson/model/Run.java
+++ b/core/src/main/java/hudson/model/Run.java
@@ -44,7 +44,6 @@ import hudson.model.Descriptor.FormException;
import hudson.model.listeners.RunListener;
import hudson.model.listeners.SaveableListener;
import hudson.security.PermissionScope;
-import jenkins.model.Jenkins.MasterComputer;
import hudson.search.SearchIndexBuilder;
import hudson.security.ACL;
import hudson.security.AccessControlled;
@@ -640,10 +639,11 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run> extends AbstractLazyLoadRunMap
// patch up next/previous build link
+ /**
+ * @deprecated
+ * Use {@link #RunMap(File, Constructor)}.
+ */
public RunMap() {
super(null); // will be set later
}
+ /**
+ * @param cons
+ * Used to create new instance of {@link Run}.
+ */
+ public RunMap(File baseDir, Constructor cons) {
+ super(baseDir);
+ this.cons = cons;
+ }
+
@Override
public boolean remove(R run) {
if(run.nextBuild!=null)
@@ -179,8 +192,10 @@ public final class RunMap> extends AbstractLazyLoadRunMap
* Job that owns this map.
* @param cons
* Used to create new instance of {@link Run}.
+ * @deprecated
+ * Use {@link #RunMap(File, Constructor)}
*/
- public synchronized void load(Job job, Constructor cons) {
+ public void load(Job job, Constructor cons) {
this.cons = cons;
initBaseDir(job.getBuildDir());
}
diff --git a/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java b/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
index ae185c0b99c7e94e7c1ebede18410adf805df1d1..fff288b27c156e5981e9af291f737c6941715335 100644
--- a/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
+++ b/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
@@ -94,7 +94,6 @@ public abstract class AbstractLazyLoadRunMap extends AbstractMap i
*/
private File dir;
- @Restricted(NoExternalUse.class) // for now
protected AbstractLazyLoadRunMap(File dir) {
this.dir = dir;
initBaseDir(dir);