Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jun 7, 2016
1 parent 405c86a commit 310c952
Show file tree
Hide file tree
Showing 4 changed files with 51 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
20 changes: 20 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,12 @@ public void onCompleted(R r, @Nonnull TaskListener listener) {}
*/
public void onFinalized(R r) {}

/**
* Called when a Run is entering execution.
* @param r
*/
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 +213,18 @@ public static void fireCompleted(Run r, @Nonnull TaskListener listener) {
}
}

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 +282,5 @@ private static void report(Throwable e) {
}

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

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

public TaskListener getListener() {
return taskListener;
}

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

0 comments on commit 310c952

Please sign in to comment.