
edu.hm.hafner.analysis.parser.SphinxBuildParser 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.Optional;
import java.util.regex.Matcher;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.util.LookaheadStream;
import static edu.hm.hafner.analysis.Categories.*;
/**
* A parser for the Sphinx build warnings.
*
* @author Robert Williams
*/
public class SphinxBuildParser extends LookaheadParser {
private static final long serialVersionUID = 1483050615340274588L;
private static final String SPHINX_BUILD_WARNING_PATTERN = "^([a-zA-Z]:\\\\.*?|/.*?|[^\\/].*?):(?:|(?:.* of .*:)?(\\d+|None|):) (ERROR|WARNING): (.*)";
/**
* Creates a new instance of {@link SphinxBuildParser}.
*/
public SphinxBuildParser() {
super(SPHINX_BUILD_WARNING_PATTERN);
}
@Override
protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) {
String message = matcher.group(4);
String category = guessCategoryIfEmpty(matcher.group(3), message);
return builder.setFileName(matcher.group(1))
.setLineStart(matcher.group(2))
.setCategory(category)
.setMessage(message)
.setSeverity(mapPriority(category))
.buildOptional();
}
private Severity mapPriority(final String priority) {
if (equalsIgnoreCase(priority, "error")) {
return Severity.WARNING_HIGH;
}
else {
return Severity.WARNING_NORMAL;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy