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