
edu.hm.hafner.analysis.parser.EclipseMavenParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of analysis-model Show documentation
Show all versions of analysis-model Show documentation
This library provides a Java object model to read, aggregate, filter, and query static analysis reports.
It is used by Jenkins' warnings next generation plug-in to visualize the warnings of individual builds.
Additionally, this library is used by a GitHub action to autograde student software projects based on a given set of
metrics (unit tests, code and mutation coverage, static analysis warnings).
package edu.hm.hafner.analysis.parser;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.util.LookaheadStream;
import static edu.hm.hafner.analysis.parser.EclipseParser.*;
/**
* A parser for Eclipse compiler warnings.
*
* @author Ullrich Hafner
* @author Jason Faust
*/
public class EclipseMavenParser extends LookaheadParser {
private static final long serialVersionUID = 425883472788422955L;
private static final String ECLIPSE_FIRST_LINE_REGEXP =
"\\s*\\[(?WARNING|ERROR|INFO)\\]\\s*(?.*):\\[(?\\d+)(?:,\\d+)?\\]\\s*(?.*)";
@Override
public boolean accepts(final ReaderFactory readerFactory) {
return !isXmlFile(readerFactory);
}
/**
* Creates a new instance of {@link EclipseMavenParser}.
*/
public EclipseMavenParser() {
super(ECLIPSE_FIRST_LINE_REGEXP);
}
@Override
protected boolean isLineInteresting(final String line) {
return line.contains(WARNING) || line.contains(ERROR) || line.contains(INFO);
}
@Override
protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) {
builder.guessSeverity(matcher.group("severity"))
.setFileName(matcher.group("file"))
.setLineStart(matcher.group("line"));
String message = matcher.group("message");
if (StringUtils.isNotBlank(message)) { // single line format
builder.setMessage(message);
extractCategory(builder, message);
}
else { // multi line format
List code = new ArrayList<>();
while (lookahead.hasNext("^\\t.*$") && lookahead.hasNext()) {
code.add(lookahead.next());
}
builder.setAdditionalProperties(code.hashCode());
if (lookahead.hasNext()) {
extractMessage(builder, RegExUtils.removeFirst(lookahead.next(), ".*\\t"));
}
}
return builder.buildOptional();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy