From 50c2bf00874d246036838ac1e429037c50fdb790 Mon Sep 17 00:00:00 2001 From: Tomek Szmytka Date: Thu, 13 May 2021 18:45:08 +0200 Subject: [PATCH 1/2] #223 Work around withMaven step not passing on log line metadata --- pom.xml | 5 +-- .../plugins/ansicolor/AnsiColorStep.java | 1 + .../plugins/ansicolor/AnsiColorStepTest.java | 18 +++++++---- .../plugins/pipeline/maven/WithMavenStep.java | 31 +++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java diff --git a/pom.xml b/pom.xml index 7d68bc8..b88b611 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,13 @@ - + 4.0.0 org.jenkins-ci.plugins plugin 4.18 - + ansicolor diff --git a/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java b/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java index 5a53801..e0efd93 100644 --- a/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java +++ b/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java @@ -125,6 +125,7 @@ private static class AnsiColorExecution extends BodyExecutionCallback { static { EXTENSIONS_NL.put(DynamicContext.Typed.class, new String[]{"kubernetes.pipeline.SecretsMasker"}); EXTENSIONS_NL.put(TaskListenerDecorator.Factory.class, new String[]{"timestamper.pipeline.GlobalDecorator"}); + EXTENSIONS_NL.put(StepDescriptor.class, new String[]{"plugins.pipeline.maven"}); } public AnsiColorExecution(String colorMapName) { diff --git a/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java b/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java index 6105d95..6d03c09 100644 --- a/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java +++ b/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java @@ -3,6 +3,7 @@ import hudson.ExtensionList; import hudson.model.queue.QueueTaskFuture; import hudson.plugins.ansicolor.mock.kubernetes.pipeline.SecretsMasker; +import hudson.plugins.ansicolor.mock.plugins.pipeline.maven.WithMavenStep; import hudson.plugins.ansicolor.mock.timestamper.pipeline.GlobalDecorator; import jenkins.model.Jenkins; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; @@ -10,6 +11,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.jenkinsci.plugins.workflow.log.TaskListenerDecorator; import org.jenkinsci.plugins.workflow.steps.DynamicContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -18,11 +20,7 @@ import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.LoggerRule; import org.jvnet.hudson.test.RestartableJenkinsRule; -import org.mockito.Mockito; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import java.io.IOException; import java.io.StringWriter; import java.time.Duration; import java.util.Arrays; @@ -32,7 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class AnsiColorStepTest { @ClassRule @@ -174,6 +173,13 @@ public void willPrintAdditionalNlOnTimestamperPlugin() { assertNlsOnRunningPipeline(); } + @Issue("223") + @Test + public void willPrintAdditionalNlOnPipelineMavenPlugin() { + ExtensionList.lookup(StepDescriptor.class).add(0, new WithMavenStep.DescriptorImpl()); + assertNlsOnRunningPipeline(); + } + @Issue("218") @Test public void canUseAndReportGlobalColorMapName() { @@ -253,7 +259,7 @@ public void evaluate() throws Throwable { final String script = "ansiColor('xterm') {\n" + "echo '\033[34mHello\033[0m \033[33mcolorful\033[0m \033[35mworld!\033[0m'" + "}"; - final WorkflowJob project = story.j.jenkins.createProject(WorkflowJob.class, "willPrintAdditionalNlOnKubernetesPlugin"); + final WorkflowJob project = story.j.jenkins.createProject(WorkflowJob.class, "willPrintAdditionalNl"); project.setDefinition(new CpsFlowDefinition(script, true)); story.j.assertBuildStatusSuccess(project.scheduleBuild2(0)); StringWriter writer = new StringWriter(); diff --git a/src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java b/src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java new file mode 100644 index 0000000..54d7c9d --- /dev/null +++ b/src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java @@ -0,0 +1,31 @@ +package hudson.plugins.ansicolor.mock.plugins.pipeline.maven; + +import org.jenkinsci.plugins.workflow.steps.Step; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.steps.StepExecution; + +import java.util.Set; + +/** + * Fake step pretending to be a pipeline-maven-plugin component + */ +public class WithMavenStep extends Step { + + @Override + public StepExecution start(StepContext stepContext) throws Exception { + return null; + } + + public static class DescriptorImpl extends StepDescriptor { + @Override + public Set> getRequiredContext() { + return null; + } + + @Override + public String getFunctionName() { + return "fake function"; + } + } +} From a95ce8835c67f4acc145fe60bd788b9955ddf923 Mon Sep 17 00:00:00 2001 From: Tomek Szmytka Date: Fri, 14 May 2021 16:43:04 +0200 Subject: [PATCH 2/2] Document changes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa842d6..2998dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ============ * [#219](https://github.com/jenkinsci/ansicolor-plugin/pull/219): Set env var TERM also if a default color map is used - [@tszmytka](https://github.com/tszmytka). +* [#226](https://github.com/jenkinsci/ansicolor-plugin/pull/226): Work around withMaven step not passing on log line metadata - [@tszmytka](https://github.com/tszmytka). * Your contribution here.