提交 14dbcd88 编写于 作者: K Kohsuke Kawaguchi

Renamed Runner family into *Execution.

... so that we can expose them as an object that keeps track of
execution-scoped objects.
上级 fba43bf5
......@@ -273,7 +273,7 @@ public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> {
@Override
public void run() {
run(new RunnerImpl());
execute(new MatrixBuildExecution());
}
@Override
......@@ -284,7 +284,7 @@ public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> {
return rs;
}
private class RunnerImpl extends AbstractRunner {
private class MatrixBuildExecution extends AbstractBuildExecution {
private final List<MatrixAggregator> aggregators = new ArrayList<MatrixAggregator>();
protected Result doRun(BuildListener listener) throws Exception {
......
......@@ -58,8 +58,6 @@ import hudson.util.CopyOnWriteMap;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import hudson.util.FormValidation.Kind;
import jenkins.scm.DefaultSCMCheckoutStrategyImpl;
import jenkins.scm.SCMCheckoutStrategy;
import jenkins.scm.SCMCheckoutStrategyDescriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.HttpResponse;
......@@ -188,7 +186,7 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
/**
* Gets the workspace location that {@link MatrixConfiguration} uses.
*
* @see MatrixRun.RunnerImpl#decideWorkspace(Node, WorkspaceList)
* @see MatrixRun.MatrixRunExecution#decideWorkspace(Node, WorkspaceList)
*
* @return never null
* even when {@link MatrixProject} uses no custom workspace, this method still
......
......@@ -143,10 +143,10 @@ public class MatrixRun extends Build<MatrixConfiguration,MatrixRun> {
@Override
public void run() {
run(new RunnerImpl());
execute(new MatrixRunExecution());
}
private class RunnerImpl extends Build<MatrixConfiguration,MatrixRun>.RunnerImpl {
private class MatrixRunExecution extends BuildExecution {
protected Lease getParentWorkspaceLease(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
MatrixProject mp = getParent().getParent();
......
......@@ -241,7 +241,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
*
* <p>
* Note to implementors: to control where the workspace is created, override
* {@link AbstractRunner#decideWorkspace(Node,WorkspaceList)}.
* {@link AbstractBuildExecution#decideWorkspace(Node,WorkspaceList)}.
*
* @return
* null if the workspace is on a slave that's not connected. Note that once the build is completed,
......@@ -257,7 +257,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
}
/**
* Normally, a workspace is assigned by {@link Runner}, but this lets you set the workspace in case
* Normally, a workspace is assigned by {@link RunExecution}, but this lets you set the workspace in case
* {@link AbstractBuild} is created without a build.
*/
protected void setWorkspace(FilePath ws) {
......@@ -407,7 +407,20 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
Util.createSymlink(getProject().getBuildDir(),"builds/"+getId(),"../"+name,listener);
}
public abstract class AbstractRunner extends Runner {
/**
* @deprecated as of 1.467
* Please use {@link RunExecution}
*/
public abstract class AbstractRunner extends AbstractBuildExecution {
}
public abstract class AbstractBuildExecution extends Runner {
/*
Some plugins might depend on this instance castable to Runner, so we need to use
deprecated class here.
*/
/**
* Since configuration can be changed while a build is in progress,
* create a launcher once and stick to it for the entire build duration.
......
......@@ -23,11 +23,14 @@
*/
package hudson.model;
import hudson.Launcher;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.Builder;
import hudson.tasks.Recorder;
import hudson.tasks.Notifier;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.io.File;
import java.io.IOException;
......@@ -107,14 +110,32 @@ public abstract class Build <P extends Project<P,B>,B extends Build<P,B>>
//
@Override
public void run() {
run(createRunner());
execute(createRunner());
}
/**
* @deprecated as of 1.467
* Override the {@link #run()} method by calling {@link #execute(RunExecution)} with
* proper execution object.
*/
@Restricted(NoExternalUse.class)
protected Runner createRunner() {
return new RunnerImpl();
return new BuildExecution();
}
/**
* @deprecated as of 1.467
* Please use {@link BuildExecution}
*/
protected class RunnerImpl extends BuildExecution {
}
protected class RunnerImpl extends AbstractRunner {
protected class BuildExecution extends AbstractRunner {
/*
Some plugins might depend on this instance castable to Runner, so we need to use
deprecated class here.
*/
protected Result doRun(BuildListener listener) throws Exception {
if(!preBuild(listener,project.getBuilders()))
return FAILURE;
......
......@@ -63,7 +63,7 @@ public class ExternalRun extends Run<ExternalJob,ExternalRun> {
* record the log and its exit code, then call it a build.
*/
public void run(final String[] cmd) {
run(new Runner() {
execute(new RunExecution() {
public Result run(BuildListener listener) throws Exception {
Proc proc = new Proc.LocalProc(cmd,getEnvironment(listener),System.in,new DualOutputStream(System.out,listener.getLogger()));
return proc.join()==0?Result.SUCCESS:Result.FAILURE;
......@@ -97,7 +97,7 @@ public class ExternalRun extends Run<ExternalJob,ExternalRun> {
@IgnoreJRERequirement
public void acceptRemoteSubmission(final Reader in) throws IOException {
final long[] duration = new long[1];
run(new Runner() {
execute(new RunExecution() {
private String elementText(XMLStreamReader r) throws XMLStreamException {
StringBuilder buf = new StringBuilder();
while(true) {
......
......@@ -43,6 +43,6 @@ public class FreeStyleBuild extends Build<FreeStyleProject,FreeStyleBuild> {
@Override
public void run() {
run(new RunnerImpl());
execute(new BuildExecution());
}
}
......@@ -238,10 +238,10 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
private boolean keepLog;
/**
* If the build is in progress, remember {@link Runner} that's running it.
* If the build is in progress, remember {@link RunExecution} that's running it.
* This field is not persisted.
*/
private volatile transient Runner runner;
private volatile transient RunExecution runner;
protected static final ThreadLocal<SimpleDateFormat> ID_FORMATTER =
new ThreadLocal<SimpleDateFormat>() {
......@@ -1282,7 +1282,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
while(true) {
Run b = RunnerStack.INSTANCE.peek().getBuild().getPreviousBuildInProgress();
if(b==null) return; // no pending earlier build
Run.Runner runner = b.runner;
Run.RunExecution runner = b.runner;
if(runner==null) {
// polled at the wrong moment. try again.
Thread.sleep(0);
......@@ -1295,14 +1295,24 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
}
}
protected abstract class Runner {
/**
* @deprecated as of 1.467
* Please use {@link RunExecution}
*/
protected abstract class Runner extends RunExecution {}
/**
* Object that lives while the build is executed, to keep track of things that
* are needed only during the build.
*/
public abstract class RunExecution {
/**
* Keeps track of the check points attained by a build, and abstracts away the synchronization needed to
* maintain this data structure.
*/
private final class CheckpointSet {
/**
* Stages of the builds that this runner has completed. This is used for concurrent {@link Runner}s to
* Stages of the builds that this runner has completed. This is used for concurrent {@link RunExecution}s to
* coordinate and serialize their executions where necessary.
*/
private final Set<CheckPoint> checkpoints = new HashSet<CheckPoint>();
......@@ -1376,7 +1386,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
}
/**
* Used in {@link Runner#run} to indicates that a fatal error in a build
* Used in {@link RunExecution#run} to indicates that a fatal error in a build
* is reported to {@link BuildListener} and the build should be simply aborted
* without further recording a stack trace.
*/
......@@ -1384,7 +1394,15 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
private static final long serialVersionUID = 1L;
}
/**
* @deprecated as of 1.467
* Use {@link #execute(RunExecution)}
*/
protected final void run(Runner job) {
execute(job);
}
protected final void execute(RunExecution job) {
if(result!=null)
return; // already built.
......
......@@ -23,37 +23,37 @@
*/
package hudson.model;
import hudson.model.Run.Runner;
import hudson.model.Run.RunExecution;
import java.util.Stack;
import java.util.Map;
import java.util.WeakHashMap;
/**
* Keeps track of {@link Runner}s that are currently executing on the given thread
* Keeps track of {@link RunExecution}s that are currently executing on the given thread
* (that can be either an {@link Executor} or threads that are impersonating one.)
*
* @author Kohsuke Kawaguchi
* @since 1.319
*/
final class RunnerStack {
private final Map<Executor,Stack<Runner>> stack = new WeakHashMap<Executor,Stack<Runner>>();
private final Map<Executor,Stack<RunExecution>> stack = new WeakHashMap<Executor,Stack<RunExecution>>();
synchronized void push(Runner r) {
synchronized void push(RunExecution r) {
Executor e = Executor.currentExecutor();
Stack<Runner> s = stack.get(e);
if(s==null) stack.put(e,s=new Stack<Runner>());
Stack<RunExecution> s = stack.get(e);
if(s==null) stack.put(e,s=new Stack<RunExecution>());
s.push(r);
}
synchronized void pop() {
Executor e = Executor.currentExecutor();
Stack<Runner> s = stack.get(e);
Stack<RunExecution> s = stack.get(e);
s.pop();
if(s.isEmpty()) stack.remove(e);
}
synchronized Runner peek() {
synchronized RunExecution peek() {
return stack.get(Executor.currentExecutor()).peek();
}
......
......@@ -5,6 +5,7 @@ import hudson.Launcher;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;
import hudson.model.AbstractBuild;
import hudson.model.AbstractBuild.AbstractBuildExecution;
import hudson.model.AbstractDescribableImpl;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
......@@ -83,8 +84,8 @@ public abstract class SCMCheckoutStrategy extends AbstractDescribableImpl<SCMChe
*
* See {@link #preCheckout(AbstractBuild, Launcher, BuildListener)} for the semantics of the parameters.
*/
public void checkout(AbstractBuild.AbstractRunner runner) throws IOException, InterruptedException {
runner.defaultCheckout();
public void checkout(AbstractBuildExecution execution) throws IOException, InterruptedException {
execution.defaultCheckout();
}
@Override
......
......@@ -25,7 +25,6 @@ package hudson.maven;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.maven.local_repo.LocalRepositoryLocator;
import hudson.maven.reporters.MavenArtifactRecord;
import hudson.maven.reporters.SurefireArchiver;
import hudson.slaves.WorkspaceList;
......@@ -246,7 +245,7 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
@Override
public void run() {
run(new RunnerImpl());
execute(new MavenBuildExecution());
getProject().updateTransientActions();
......@@ -543,7 +542,7 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
// failed before it didn't even get to this module
// OR if the aggregated build is an incremental one and this
// module needn't be build.
run(new Runner() {
MavenBuild.this.execute(new RunExecution() {
public Result run(BuildListener listener) {
listener.getLogger().println(Messages.MavenBuild_FailedEarlier());
return Result.NOT_BUILT;
......@@ -642,7 +641,7 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
private class RunnerImpl extends AbstractRunner {
private class MavenBuildExecution extends AbstractBuildExecution {
private List<MavenReporter> reporters;
@Override
......
......@@ -474,7 +474,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
public void run() {
run(new RunnerImpl());
execute(new MavenModuleSetBuildExecution());
getProject().updateTransientActions();
}
......@@ -554,7 +554,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
* The sole job of the {@link MavenModuleSet} build is to update SCM
* and triggers module builds.
*/
private class RunnerImpl extends AbstractRunner {
private class MavenModuleSetBuildExecution extends AbstractBuildExecution {
private Map<ModuleName,MavenBuild.ProxyImpl2> proxies;
protected Result doRun(final BuildListener listener) throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册