提交 7194708e 编写于 作者: K kohsuke

using AnnotatedLargeText in more places

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@28432 71c3de6d-444a-0410-be80-ed276b4c234a
上级 a7ac6a46
......@@ -31,6 +31,7 @@ import hudson.util.TimeUnit2;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.framework.io.ByteBuffer;
import org.kohsuke.stapler.framework.io.LargeText;
import javax.crypto.Cipher;
......@@ -67,12 +68,15 @@ import static java.lang.Math.abs;
* @since 1.349
*/
public class AnnotatedLargeText<T> extends LargeText {
private final File logFile;
private T context;
public AnnotatedLargeText(File file, Charset charset, boolean completed, T context) {
super(file, charset, completed);
this.logFile = file;
this.context = context;
}
public AnnotatedLargeText(ByteBuffer memory, Charset charset, boolean completed, T context) {
super(memory, charset, completed);
this.context = context;
}
......
......@@ -26,6 +26,7 @@ package hudson.model;
import hudson.EnvVars;
import hudson.Util;
import hudson.cli.declarative.CLIMethod;
import hudson.console.AnnotatedLargeText;
import hudson.model.Descriptor.FormException;
import hudson.node_monitors.NodeMonitor;
import hudson.remoting.Channel;
......@@ -983,7 +984,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* Handles incremental log.
*/
public void doProgressiveLog( StaplerRequest req, StaplerResponse rsp) throws IOException {
new org.kohsuke.stapler.framework.io.LargeText(getLogFile(),false).doProgressText(req,rsp);
new AnnotatedLargeText<Computer>(getLogFile(), Charset.defaultCharset(), false, this).doProgressText(req,rsp);
}
/**
......
......@@ -23,6 +23,7 @@
*/
package hudson.model;
import hudson.console.AnnotatedLargeText;
import org.kohsuke.stapler.framework.io.LargeText;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
......@@ -56,7 +57,7 @@ public abstract class TaskAction extends AbstractModelObject implements Action {
/**
* Hold the log of the tagging operation.
*/
protected transient WeakReference<LargeText> log;
protected transient WeakReference<AnnotatedLargeText> log;
/**
* Gets the permission object that represents the permission to perform this task.
......@@ -68,6 +69,14 @@ public abstract class TaskAction extends AbstractModelObject implements Action {
*/
protected abstract ACL getACL();
/**
* @deprecated as of 1.350
* Use {@link #obtainLog()}, which returns the same object in a more type-safe signature.
*/
public LargeText getLog() {
return obtainLog();
}
/**
* Obtains the log file.
*
......@@ -79,8 +88,8 @@ public abstract class TaskAction extends AbstractModelObject implements Action {
* Derived classes that persist the text should override this
* method so that it fetches the file from disk.
*/
public LargeText getLog() {
WeakReference<LargeText> l = log;
public AnnotatedLargeText obtainLog() {
WeakReference<AnnotatedLargeText> l = log;
if(l==null) return null;
return l.get();
}
......@@ -97,7 +106,7 @@ public abstract class TaskAction extends AbstractModelObject implements Action {
* Handles incremental log output.
*/
public void doProgressiveLog( StaplerRequest req, StaplerResponse rsp) throws IOException {
LargeText text = getLog();
AnnotatedLargeText text = obtainLog();
if(text!=null) {
text.doProgressText(req,rsp);
return;
......
......@@ -23,12 +23,14 @@
*/
package hudson.model;
import hudson.console.AnnotatedLargeText;
import hudson.util.StreamTaskListener;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.lang.ref.WeakReference;
import java.nio.charset.Charset;
import org.kohsuke.stapler.framework.io.LargeText;
import org.kohsuke.stapler.framework.io.ByteBuffer;
......@@ -46,10 +48,16 @@ import org.kohsuke.stapler.framework.io.ByteBuffer;
*/
public abstract class TaskThread extends Thread {
/**
* Represents the output from this task thread.
* @deprecated as of Hudson 1.350
* Use {@link #log}. It's the same object, in a better type.
*/
private final LargeText text;
/**
* Represents the output from this task thread.
*/
private final AnnotatedLargeText<TaskThread> log;
/**
* Represents the interface to produce output.
*/
......@@ -70,7 +78,7 @@ public abstract class TaskThread extends Thread {
//if you want it in the thread's name.
super(owner.getDisplayName());
this.owner = owner;
this.text = output.text;
this.text = this.log = output.text;
this.listener = output.listener;
}
......@@ -86,7 +94,7 @@ public abstract class TaskThread extends Thread {
*/
protected final void associateWith(TaskAction action) {
action.workerThread = this;
action.log = new WeakReference<LargeText>(text);
action.log = new WeakReference<AnnotatedLargeText>(log);
}
/**
......@@ -126,7 +134,7 @@ public abstract class TaskThread extends Thread {
listener = null;
isRunning =false;
}
text.markAsComplete();
log.markAsComplete();
}
/**
......@@ -138,38 +146,54 @@ public abstract class TaskThread extends Thread {
protected abstract void perform(TaskListener listener) throws Exception;
/**
* Tuple of {@link TaskListener} and {@link LargeText}, representing
* Tuple of {@link TaskListener} and {@link AnnotatedLargeText}, representing
* the interface for producing output and how to retrieve it later.
*/
public static final class ListenerAndText {
final TaskListener listener;
final LargeText text;
final AnnotatedLargeText<TaskThread> text;
public ListenerAndText(TaskListener listener, LargeText text) {
public ListenerAndText(TaskListener listener, AnnotatedLargeText<TaskThread> text) {
this.listener = listener;
this.text = text;
}
/**
* Creates one that's backed by memory.
* @deprecated as of Hudson 1.350
* Use {@link #forMemory(TaskThread)} and pass in the calling {@link TaskAction}
*/
public static ListenerAndText forMemory() {
return forMemory(null);
}
/**
* @deprecated as of Hudson 1.350
* Use {@link #forFile(File, TaskThread)} and pass in the calling {@link TaskAction}
*/
public static ListenerAndText forFile(File f) throws IOException {
return forFile(f,null);
}
/**
* Creates one that's backed by memory.
*/
public static ListenerAndText forMemory(TaskThread context) {
// StringWriter is synchronized
ByteBuffer log = new ByteBuffer();
return new ListenerAndText(
new StreamTaskListener(log),
new LargeText(log,false)
new AnnotatedLargeText<TaskThread>(log,Charset.defaultCharset(),false,context)
);
}
/**
* Creates one that's backed by a file.
*/
public static ListenerAndText forFile(File f) throws IOException {
public static ListenerAndText forFile(File f, TaskThread context) throws IOException {
return new ListenerAndText(
new StreamTaskListener(f),
new LargeText(f,false)
new AnnotatedLargeText<TaskThread>(f,Charset.defaultCharset(),false,context)
);
}
}
......
......@@ -29,7 +29,7 @@ THE SOFTWARE.
<j:choose>
<!-- Do progressive console output -->
<j:when test="${it.workerThread.running}">
<pre id="out"></pre>
<pre id="out" />
<div id="spinner">
<img src="${imagesURL}/spinner.gif" alt=""/>
</div>
......@@ -37,7 +37,8 @@ THE SOFTWARE.
</j:when>
<!-- output is completed now. -->
<j:otherwise>
<pre><st:copyStream reader="${it.log.readAll()}" /></pre>
<st:getOutput var="output" />
<j:whitespace>${it.obtainLog().writeLogTo(0,output)}</j:whitespace>
<form method="get" action="clearError">
<f:submit value="${%Clear error to retry}" />
</form>
......
......@@ -27,7 +27,7 @@ THE SOFTWARE.
<st:include page="sidepanel.jelly" />
<l:main-panel>
<l:isAdmin>
<pre id="out"></pre>
<pre id="out" />
<div id="spinner">
<img src="${imagesURL}/spinner.gif" alt=""/>
</div>
......
......@@ -23,6 +23,7 @@
*/
package hudson.maven.reporters;
import hudson.console.AnnotatedLargeText;
import hudson.maven.MavenEmbedder;
import hudson.maven.MavenUtil;
import hudson.model.AbstractBuild;
......@@ -55,6 +56,7 @@ import org.kohsuke.stapler.framework.io.LargeText;
import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.CopyOnWriteArrayList;
......@@ -96,8 +98,8 @@ public abstract class MavenAbstractArtifactRecord<T extends AbstractBuild<?,?>>
/**
* Returns the log of this deployment record.
*/
public LargeText getLog() {
return new LargeText(new File(getBuild().getRootDir(),fileName),true);
public AnnotatedLargeText getLog() {
return new AnnotatedLargeText<Record>(new File(getBuild().getRootDir(),fileName), Charset.defaultCharset(), true, this);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册