提交 ac64bcb8 编写于 作者: S StevenGBrown

[FIXED HUDSON-7112] Plugins can now transform the console output.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34008 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b228c24d
......@@ -99,6 +99,8 @@ import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import com.thoughtworks.xstream.XStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import static java.util.logging.Level.FINE;
......@@ -1236,7 +1238,20 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
try {
Charset charset = Computer.currentComputer().getDefaultCharset();
this.charset = charset.name();
listener = new StreamBuildListener(getLogFile(),charset);
// 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();
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.started(getCauses());
......
......@@ -31,6 +31,7 @@ import hudson.model.*;
import hudson.model.Run.RunnerAbortedException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
......@@ -173,6 +174,32 @@ public abstract class BuildWrapper extends AbstractDescribableImpl<BuildWrapper>
return launcher;
}
/**
* Provides an opportunity for a {@link BuildWrapper} to decorate the {@link BuildListener} logger to be used by the build.
*
* <p>
* This hook is called very early on in the build (even before {@link #setUp(AbstractBuild, Launcher, BuildListener)} is invoked.)
*
* <p>
* The default implementation is no-op, which just returns the {@code logger} parameter as-is.
*
* @param build
* The build in progress for which this {@link BuildWrapper} is called. Never null.
* @param logger
* The default logger. Never null. This method is expected to wrap this logger.
* This makes sure that when multiple {@link BuildWrapper}s attempt to decorate the same logger
* it will sort of work.
* @return
* Must not be null. If a fatal error happens, throw an exception.
* @throws RunnerAbortedException
* If a fatal error is detected but the implementation handled it gracefully, throw this exception
* to suppress stack trace.
* @since 1.374
*/
public OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException, RunnerAbortedException {
return logger;
}
/**
* {@link Action} to be displayed in the job page.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册