[FIXED HUDSON-2786] Fix posting external job results.

Made Executor.currentExecutor() return null if current thread is not an executor,
and Computer.currentComputer() return Hudson.getInstance().toComputer() if
currentExecutor returns null (must be on master if not in an executor).
This avoids exception causing posting of external job results to fail.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14176 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
mindless committed 2009-01-06 00:25:24 +00:00
1 parent 01e9631a11
commit ea0de1dc5e
2 files changed
+6 -3

No files matched your search

@@ -521,7 +521,9 @@ public abstract class Computer extends AbstractModelObject implements AccessCont
* {@link Publisher}, {@link BuildWrapper}, etc.
*/
public static Computer currentComputer() {
return Executor.currentExecutor().getOwner();
Executor e = Executor.currentExecutor();
// If no executor then must be on master node
return e != null ? e.getOwner() : Hudson.getInstance().toComputer();
}
/**
@@ -288,10 +288,11 @@ public class Executor extends Thread implements ModelObject {
}
/**
* Returns the executor of the current thread.
* Returns the executor of the current thread or null if current thread is not an executor.
*/
public static Executor currentExecutor() {
return (Executor)Thread.currentThread();
Thread t = Thread.currentThread();
return t instanceof Executor ? (Executor)t : null;
}
private static final Logger LOGGER = Logger.getLogger(Executor.class.getName());