Skip to content

Commit

Permalink
#223 Work around withMaven step not passing on log line metadata (#226)
Browse files Browse the repository at this point in the history
* #223 Work around withMaven step not passing on log line metadata

* Document changes
  • Loading branch information
tszmytka authored May 15, 2021
1 parent 7758873 commit 0d69f83
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
* [#225](https://github.com/jenkinsci/ansicolor-plugin/pull/225): Work around logstash-plugin hiding some log lines from ansicolor - [@tszmytka](https://github.com/tszmytka).
* Your contribution here.

Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.18</version>
<relativePath />
<relativePath/>
</parent>

<artifactId>ansicolor</artifactId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private static class AnsiColorExecution extends BodyExecutionCallback {
"timestamper.pipeline.GlobalDecorator",
"logstash.pipeline.GlobalDecorator",
});
EXTENSIONS_NL.put(StepDescriptor.class, new String[]{"plugins.pipeline.maven"});
}

public AnsiColorExecution(String colorMapName) {
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
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;
Expand Down Expand Up @@ -178,6 +180,13 @@ public void willPrintAdditionalNlOnLogstashPlugin() {
assertNlsOnRunningPipeline();
}

@Issue("223")
@Test
public void willPrintAdditionalNlOnPipelineMavenPlugin() {
ExtensionList.lookup(StepDescriptor.class).add(0, new WithMavenStep.DescriptorImpl());
assertNlsOnRunningPipeline();
}

@Issue("218")
@Test
public void canUseAndReportGlobalColorMapName() {
Expand Down Expand Up @@ -257,7 +266,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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends Class<?>> getRequiredContext() {
return null;
}

@Override
public String getFunctionName() {
return "fake function";
}
}
}

0 comments on commit 0d69f83

Please sign in to comment.