diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4fe96cf..99b6a5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
-0.5.4 (Next)
+0.6 (Next)
============
+* [#132](https://github.com/jenkinsci/ansicolor-plugin/pull/132): Reworked implementation to add markup on display, not to the actual build log - [@jglick](https://github.com/jglick).
* Your contribution here.
0.5.3 (11/06/2018)
diff --git a/pom.xml b/pom.xml
index 6890c3b..1e52962 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
ansicolor
- 0.5.4-SNAPSHOT
+ 0.6-SNAPSHOT
hpi
AnsiColor
@@ -46,7 +46,7 @@
- 2.121.2
+ 2.145
8
@@ -57,6 +57,12 @@
2.15
true
+
+ org.jenkins-ci.plugins.workflow
+ workflow-api
+ 2.30
+ true
+
org.jenkins-ci.plugins.workflow
workflow-cps
@@ -89,6 +95,11 @@
structs
1.17
+
+ org.jenkins-ci.plugins
+ scm-api
+ 2.2.6
+
diff --git a/src/main/java/hudson/plugins/ansicolor/AnsiColorBuildWrapper.java b/src/main/java/hudson/plugins/ansicolor/AnsiColorBuildWrapper.java
index 1b67a4c..f37beef 100644
--- a/src/main/java/hudson/plugins/ansicolor/AnsiColorBuildWrapper.java
+++ b/src/main/java/hudson/plugins/ansicolor/AnsiColorBuildWrapper.java
@@ -27,7 +27,6 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
-import hudson.console.ConsoleLogFilter;
import hudson.model.TaskListener;
import hudson.model.AbstractProject;
import hudson.model.Run;
@@ -80,6 +79,7 @@ public DescriptorImpl getDescriptor() {
@Override
public void setUp(Context context, Run, ?> build, FilePath workspace, Launcher launcher, TaskListener listener,
EnvVars initialEnvironment) throws IOException, InterruptedException {
+ build.replaceAction(new ColorizedAction(colorMapName));
}
/**
@@ -188,8 +188,4 @@ public boolean isApplicable(AbstractProject, ?> item) {
}
}
- @Override
- public ConsoleLogFilter createLoggerDecorator(Run, ?> build) {
- return new AnsiColorConsoleLogFilter(getDescriptor().getColorMap(colorMapName));
- }
}
diff --git a/src/main/java/hudson/plugins/ansicolor/AnsiColorConsoleLogFilter.java b/src/main/java/hudson/plugins/ansicolor/AnsiColorConsoleLogFilter.java
index 646f5f8..570f7ea 100644
--- a/src/main/java/hudson/plugins/ansicolor/AnsiColorConsoleLogFilter.java
+++ b/src/main/java/hudson/plugins/ansicolor/AnsiColorConsoleLogFilter.java
@@ -15,7 +15,9 @@
/**
* {@link ConsoleLogFilter} that adds a {@link SimpleHtmlNote} to each line.
+ * @deprecated Only here for serial form compatibility.
*/
+@Deprecated
public final class AnsiColorConsoleLogFilter extends ConsoleLogFilter implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java b/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java
index 0a7411f..bdc88aa 100644
--- a/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java
+++ b/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java
@@ -1,32 +1,30 @@
package hudson.plugins.ansicolor;
import hudson.Extension;
-import hudson.console.ConsoleLogFilter;
import hudson.plugins.ansicolor.AnsiColorBuildWrapper.DescriptorImpl;
import hudson.util.ListBoxModel;
-import java.io.IOException;
import java.util.Collections;
-import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
-import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
-import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
-import org.jenkinsci.plugins.workflow.steps.BodyInvoker;
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.stapler.DataBoundConstructor;
-import com.google.inject.Inject;
+import hudson.model.Run;
+import java.util.Set;
+import org.jenkinsci.plugins.workflow.steps.Step;
+import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
+import org.jenkinsci.plugins.workflow.steps.StepExecution;
/**
* Custom pipeline step that can be used without a node and build wrapper.
*/
-public class AnsiColorStep extends AbstractStepImpl {
+public class AnsiColorStep extends Step {
private final String colorMapName;
@@ -50,15 +48,24 @@ private static DescriptorImpl getWrapperDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(DescriptorImpl.class);
}
+ @Override
+ public StepExecution start(StepContext context) throws Exception {
+ return new ExecutionImpl(context, colorMapName);
+ }
+
/**
* Execution for {@link AnsiColorStep}.
*/
- public static class ExecutionImpl extends AbstractStepExecutionImpl {
+ private static class ExecutionImpl extends AbstractStepExecutionImpl {
private static final long serialVersionUID = 1L;
- @Inject(optional = true)
- private transient AnsiColorStep step;
+ private final String colorMapName;
+
+ ExecutionImpl(StepContext context, String colorMapName) {
+ super(context);
+ this.colorMapName = colorMapName;
+ }
/**
* {@inheritDoc}
@@ -66,39 +73,22 @@ public static class ExecutionImpl extends AbstractStepExecutionImpl {
@Override
public boolean start() throws Exception {
StepContext context = getContext();
+ context.get(Run.class).replaceAction(new ColorizedAction(colorMapName));
EnvironmentExpander currentEnvironment = context.get(EnvironmentExpander.class);
- EnvironmentExpander terminalEnvironment = EnvironmentExpander.constant(Collections.singletonMap("TERM", step.getColorMapName()));
- context.newBodyInvoker().withContext(createConsoleLogFilter(context))
+ EnvironmentExpander terminalEnvironment = EnvironmentExpander.constant(Collections.singletonMap("TERM", colorMapName));
+ context.newBodyInvoker()
.withContext(EnvironmentExpander.merge(currentEnvironment, terminalEnvironment))
.withCallback(BodyExecutionCallback.wrap(context)).start();
return false;
}
- private ConsoleLogFilter createConsoleLogFilter(StepContext context)
- throws IOException, InterruptedException {
- ConsoleLogFilter original = context.get(ConsoleLogFilter.class);
- ConsoleLogFilter subsequent = new AnsiColorConsoleLogFilter(step.getColorMap());
- return BodyInvoker.mergeConsoleLogFilters(original, subsequent);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void stop(@Nonnull Throwable cause) throws Exception {
- getContext().onFailure(cause);
- }
}
/**
* Descriptor for {@link AnsiColorStep}.
*/
@Extension(optional = true)
- public static class StepDescriptorImpl extends AbstractStepDescriptorImpl {
-
- public StepDescriptorImpl() {
- super(ExecutionImpl.class);
- }
+ public static class StepDescriptorImpl extends StepDescriptor {
@Override
public String getDisplayName() {
@@ -124,5 +114,11 @@ public boolean takesImplicitBlockArgument() {
public ListBoxModel doFillColorMapNameItems() {
return getWrapperDescriptor().doFillColorMapNameItems();
}
+
+ @Override
+ public Set extends Class>> getRequiredContext() {
+ return Collections.singleton(Run.class);
+ }
+
}
}
diff --git a/src/main/java/hudson/plugins/ansicolor/ColorConsoleAnnotator.java b/src/main/java/hudson/plugins/ansicolor/ColorConsoleAnnotator.java
new file mode 100644
index 0000000..fc54977
--- /dev/null
+++ b/src/main/java/hudson/plugins/ansicolor/ColorConsoleAnnotator.java
@@ -0,0 +1,135 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2018 CloudBees, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package hudson.plugins.ansicolor;
+
+import hudson.Extension;
+import hudson.MarkupText;
+import hudson.console.ConsoleAnnotator;
+import hudson.console.ConsoleAnnotatorFactory;
+import hudson.model.Queue;
+import hudson.model.Run;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import jenkins.model.Jenkins;
+import org.apache.commons.io.output.CountingOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
+import org.jenkinsci.plugins.workflow.graph.FlowNode;
+
+/**
+ * Applies ANSI coloration to log files where requested.
+ */
+final class ColorConsoleAnnotator extends ConsoleAnnotator