Skip to content

Commit

Permalink
Merge pull request #2395 from ndeloof/one-shot-6
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof committed Jun 9, 2016
2 parents 057791c + 97a3f71 commit ceb36b5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Computer.java
Expand Up @@ -1014,7 +1014,7 @@ public final long getDemandStartMilliseconds() {
/**
* 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() {
Expand Down
48 changes: 26 additions & 22 deletions core/src/main/java/hudson/model/Run.java
Expand Up @@ -1701,28 +1701,7 @@ protected final void execute(@Nonnull RunExecution job) {
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();
Expand Down Expand Up @@ -1811,6 +1790,30 @@ protected final void execute(@Nonnull RunExecution job) {
}
}

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,
Expand Down Expand Up @@ -1868,6 +1871,7 @@ protected void onStartBuilding() {
startTime = System.currentTimeMillis();
if (runner!=null)
RunnerStack.INSTANCE.push(runner);
RunListener.fireInitialize(this);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/hudson/model/listeners/RunListener.java
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -107,6 +108,14 @@ public void onCompleted(R r, @Nonnull TaskListener listener) {}
*/
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)
Expand Down Expand Up @@ -206,6 +215,21 @@ public static void fireCompleted(Run r, @Nonnull TaskListener listener) {
}
}

/**
* 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.
*/
Expand Down Expand Up @@ -263,4 +287,5 @@ private static void report(Throwable e) {
}

private static final Logger LOGGER = Logger.getLogger(RunListener.class.getName());

}
8 changes: 8 additions & 0 deletions core/src/main/java/hudson/slaves/SlaveComputer.java
Expand Up @@ -204,6 +204,14 @@ public Slave getNode() {
}
}

/**
* Return the {@code TaskListener} for this SlaveComputer. Never null
* @since 2.9
*/
public TaskListener getListener() {
return taskListener;
}

@Override
public String getIcon() {
Future<?> l = lastConnectActivity;
Expand Down

0 comments on commit ceb36b5

Please sign in to comment.