提交 ceb36b54 编写于 作者: N Nicolas De loof

Merge pull request #2395 from ndeloof/one-shot-6

[JENKINS-34923]
......@@ -1014,7 +1014,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* Called by {@link Executor} to kill excessive executors from this computer.
*/
/*package*/ void removeExecutor(final Executor e) {
protected void removeExecutor(final Executor e) {
final Runnable task = new Runnable() {
@Override
public void run() {
......
......@@ -1701,28 +1701,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
charset = computer.getDefaultCharset();
this.charset = charset.name();
}
// don't do buffering so that what's written to the listener
// gets reflected to the file immediately, which can then be
// served to the browser immediately
OutputStream logger = new FileOutputStream(getLogFile());
RunT build = job.getBuild();
// Global log filters
for (ConsoleLogFilter filter : ConsoleLogFilter.all()) {
logger = filter.decorateLogger(build, logger);
}
// Project specific log filters
if (project instanceof BuildableItemWithBuildWrappers && build instanceof AbstractBuild) {
BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
for (BuildWrapper bw : biwbw.getBuildWrappersList()) {
logger = bw.decorateLogger((AbstractBuild) build, logger);
}
}
listener = new StreamBuildListener(logger,charset);
listener = createBuildListener(job, listener, charset);
listener.started(getCauses());
Authentication auth = Jenkins.getAuthentication();
......@@ -1811,6 +1790,30 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
}
}
private StreamBuildListener createBuildListener(@Nonnull RunExecution job, StreamBuildListener listener, Charset charset) throws IOException, InterruptedException {
// don't do buffering so that what's written to the listener
// gets reflected to the file immediately, which can then be
// served to the browser immediately
OutputStream logger = new FileOutputStream(getLogFile(), true);
RunT build = job.getBuild();
// Global log filters
for (ConsoleLogFilter filter : ConsoleLogFilter.all()) {
logger = filter.decorateLogger(build, logger);
}
// Project specific log filters
if (project instanceof BuildableItemWithBuildWrappers && build instanceof AbstractBuild) {
BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
for (BuildWrapper bw : biwbw.getBuildWrappersList()) {
logger = bw.decorateLogger((AbstractBuild) build, logger);
}
}
listener = new StreamBuildListener(logger,charset);
return listener;
}
/**
* Makes sure that {@code lastSuccessful} and {@code lastStable} legacy links in the project’s root directory exist.
* Normally you do not need to call this explicitly, since {@link #execute} does so,
......@@ -1868,6 +1871,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
startTime = System.currentTimeMillis();
if (runner!=null)
RunnerStack.INSTANCE.push(runner);
RunListener.fireInitialize(this);
}
/**
......
......@@ -33,6 +33,7 @@ import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Environment;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.Run;
import hudson.model.Run.RunnerAbortedException;
......@@ -107,6 +108,14 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint {
*/
public void onFinalized(R r) {}
/**
* Called when a Run is entering execution.
* @param r
* The started build.
* @since 2.9
*/
public void onInitialize(R r) {}
/**
* Called when a build is started (i.e. it was in the queue, and will now start running
* on an executor)
......@@ -206,6 +215,21 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint {
}
}
/**
* Fires the {@link #onInitialize(Run)} event.
*/
public static void fireInitialize(Run r) {
for (RunListener l : all()) {
if(l.targetType.isInstance(r))
try {
l.onInitialize(r);
} catch (Throwable e) {
report(e);
}
}
}
/**
* Fires the {@link #onStarted(Run, TaskListener)} event.
*/
......@@ -263,4 +287,5 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint {
}
private static final Logger LOGGER = Logger.getLogger(RunListener.class.getName());
}
......@@ -204,6 +204,14 @@ public class SlaveComputer extends Computer {
}
}
/**
* Return the {@code TaskListener} for this SlaveComputer. Never null
* @since 2.9
*/
public TaskListener getListener() {
return taskListener;
}
@Override
public String getIcon() {
Future<?> l = lastConnectActivity;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册