From 3f0a73e6f9f8a07b732520a97a2e5905a1c7ea58 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 27 Jan 2022 12:55:59 -0500 Subject: [PATCH 1/4] [JEP-7] Additional Ruby-related cleanups --- core/src/main/java/hudson/util/LogTaskListener.java | 5 +---- .../main/java/hudson/util/StreamTaskListener.java | 5 +---- core/src/main/resources/hudson/model/Api/index.jelly | 12 ------------ 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/hudson/util/LogTaskListener.java b/core/src/main/java/hudson/util/LogTaskListener.java index 7d696ada4632..d054d1b4ad71 100644 --- a/core/src/main/java/hudson/util/LogTaskListener.java +++ b/core/src/main/java/hudson/util/LogTaskListener.java @@ -37,13 +37,10 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; -// TODO: AbstractTaskListener is empty now, but there are dependencies on that e.g. Ruby Runtime - JENKINS-48116) -// The change needs API deprecation policy or external usages cleanup. - /** * {@link TaskListener} which sends messages to a {@link Logger}. */ -public class LogTaskListener extends AbstractTaskListener implements TaskListener, Closeable { +public class LogTaskListener implements TaskListener, Closeable { // would be simpler to delegate to the LogOutputStream but this would incompatibly change the serial form private final TaskListener delegate; diff --git a/core/src/main/java/hudson/util/StreamTaskListener.java b/core/src/main/java/hudson/util/StreamTaskListener.java index 8aad40f5b599..be73be86a7b6 100644 --- a/core/src/main/java/hudson/util/StreamTaskListener.java +++ b/core/src/main/java/hudson/util/StreamTaskListener.java @@ -48,9 +48,6 @@ import jenkins.util.SystemProperties; import org.kohsuke.stapler.framework.io.WriterOutputStream; -// TODO: AbstractTaskListener is empty now, but there are dependencies on that e.g. Ruby Runtime - JENKINS-48116) -// The change needs API deprecation policy or external usages cleanup. - /** * {@link TaskListener} that generates output into a single stream. * @@ -59,7 +56,7 @@ * * @author Kohsuke Kawaguchi */ -public class StreamTaskListener extends AbstractTaskListener implements TaskListener, Closeable { +public class StreamTaskListener implements TaskListener, Closeable { @NonNull private PrintStream out; @CheckForNull diff --git a/core/src/main/resources/hudson/model/Api/index.jelly b/core/src/main/resources/hudson/model/Api/index.jelly index b927eafb513d..cc208c986d7d 100644 --- a/core/src/main/resources/hudson/model/Api/index.jelly +++ b/core/src/main/resources/hudson/model/Api/index.jelly @@ -84,18 +84,6 @@ THE SOFTWARE. ast.literal_eval(urllib.urlopen("...").read())

- -

From 625ef1badc437c13226d49ed98325722376a930c Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 27 Jan 2022 15:01:26 -0500 Subject: [PATCH 2/4] Might need to preserve serial form of `StreamTaskListener` for nonstandard usages. (`LogTaskListener` was not serializable to begin with.) --- core/src/main/java/hudson/util/StreamTaskListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/util/StreamTaskListener.java b/core/src/main/java/hudson/util/StreamTaskListener.java index be73be86a7b6..f19db94b45cd 100644 --- a/core/src/main/java/hudson/util/StreamTaskListener.java +++ b/core/src/main/java/hudson/util/StreamTaskListener.java @@ -56,7 +56,8 @@ * * @author Kohsuke Kawaguchi */ -public class StreamTaskListener implements TaskListener, Closeable { +@SuppressWarnings("deprecation") // to preserve serial form +public class StreamTaskListener extends AbstractTaskListener implements TaskListener, Closeable { @NonNull private PrintStream out; @CheckForNull From 0c2f85d987f386c2ca5cd3615dda6a37ea4638b3 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 28 Jan 2022 08:51:44 -0500 Subject: [PATCH 3/4] Did not believe f744501078b32d9a9d872c85659e87449fc5792a at first, but indeed `LogTaskListener` is remotable due to its one field being a `StreamTaskListener` which proxies a stream --- .../java/hudson/util/LogTaskListener.java | 3 ++- .../java/hudson/util/LogTaskListenerTest.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/util/LogTaskListener.java b/core/src/main/java/hudson/util/LogTaskListener.java index d054d1b4ad71..267f8f7bf27f 100644 --- a/core/src/main/java/hudson/util/LogTaskListener.java +++ b/core/src/main/java/hudson/util/LogTaskListener.java @@ -40,7 +40,8 @@ /** * {@link TaskListener} which sends messages to a {@link Logger}. */ -public class LogTaskListener implements TaskListener, Closeable { +@SuppressWarnings("deprecation") // to preserve serial form +public class LogTaskListener extends AbstractTaskListener implements TaskListener, Closeable { // would be simpler to delegate to the LogOutputStream but this would incompatibly change the serial form private final TaskListener delegate; diff --git a/test/src/test/java/hudson/util/LogTaskListenerTest.java b/test/src/test/java/hudson/util/LogTaskListenerTest.java index 72b89f64a205..c92b65ac3567 100644 --- a/test/src/test/java/hudson/util/LogTaskListenerTest.java +++ b/test/src/test/java/hudson/util/LogTaskListenerTest.java @@ -30,6 +30,7 @@ import hudson.model.TaskListener; import java.util.logging.Level; import java.util.logging.Logger; +import jenkins.security.MasterToSlaveCallable; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -56,4 +57,23 @@ public void annotations() throws Exception { assertEquals("[plain line, from annotate, from hyperlink, there from encoded]", logging.getMessages().toString()); } + @Test + public void serialization() throws Exception { + TaskListener l = new LogTaskListener(Logger.getLogger("LogTaskListenerTest"), Level.INFO); + r.createOnlineSlave().getChannel().call(new Log(l)); + assertEquals("[from agent]", logging.getMessages().toString()); + } + private static final class Log extends MasterToSlaveCallable { + private final TaskListener l; + Log(TaskListener l) { + this.l = l; + } + @Override + public Void call() throws RuntimeException { + l.getLogger().println("from agent"); + l.getLogger().flush(); + return null; + } + } + } From ef066f9f1f0f08ca1e3fcac446dc0753d58f43ff Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 28 Jan 2022 12:40:04 -0500 Subject: [PATCH 4/4] CheckStyle :angry: --- test/src/test/java/hudson/util/LogTaskListenerTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/src/test/java/hudson/util/LogTaskListenerTest.java b/test/src/test/java/hudson/util/LogTaskListenerTest.java index c92b65ac3567..f1dad026f5d6 100644 --- a/test/src/test/java/hudson/util/LogTaskListenerTest.java +++ b/test/src/test/java/hudson/util/LogTaskListenerTest.java @@ -63,17 +63,22 @@ public void serialization() throws Exception { r.createOnlineSlave().getChannel().call(new Log(l)); assertEquals("[from agent]", logging.getMessages().toString()); } + private static final class Log extends MasterToSlaveCallable { + private final TaskListener l; + Log(TaskListener l) { this.l = l; } + @Override public Void call() throws RuntimeException { l.getLogger().println("from agent"); l.getLogger().flush(); return null; } + } }