-
-
Notifications
You must be signed in to change notification settings - Fork 72
[JENKINS-58102] GlobalAnnotator does not annotate lines that are part of a multi-line color sequence #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[JENKINS-58102] GlobalAnnotator does not annotate lines that are part of a multi-line color sequence #28
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bbb0dd2
JENKINS-58102 GlobalAnnotator does not annotate lines that are part o…
basil a57f7e5
Merge remote-tracking branch 'origin/master' into JENKINS-58102
basil e4d58ea
Bump the minimum Jenkins version to 2.150.3
basil 48e1649
Jesse's review feedback
basil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/test/java/hudson/plugins/timestamper/pipeline/PipelineTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package hudson.plugins.timestamper.pipeline; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import com.gargoylesoftware.htmlunit.WebClientUtil; | ||
| import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
| import com.gargoylesoftware.htmlunit.html.HtmlPreformattedText; | ||
| import com.gargoylesoftware.htmlunit.html.HtmlSpan; | ||
| import hudson.plugins.timestamper.TimestamperConfig; | ||
| import java.io.BufferedReader; | ||
| import java.io.StringReader; | ||
| import java.time.ZonedDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
| import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
| import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
|
|
||
| public class PipelineTest { | ||
|
|
||
| private boolean originalAllPipelines; | ||
|
|
||
| @Rule public JenkinsRule r = new JenkinsRule(); | ||
|
|
||
| @Before | ||
| public void setAllPipelines() { | ||
| TimestamperConfig config = TimestamperConfig.get(); | ||
| originalAllPipelines = config.isAllPipelines(); | ||
| config.setAllPipelines(true); | ||
| } | ||
|
|
||
| @After | ||
| public void restoreAllPipelines() { | ||
| TimestamperConfig config = TimestamperConfig.get(); | ||
| config.setAllPipelines(originalAllPipelines); | ||
basil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Test | ||
basil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public void globalDecoratorAnnotator() throws Exception { | ||
| WorkflowJob project = r.createProject(WorkflowJob.class); | ||
| project.setDefinition( | ||
| new CpsFlowDefinition( | ||
| "node {\n" | ||
| + " ansiColor('xterm') {\n" | ||
| + " echo 'foo'\n" | ||
| + " echo \"\\u001B[31mBeginning multi-line color\"\n" | ||
| + " echo \"More color\"\n" | ||
| + " echo \"Ending multi-line color\\u001B[39m\"\n" | ||
| + " }\n" | ||
| + "}", | ||
| true)); | ||
| WorkflowRun build = r.buildAndAssertSuccess(project); | ||
| r.assertLogContains("foo", build); | ||
| r.assertLogContains("Beginning multi-line color", build); | ||
| r.assertLogContains("More color", build); | ||
| r.assertLogContains("Ending multi-line color", build); | ||
|
|
||
| /* | ||
| * Ensure that each line of the console log is decorated with a valid timestamp decoration. | ||
| * While doing so, save the raw timestamps for later comparison with the annotated console | ||
| * output. | ||
| */ | ||
| List<String> rawTimestamps = new ArrayList<>(); | ||
| for (String line : build.getLog(Integer.MAX_VALUE)) { | ||
| assertTrue(line, line.startsWith("[")); | ||
| int end = line.indexOf(']'); | ||
| assertEquals(line, 25, end); | ||
| assertNotNull( | ||
| line, ZonedDateTime.parse(line.substring(1, end), GlobalDecorator.UTC_MILLIS)); | ||
|
|
||
| rawTimestamps.add(line.substring(0, 26)); | ||
| } | ||
|
|
||
| // Fetch the annotated console output. | ||
| HtmlPage page = r.createWebClient().getPage(build, "consoleFull"); | ||
| WebClientUtil.waitForJSExec(page.getWebClient()); | ||
| HtmlPreformattedText consoleOutput = page.getFirstByXPath("//pre[@class='console-output']"); | ||
| String consoleText = consoleOutput.asText(); | ||
|
|
||
| /* | ||
| * Ensure that each line of the console output is annotated with a timestamp and a raw | ||
| * timestamp. While doing so, save the raw timestamps for later comparison with the | ||
| * decorated console log. | ||
| */ | ||
| List<String> annotatedLines = | ||
| new BufferedReader(new StringReader(consoleText)) | ||
| .lines() | ||
| .collect(Collectors.toList()); | ||
|
|
||
| List<String> annotatedTimestamps = | ||
| getTimestamps(consoleOutput, "//span[@class='timestamp']"); | ||
| assertEquals(consoleText, annotatedLines.size(), annotatedTimestamps.size()); | ||
|
|
||
| List<String> annotatedRawTimestamps = | ||
| getTimestamps(consoleOutput, "//span[contains(@style, 'display: none')]"); | ||
| assertEquals(consoleText, annotatedLines.size(), annotatedRawTimestamps.size()); | ||
|
|
||
| for (int i = 0; i < annotatedLines.size(); i++) { | ||
| String annotatedLine = annotatedLines.get(i); | ||
| String prefix = annotatedTimestamps.get(i) + annotatedRawTimestamps.get(i) + ' '; | ||
| assertTrue( | ||
| String.format("annotatedLine: '%s', prefix: '%s'", annotatedLine, prefix), | ||
| annotatedLine.startsWith(prefix)); | ||
|
|
||
| /* | ||
| * The annotated console output contains "Terminated" lines which don't appear in the | ||
| * decorated console log. In order to do the raw timestamp comparison below, we ignore | ||
| * such lines. | ||
| */ | ||
| if (annotatedLine.substring(prefix.length()).equals("Terminated")) { | ||
| annotatedTimestamps.remove(i); | ||
| annotatedRawTimestamps.remove(i); | ||
| annotatedLines.remove(i); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Ensure that the raw timestamps were correctly propagated from the decorated console log | ||
| * to the annotated console output. | ||
| */ | ||
| assertEquals(rawTimestamps, annotatedRawTimestamps); | ||
| } | ||
|
|
||
| private static List<String> getTimestamps( | ||
| HtmlPreformattedText consoleOutput, String xpathExpr) { | ||
| List<String> timestamps = new ArrayList<>(); | ||
|
|
||
| List<HtmlSpan> nodes = consoleOutput.getByXPath(xpathExpr); | ||
| for (HtmlSpan node : nodes) { | ||
| timestamps.add(node.getTextContent()); | ||
| } | ||
|
|
||
| return timestamps; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.