提交 a197999c 编写于 作者: C CloudBees DEV@Cloud

Merge commit '52c28ae3'

...@@ -111,6 +111,7 @@ import java.util.regex.Pattern; ...@@ -111,6 +111,7 @@ import java.util.regex.Pattern;
import static hudson.FilePath.TarCompression.*; import static hudson.FilePath.TarCompression.*;
import static hudson.Util.*; import static hudson.Util.*;
import javax.annotation.Nonnull;
/** /**
* {@link File} like object with remoting support. * {@link File} like object with remoting support.
...@@ -1161,7 +1162,7 @@ public final class FilePath implements Serializable { ...@@ -1161,7 +1162,7 @@ public final class FilePath implements Serializable {
* @param relOrAbsolute a relative or absolute path * @param relOrAbsolute a relative or absolute path
* @return a file on the same channel * @return a file on the same channel
*/ */
public FilePath child(String relOrAbsolute) { public @Nonnull FilePath child(String relOrAbsolute) {
return new FilePath(this,relOrAbsolute); return new FilePath(this,relOrAbsolute);
} }
......
...@@ -292,7 +292,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs ...@@ -292,7 +292,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
* Normally, a workspace is assigned by {@link hudson.model.Run.RunExecution}, but this lets you set the workspace in case * Normally, a workspace is assigned by {@link hudson.model.Run.RunExecution}, but this lets you set the workspace in case
* {@link AbstractBuild} is created without a build. * {@link AbstractBuild} is created without a build.
*/ */
protected void setWorkspace(FilePath ws) { protected void setWorkspace(@Nonnull FilePath ws) {
this.workspace = ws.getRemote(); this.workspace = ws.getRemote();
} }
......
...@@ -1432,7 +1432,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1432,7 +1432,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
} }
} }
private PollingResult pollWithWorkspace(TaskListener listener, SCM scm, R lb, FilePath ws, WorkspaceList l) throws InterruptedException, IOException { private PollingResult pollWithWorkspace(TaskListener listener, SCM scm, R lb, @Nonnull FilePath ws, WorkspaceList l) throws InterruptedException, IOException {
// if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace. // if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace.
// this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319. // this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319.
// //
......
...@@ -32,6 +32,7 @@ import java.util.HashMap; ...@@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.Nonnull;
/** /**
* Used by {@link Computer} to keep track of workspaces that are actively in use. * Used by {@link Computer} to keep track of workspaces that are actively in use.
...@@ -72,7 +73,7 @@ public final class WorkspaceList { ...@@ -72,7 +73,7 @@ public final class WorkspaceList {
*/ */
public final boolean quick; public final boolean quick;
public final FilePath path; public final @Nonnull FilePath path;
/** /**
* Multiple threads can acquire the same lock if they share the same context object. * Multiple threads can acquire the same lock if they share the same context object.
...@@ -81,11 +82,11 @@ public final class WorkspaceList { ...@@ -81,11 +82,11 @@ public final class WorkspaceList {
public int lockCount=1; public int lockCount=1;
private Entry(FilePath path, boolean quick) { private Entry(@Nonnull FilePath path, boolean quick) {
this(path,quick,new Object()); // unique context this(path,quick,new Object()); // unique context
} }
private Entry(FilePath path, boolean quick, Object context) { private Entry(@Nonnull FilePath path, boolean quick, Object context) {
this.path = path; this.path = path;
this.quick = quick; this.quick = quick;
this.context = context; this.context = context;
...@@ -104,9 +105,10 @@ public final class WorkspaceList { ...@@ -104,9 +105,10 @@ public final class WorkspaceList {
* Represents a leased workspace that needs to be returned later. * Represents a leased workspace that needs to be returned later.
*/ */
public static abstract class Lease { public static abstract class Lease {
public final FilePath path; public final @Nonnull FilePath path;
protected Lease(FilePath path) { protected Lease(@Nonnull FilePath path) {
path.getRemote(); // null check
this.path = path; this.path = path;
} }
...@@ -118,7 +120,7 @@ public final class WorkspaceList { ...@@ -118,7 +120,7 @@ public final class WorkspaceList {
/** /**
* Creates a dummy {@link Lease} object that does no-op in the release. * Creates a dummy {@link Lease} object that does no-op in the release.
*/ */
public static Lease createDummyLease(FilePath p) { public static Lease createDummyLease(@Nonnull FilePath p) {
return new Lease(p) { return new Lease(p) {
public void release() { public void release() {
// noop // noop
...@@ -130,7 +132,7 @@ public final class WorkspaceList { ...@@ -130,7 +132,7 @@ public final class WorkspaceList {
* Creates a {@link Lease} object that points to the specified path, but the lock * Creates a {@link Lease} object that points to the specified path, but the lock
* is controlled by the given parent lease object. * is controlled by the given parent lease object.
*/ */
public static Lease createLinkedDummyLease(FilePath p, final Lease parent) { public static Lease createLinkedDummyLease(@Nonnull FilePath p, final Lease parent) {
return new Lease(p) { return new Lease(p) {
public void release() { public void release() {
parent.release(); parent.release();
...@@ -151,7 +153,7 @@ public final class WorkspaceList { ...@@ -151,7 +153,7 @@ public final class WorkspaceList {
* This method doesn't block prolonged amount of time. Whenever a desired workspace * This method doesn't block prolonged amount of time. Whenever a desired workspace
* is in use, the unique variation is added. * is in use, the unique variation is added.
*/ */
public synchronized Lease allocate(FilePath base) throws InterruptedException { public synchronized Lease allocate(@Nonnull FilePath base) throws InterruptedException {
return allocate(base,new Object()); return allocate(base,new Object());
} }
...@@ -162,7 +164,7 @@ public final class WorkspaceList { ...@@ -162,7 +164,7 @@ public final class WorkspaceList {
* Threads that share the same context can re-acquire the same lock (which will just increment the lock count.) * Threads that share the same context can re-acquire the same lock (which will just increment the lock count.)
* This allows related executors to share the same workspace. * This allows related executors to share the same workspace.
*/ */
public synchronized Lease allocate(FilePath base, Object context) throws InterruptedException { public synchronized Lease allocate(@Nonnull FilePath base, Object context) throws InterruptedException {
for (int i=1; ; i++) { for (int i=1; ; i++) {
FilePath candidate = i==1 ? base : base.withSuffix(COMBINATOR+i); FilePath candidate = i==1 ? base : base.withSuffix(COMBINATOR+i);
Entry e = inUse.get(candidate); Entry e = inUse.get(candidate);
...@@ -175,7 +177,7 @@ public final class WorkspaceList { ...@@ -175,7 +177,7 @@ public final class WorkspaceList {
/** /**
* Just record that this workspace is being used, without paying any attention to the synchronization support. * Just record that this workspace is being used, without paying any attention to the synchronization support.
*/ */
public synchronized Lease record(FilePath p) { public synchronized Lease record(@Nonnull FilePath p) {
if (LOGGER.isLoggable(Level.FINE)) { if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "recorded " + p, new Throwable("from " + this)); LOGGER.log(Level.FINE, "recorded " + p, new Throwable("from " + this));
} }
...@@ -188,7 +190,7 @@ public final class WorkspaceList { ...@@ -188,7 +190,7 @@ public final class WorkspaceList {
/** /**
* Releases an allocated or acquired workspace. * Releases an allocated or acquired workspace.
*/ */
private synchronized void _release(FilePath p) { private synchronized void _release(@Nonnull FilePath p) {
Entry old = inUse.get(p); Entry old = inUse.get(p);
if (old==null) if (old==null)
throw new AssertionError("Releasing unallocated workspace "+p); throw new AssertionError("Releasing unallocated workspace "+p);
...@@ -207,7 +209,7 @@ public final class WorkspaceList { ...@@ -207,7 +209,7 @@ public final class WorkspaceList {
* @return * @return
* The same {@link FilePath} as given to this method. * The same {@link FilePath} as given to this method.
*/ */
public synchronized Lease acquire(FilePath p) throws InterruptedException { public synchronized Lease acquire(@Nonnull FilePath p) throws InterruptedException {
return acquire(p,false); return acquire(p,false);
} }
...@@ -218,7 +220,7 @@ public final class WorkspaceList { ...@@ -218,7 +220,7 @@ public final class WorkspaceList {
* If true, indicates that the acquired workspace will be returned quickly. * If true, indicates that the acquired workspace will be returned quickly.
* This makes other calls to {@link #allocate(FilePath)} to wait for the release of this workspace. * This makes other calls to {@link #allocate(FilePath)} to wait for the release of this workspace.
*/ */
public synchronized Lease acquire(FilePath p, boolean quick) throws InterruptedException { public synchronized Lease acquire(@Nonnull FilePath p, boolean quick) throws InterruptedException {
return acquire(p,quick,new Object()); return acquire(p,quick,new Object());
} }
...@@ -229,7 +231,7 @@ public final class WorkspaceList { ...@@ -229,7 +231,7 @@ public final class WorkspaceList {
* Threads that share the same context can re-acquire the same lock (which will just increment the lock count.) * Threads that share the same context can re-acquire the same lock (which will just increment the lock count.)
* This allows related executors to share the same workspace. * This allows related executors to share the same workspace.
*/ */
public synchronized Lease acquire(FilePath p, boolean quick, Object context) throws InterruptedException { public synchronized Lease acquire(@Nonnull FilePath p, boolean quick, Object context) throws InterruptedException {
Entry e; Entry e;
Thread t = Thread.currentThread(); Thread t = Thread.currentThread();
...@@ -257,7 +259,7 @@ public final class WorkspaceList { ...@@ -257,7 +259,7 @@ public final class WorkspaceList {
/** /**
* Wraps a path into a valid lease. * Wraps a path into a valid lease.
*/ */
private Lease lease(FilePath p) { private Lease lease(@Nonnull FilePath p) {
return new Lease(p) { return new Lease(p) {
public void release() { public void release() {
_release(path); _release(path);
......
...@@ -419,7 +419,9 @@ public class ProjectTest { ...@@ -419,7 +419,9 @@ public class ProjectTest {
FreeStyleProject p = j.createFreeStyleProject("project"); FreeStyleProject p = j.createFreeStyleProject("project");
Slave slave = j.createOnlineSlave(); Slave slave = j.createOnlineSlave();
AbstractBuild build = p.createExecutable(); AbstractBuild build = p.createExecutable();
FilePath path = slave.toComputer().getWorkspaceList().allocate(slave.getWorkspaceFor(p), build).path; FilePath ws = slave.getWorkspaceFor(p);
assertNotNull(ws);
FilePath path = slave.toComputer().getWorkspaceList().allocate(ws, build).path;
build.setWorkspace(path); build.setWorkspace(path);
BuildListener listener = new StreamBuildListener(BuildListener.NULL.getLogger(), Charset.defaultCharset()); BuildListener listener = new StreamBuildListener(BuildListener.NULL.getLogger(), Charset.defaultCharset());
assertTrue("Project with null smc should perform checkout without problems.", p.checkout(build, new RemoteLauncher(listener, slave.getChannel(), true), listener, new File(build.getRootDir(),"changelog.xml"))); assertTrue("Project with null smc should perform checkout without problems.", p.checkout(build, new RemoteLauncher(listener, slave.getChannel(), true), listener, new File(build.getRootDir(),"changelog.xml")));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册