From 7194708e5ba8a1f912abfed5dc203506747d6ef3 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 9 Mar 2010 00:45:24 +0000 Subject: [PATCH] using AnnotatedLargeText in more places git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@28432 71c3de6d-444a-0410-be80-ed276b4c234a --- .../hudson/console/AnnotatedLargeText.java | 8 +++- core/src/main/java/hudson/model/Computer.java | 3 +- .../main/java/hudson/model/TaskAction.java | 17 +++++-- .../main/java/hudson/model/TaskThread.java | 46 ++++++++++++++----- .../hudson/model/TaskAction/log.jelly | 5 +- .../hudson/slaves/SlaveComputer/log.jelly | 2 +- .../MavenAbstractArtifactRecord.java | 6 ++- 7 files changed, 64 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/hudson/console/AnnotatedLargeText.java b/core/src/main/java/hudson/console/AnnotatedLargeText.java index d04d6036d6..77bb8fe769 100644 --- a/core/src/main/java/hudson/console/AnnotatedLargeText.java +++ b/core/src/main/java/hudson/console/AnnotatedLargeText.java @@ -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 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; } diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 11760e37d7..cde98fd2dc 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -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(getLogFile(), Charset.defaultCharset(), false, this).doProgressText(req,rsp); } /** diff --git a/core/src/main/java/hudson/model/TaskAction.java b/core/src/main/java/hudson/model/TaskAction.java index c5b8befaeb..78ab230343 100644 --- a/core/src/main/java/hudson/model/TaskAction.java +++ b/core/src/main/java/hudson/model/TaskAction.java @@ -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 log; + protected transient WeakReference 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 l = log; + public AnnotatedLargeText obtainLog() { + WeakReference 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; diff --git a/core/src/main/java/hudson/model/TaskThread.java b/core/src/main/java/hudson/model/TaskThread.java index 303b81137d..f0f760233f 100644 --- a/core/src/main/java/hudson/model/TaskThread.java +++ b/core/src/main/java/hudson/model/TaskThread.java @@ -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 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(text); + action.log = new WeakReference(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 text; - public ListenerAndText(TaskListener listener, LargeText text) { + public ListenerAndText(TaskListener listener, AnnotatedLargeText 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(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(f,Charset.defaultCharset(),false,context) ); } } diff --git a/core/src/main/resources/hudson/model/TaskAction/log.jelly b/core/src/main/resources/hudson/model/TaskAction/log.jelly index 9e4ae9b541..c34fba3fd2 100644 --- a/core/src/main/resources/hudson/model/TaskAction/log.jelly +++ b/core/src/main/resources/hudson/model/TaskAction/log.jelly @@ -29,7 +29,7 @@ THE SOFTWARE. -

+      
       
@@ -37,7 +37,8 @@ THE SOFTWARE. -
+ + ${it.obtainLog().writeLogTo(0,output)}
diff --git a/core/src/main/resources/hudson/slaves/SlaveComputer/log.jelly b/core/src/main/resources/hudson/slaves/SlaveComputer/log.jelly index 07acc7800e..a8a4bc4e47 100644 --- a/core/src/main/resources/hudson/slaves/SlaveComputer/log.jelly +++ b/core/src/main/resources/hudson/slaves/SlaveComputer/log.jelly @@ -27,7 +27,7 @@ THE SOFTWARE. -

+        
         
diff --git a/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java b/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java index a4280b0b13..444269a9f3 100644 --- a/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java +++ b/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java @@ -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> /** * 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(new File(getBuild().getRootDir(),fileName), Charset.defaultCharset(), true, this); } /** -- GitLab