Skip to content

Commit

Permalink
Merge pull request #917 from jenkinsci/maven-3.9.x-log-format
Browse files Browse the repository at this point in the history
Add support for Maven 3.9.x log messages
  • Loading branch information
uhafner authored May 4, 2023
2 parents 5eaf7fc + 3ab4d53 commit 85cbd1f
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ public int hashCode() {

@Override
public String toString() {
return String.format("%s(%d,%d): %s: %s: %s", fileName, lineStart, columnStart, type, category, message);
return String.format("%s(%d,%d): %s: %s: %s", getBaseName(), lineStart, columnStart, type, category, message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public abstract class AbstractMavenLogParser extends LookaheadParser {
private static final Pattern MAVEN_MODULE_START = Pattern.compile(
"-+< (?<id>\\S+) >-+"
);
static final String MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin";
private static final String MAVEN_PLUGIN_PREFIX = "maven-";
private static final String MAVEN_PLUGIN_SUFFIX = "-plugin";
static final String MAVEN_COMPILER_PLUGIN = MAVEN_PLUGIN_PREFIX + "compiler" + MAVEN_PLUGIN_SUFFIX;
static final String MAVEN_JAVADOC_PLUGIN = MAVEN_PLUGIN_PREFIX + "javadoc" + MAVEN_PLUGIN_SUFFIX;
static final String MAVEN_ENFORCER_PLUGIN = MAVEN_PLUGIN_PREFIX + "enforcer" + MAVEN_PLUGIN_SUFFIX;
private String goal = StringUtils.EMPTY;
private String module = StringUtils.EMPTY;

Expand Down Expand Up @@ -61,4 +65,17 @@ protected String getGoal() {
boolean hasGoalOrModule() {
return StringUtils.isNotBlank(goal) || StringUtils.isNotBlank(module);
}

protected boolean hasGoals(final String... goals) {
for (String searchGoal : goals) {
if (goal.contains(searchGoal)) {
return true;
}
if (goal.contains(StringUtils.removeEnd(
StringUtils.removeStart(searchGoal, MAVEN_PLUGIN_PREFIX), MAVEN_PLUGIN_SUFFIX))) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public JavaDocParser() {
@Override
protected boolean isLineInteresting(final String line) {
return super.isLineInteresting(line)
&& !getGoal().equals(MAVEN_COMPILER_PLUGIN)
&& !hasGoals(MAVEN_COMPILER_PLUGIN)
&& lineContainsKeywords(line);
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/edu/hm/hafner/analysis/parser/JavacParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class JavacParser extends AbstractMavenLogParser {
private static final long serialVersionUID = 7199325311690082782L;

private static final String ERRORPRONE_URL_PATTERN = "\\s+\\(see https?://\\S+\\s*\\)";
private static final String ERROR_PRONE_URL_PATTERN = "\\s+\\(see https?://\\S+\\s*\\)";

private static final String JAVAC_WARNING_PATTERN
= "^(?:\\S+\\s+)?" // optional preceding arbitrary number of characters that are not a
Expand Down Expand Up @@ -50,13 +50,14 @@ public JavacParser() {

@Override
protected boolean isLineInteresting(final String line) {
return line.contains("[") || line.contains("w:") || line.contains("e:");
return (line.contains("[") || line.contains("w:") || line.contains("e:"))
&& !hasGoals(MAVEN_JAVADOC_PLUGIN);
}

@Override
protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) throws ParsingException {
if (lookahead.hasNext(ERRORPRONE_URL_PATTERN)) {
if (lookahead.hasNext(ERROR_PRONE_URL_PATTERN)) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -26,16 +25,6 @@ public class MavenConsoleParser extends AbstractMavenLogParser {
private static final String WARNING = "WARNING";
private static final String ERROR = "ERROR";

/**
* Regular expression to parse the start of maven plugin in console.
*/
protected static final Pattern MAVEN_PLUGIN_START = Pattern.compile(
"\\[INFO\\] --- (?<id>\\S+):(?<version>\\S+):(?<goal>\\S+)\\s.*");

private static final Pattern MAVEN_MODULE_START = Pattern.compile(
"-+< (?<id>\\S+) >-+"
);

/**
* Pattern for identifying warning or error maven logs.
*
Expand All @@ -58,9 +47,6 @@ public class MavenConsoleParser extends AbstractMavenLogParser {
*/
private static final String PATTERN = "^(?<timestamp>.*\\s|)\\[(?<severity>WARNING|ERROR)\\]\\s*(?<message>.*)$";

private String goal = StringUtils.EMPTY;
private String module = StringUtils.EMPTY;

/**
* Creates a new instance of {@link MavenConsoleParser}.
*/
Expand All @@ -70,22 +56,11 @@ public MavenConsoleParser() {

@Override
protected boolean isLineInteresting(final String line) {
Matcher goalMatcher = MAVEN_PLUGIN_START.matcher(line);
if (goalMatcher.find()) {
goal = String.format("%s:%s", goalMatcher.group("id"), goalMatcher.group("goal"));
}

Matcher moduleMatcher = MAVEN_MODULE_START.matcher(line);
if (moduleMatcher.find()) {
module = moduleMatcher.group("id");
}

return isValidGoal() && (line.contains(WARNING) || line.contains(ERROR));
}

private boolean isValidGoal() {
return !(goal.contains("maven-compiler-plugin")
|| goal.contains("maven-javadoc-plugin")); // will be captured by another parser already
return !hasGoals(MAVEN_COMPILER_PLUGIN, MAVEN_JAVADOC_PLUGIN); // will be captured by another parser already
}

@Override
Expand All @@ -96,7 +71,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre

StringBuilder message = new StringBuilder(matcher.group("message"));

if (goal.startsWith("maven-enforcer-plugin")) {
if (hasGoals(MAVEN_ENFORCER_PLUGIN)) {
String timestamp = matcher.group("timestamp");
int length = StringUtils.length(timestamp);

Expand All @@ -120,8 +95,8 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
}
}
return builder.setDescription(pre().with(code().withText(message.toString())).render())
.setType(goal)
.setModuleName(module)
.setType(getGoal())
.setModuleName(getModule())
.setLineEnd(lookahead.getLine())
.setFileName(lookahead.getFileName())
.buildOptional();
Expand Down
15 changes: 0 additions & 15 deletions src/test/java/edu/hm/hafner/analysis/IssueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,6 @@ protected Issue createFilledIssue() {
ADDITIONAL_PROPERTIES, UUID.randomUUID());
}

@Test
void testToString() {
Issue issue = createFilledIssue();

try (SoftAssertions softly = new SoftAssertions()) {
softly.assertThat(issue.toString())
.contains(FILE_NAME)
.contains(Integer.toString(LINE_START))
.contains(Integer.toString(COLUMN_START))
.contains(CATEGORY)
.contains(TYPE)
.contains(MESSAGE);
}
}

@Test
void shouldObeyEqualsContract() {
LineRangeList filled = new LineRangeList(15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class AntJavacParserTest extends AbstractParserTest {
super("ant-javac.txt");
}

@Test
void issue67521IgnoreJavaDocWarnings() {
Report warnings = parse("javadoc-in-java.log");

assertThat(warnings).isEmpty();
}

/**
* Parses a warning log with a very long line that will take several seconds to parse.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,30 @@ protected JavaDocParser createParser() {
return new JavaDocParser();
}

@Test
void issue67521IgnoreJavaDocWarnings() {
Report warnings = parse("javadoc-in-java.log");

assertThat(warnings).hasSize(12);
}

@Test
void issue70658RemovePrefixAndSuffixFromMavenPlugins() {
Report warnings = parse("maven.3.9.1.log");
assertThat(warnings).hasSize(1);

assertThat(warnings.get(0))
.hasFileName("/Users/hafner/git/warnings-ng-plugin-devenv/codingstyle/src/main/java/edu/hm/hafner/util/Ensure.java")
.hasLineStart(57)
.hasMessage("@param \"value\" has already been specified")
.hasSeverity(Severity.WARNING_NORMAL);
}

/**
* Parses a warning log with JavaDoc 1.8 warnings.
*/
@Test
void shouldHaveACategory() {
void shouldHaveCategory() {
Report warnings = parse("javadoc-category.txt");

assertThat(warnings).hasSize(4);
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ protected JavacParser createParser() {
return new JavacParser();
}

@Test
void issue70658RemovePrefixAndSuffixFromMavenPlugins() {
Report warnings = parse("maven.3.9.1.log");

assertThat(warnings).hasSize(1);
}

@Test
void issue67521IgnoreJavaDocWarnings() {
Report warnings = parse("javadoc-in-java.log");

assertThat(warnings).isEmpty();
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
assertThat(report).hasSize(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ protected MavenConsoleParserTest() {
super("maven-console.txt");
}

@Test
void issue70658RemovePrefixAndSuffixFromMavenPlugins() {
Report warnings = parse("maven.3.9.1.log");

assertThat(warnings).hasSize(2);
}

@Test
void shouldAssignTypesFromGoals() {
Report warnings = parse("maven-goals.log");
Expand Down
110 changes: 110 additions & 0 deletions src/test/resources/edu/hm/hafner/analysis/parser/javadoc-in-java.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[INFO] --- maven-javadoc-plugin:3.3.1:jar (default-cli) @ foo-app ---
[INFO] No previous run data found, generating javadoc.
[WARNING] Javadoc Warnings
[WARNING] Loading source files for package foo.app...
[WARNING] Constructing Javadoc information...
[WARNING] Building index for all the packages and classes...
[WARNING] Standard Doclet version 17.0.1+12-LTS
[WARNING] Building tree for all the packages and classes...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/ApplicationSettings.html...
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:38: warning: no comment
[WARNING] public static class ServiceDetails
[WARNING] ^
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/ApplicationSettings.ServiceDetails.html...
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:83: warning: no comment
[WARNING] public enum Stage
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:88: warning: no comment
[WARNING] public enum VersionCheck
[WARNING] ^
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/ApplicationSettings.ServiceDetails.Stage.html...
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/ApplicationSettings.java:85: warning: no comment
[WARNING] AN, EW, TE, TI, VP, VP2, PA, BT, PR, M1B, ED, MA
[WARNING] ^
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/ApplicationSettings.ServiceDetails.VersionCheck.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/Application.html...
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/Application.java:14: warning: no comment
[WARNING] public static void main(String... args)
[WARNING] ^
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/AppController.html...
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/AppController.java:36: warning: no comment
[WARNING] public AppController(final ApplicationSettings settings, final StatusResolver resolver)
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/AppController.java:43: warning: no comment
[WARNING] public Mono<Rendering> index()
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/AppController.java:109: warning: no comment
[WARNING] public Mono<ResponseEntity<StatusData>> serviceStatus(@PathVariable String mandant, @PathVariable String stage, @PathVariable String serviceId)
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/AppController.java:56: warning: no comment
[WARNING] public Mono<Rendering> stages(@PathVariable String mandant)
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/AppController.java:82: warning: no comment
[WARNING] public Mono<Rendering> status(@PathVariable String mandant, @PathVariable String stage)
[WARNING] ^
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/StatusData.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/StatusResolver.html...
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/StatusResolver.java:35: warning: no comment
[WARNING] public List<StatusData> getServiceResults(@NonNull final List<ApplicationSettings.ServiceDetails> services)
[WARNING] ^
[WARNING] /home/jenkins/workspace/foo-job/foo-app/src/main/java/foo/app/StatusResolver.java:40: warning: no comment
[WARNING] public StatusData resolveStatus(final ApplicationSettings.ServiceDetails service)
[WARNING] ^
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/WebConfig.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/package-summary.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/package-tree.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/WebConfig.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/StatusResolver.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/StatusData.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/AppController.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/Application.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/ApplicationSettings.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/ApplicationSettings.ServiceDetails.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/ApplicationSettings.ServiceDetails.VersionCheck.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/class-use/ApplicationSettings.ServiceDetails.Stage.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/foo/app/package-use.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/overview-tree.html...
[WARNING] Building index for all classes...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/allclasses-index.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/allpackages-index.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/index-all.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/index.html...
[WARNING] Generating /home/jenkins/workspace/foo-job/foo-app/target/apidocs/help-doc.html...
[WARNING] 23 warnings
[INFO] Building jar: /home/jenkins/workspace/foo-job/foo-app/target/foo-app-2.3.6-SNAPSHOT-javadoc.jar

Fake: from javac
[WARNING] /Users/hafner/git/warnings-ng-plugin-devenv/codingstyle/src/main/java/edu/hm/hafner/util/Ensure.java:[107,64] [AvoidObjectArrays] Avoid accepting a Object[]; consider an Iterable<Object> instead
Loading

0 comments on commit 85cbd1f

Please sign in to comment.