Skip to content

Commit 8af4ec0

Browse files
authored
Merge pull request #1901 from Bananeweizen/newline
Recognize `\R` for multiline regex in groovy parsers
2 parents 661b60b + e3322c4 commit 8af4ec0

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParser.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package io.jenkins.plugins.analysis.warnings.groovy;
22

3-
import java.io.Serializable;
4-
import java.util.Arrays;
5-
import java.util.Optional;
6-
import java.util.regex.Matcher;
7-
import java.util.regex.Pattern;
8-
import java.util.regex.PatternSyntaxException;
9-
103
import org.apache.commons.lang3.ObjectUtils;
114
import org.apache.commons.lang3.StringUtils;
125
import org.codehaus.groovy.control.CompilationFailedException;
@@ -20,6 +13,12 @@
2013
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2114

2215
import groovy.lang.Script;
16+
import java.io.Serializable;
17+
import java.util.Arrays;
18+
import java.util.Optional;
19+
import java.util.regex.Matcher;
20+
import java.util.regex.Pattern;
21+
import java.util.regex.PatternSyntaxException;
2322

2423
import org.kohsuke.stapler.AncestorInPath;
2524
import org.kohsuke.stapler.DataBoundConstructor;
@@ -38,7 +37,7 @@
3837
import io.jenkins.plugins.util.ValidationUtilities;
3938

4039
/**
41-
* Defines the properties of a warnings parser that uses a Groovy script to parse the warnings log.
40+
* Defines the properties of a warning parser that uses a Groovy script to parse the console log.
4241
*
4342
* @author Ullrich Hafner
4443
*/
@@ -86,7 +85,7 @@ public GroovyParser(final String id, final String name,
8685
}
8786

8887
private static boolean containsNewline(final String expression) {
89-
return StringUtils.contains(expression, "\\n") || StringUtils.contains(expression, "\\r");
88+
return StringUtils.containsAny(expression, "\\n", "\\r", "\\R");
9089
}
9190

9291
/**

plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParserTest.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package io.jenkins.plugins.analysis.warnings.groovy;
22

3-
import java.io.IOException;
4-
import java.io.StringReader;
5-
63
import org.apache.commons.lang3.StringUtils;
74
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.ValueSource;
87
import org.junitpioneer.jupiter.Issue;
98

109
import edu.hm.hafner.analysis.IssueParser;
1110
import edu.hm.hafner.analysis.Report;
1211
import edu.hm.hafner.util.SerializableTest;
1312

13+
import java.io.IOException;
14+
import java.io.StringReader;
15+
1416
import hudson.model.Run;
1517

1618
import io.jenkins.plugins.analysis.core.util.ConsoleLogReaderFactory;
@@ -55,15 +57,16 @@ void shouldShortenExample() {
5557
/**
5658
* Tries to expose JENKINS-35262: multi-line regular expression parser.
5759
*
60+
* @param regexp
61+
* the regular expression to check
62+
*
5863
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-35262">Issue 35262</a>
5964
*/
60-
@Test
61-
void issue35262() throws IOException {
62-
matchMultiLine("(make(?:(?!make)[\\s\\S])*?make-error:.*(?:\\n|\\r\\n?))");
63-
matchMultiLine("(make(?:(?!make)[\\s\\S])*?make-error:.*(?:\\r?))");
64-
}
65-
66-
private void matchMultiLine(final String multiLineRegexp) throws IOException {
65+
@Issue("JENKINS-35262")
66+
@ParameterizedTest(name = "{index}: Regular expression should be multiline \"{0}\"")
67+
@ValueSource(strings = {"\\n|\\r\\n", "\\r", "\\R"})
68+
void issue35262(final String regexp) throws IOException {
69+
var multiLineRegexp = String.format("(make(?:(?!make)[\\s\\S])*?make-error:.*(?:%s?))", regexp);
6770
String textToMatch = toString("issue35262.log");
6871
String script = toString("issue35262.groovy");
6972

0 commit comments

Comments
 (0)