
edu.hm.hafner.analysis.parser.OTDockerLintParser 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 org.json.JSONArray;
import org.json.JSONObject;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
/**
* A parser for ot-docker-linter json output.
*
* @author Abhishek Dubey
* @see ot-docker-linter
*/
public class OTDockerLintParser extends JsonIssueParser {
private static final long serialVersionUID = 42L;
@Override
public boolean accepts(final ReaderFactory readerFactory) {
return readerFactory.getFileName().endsWith(".json");
}
@Override
protected void parseJsonArray(final Report report, final JSONArray jsonReport, final IssueBuilder issueBuilder) {
for (Object entry : jsonReport) {
if (entry instanceof JSONObject) {
parseJsonObject(report, (JSONObject) entry, issueBuilder);
}
}
}
@Override
protected void parseJsonObject(final Report report, final JSONObject jsonIssue, final IssueBuilder issueBuilder) {
if (jsonIssue.has("code")) {
issueBuilder.setCategory(jsonIssue.getString("code"));
}
if (jsonIssue.has("severity")) {
issueBuilder.setSeverity(Severity.guessFromString(jsonIssue.getString("severity")));
}
if (jsonIssue.has("line")) {
issueBuilder.setLineStart(jsonIssue.getInt("line_number"));
}
if (jsonIssue.has("line")) {
issueBuilder.setModuleName(jsonIssue.getString("line"));
}
if (jsonIssue.has("description")) {
issueBuilder.setDescription(jsonIssue.getString("description"));
}
if (jsonIssue.has("message")) {
issueBuilder.setMessage(jsonIssue.getString("message"));
}
if (jsonIssue.has("file")) {
issueBuilder.setFileName(jsonIssue.getString("file"));
}
report.add(issueBuilder.buildAndClean());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy