Skip to content

Commit

Permalink
feat: adding configurable Jacoco parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jul 12, 2021
1 parent 4493b6c commit 10019b5
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 48 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ A number of **parsers** have been implemented. Some **parsers** can parse output
| [_HadoLint_](https://github.com/hadolint/hadolint/) | `CHECKSTYLE` | With `-f checkstyle`
| [_IAR_](https://www.iar.com/iar-embedded-workbench/) | `IAR` | With `--no_wrap_diagnostics`
| [_Infer_](http://fbinfer.com/) | `PMD` | Facebook Infer. With `--pmd-xml`.
| [_JACOCO_](https://www.jacoco.org/) | `JACOCO` |
| [_JCReport_](https://github.com/jCoderZ/fawkez/wiki/JcReport) | `JCREPORT` |
| [_JSHint_](http://jshint.com/) | `JSLINT` | With `--reporter=jslint` or the CHECKSTYLE parser with `--reporter=checkstyle`
| [_JUnit_](https://junit.org/junit4/) | `JUNIT` | It only contains the failures.
Expand Down Expand Up @@ -205,6 +206,16 @@ Missing a format? Open an issue [here](https://github.com/tomasbjerre/violations
Default: /home/bjerre/workspace/violations/violations-command-line/.
-h, --help <argument-to-print-help-for> <argument-to-print-help-for>: an argument to print help for
Default: If no specific parameter is given the whole usage text is given
-jacoco-min-coverage, -jmc <big-decimal> Minimum coverage in
Jacoco that will generate a
violation.
<big-decimal>: an arbitrary decimal number (practically no limits)
Default: 0.7
-jacoco-min-line-count, -jmlc <integer> Minimum line count in
Jacoco that will generate a
violation.
<integer>: -2,147,483,648 to 2,147,483,647
Default: 4
-max-line-column-width, -mlcw <integer> 0 means no limit
<integer>: -2,147,483,648 to 2,147,483,647
Default: 0
Expand Down Expand Up @@ -249,8 +260,8 @@ Missing a format? Open an issue [here](https://github.com/tomasbjerre/violations
CLANG, CPD, CPPCHECK,
CPPLINT, CSSLINT, GENERIC,
FINDBUGS, FLAKE8, FXCOP,
GENDARME, IAR, JCREPORT, JSLINT,
JUNIT, LINT, KLOCWORK,
GENDARME, IAR, JACOCO, JCREPORT,
JSLINT, JUNIT, LINT, KLOCWORK,
KOTLINMAVEN, KOTLINGRADLE, MSCPP,
MSBULDLOG, MYPY, GOLINT,
GOOGLEERRORPRONE, PERLCRITIC, PITEST,
Expand Down
36 changes: 32 additions & 4 deletions src/main/java/se/bjurr/violations/main/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static se.bjurr.violations.lib.ViolationsApi.violationsApi;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.codeclimate.CodeClimateTransformer.fromViolations;
import static se.softhouse.jargo.Arguments.bigDecimalArgument;
import static se.softhouse.jargo.Arguments.booleanArgument;
import static se.softhouse.jargo.Arguments.enumArgument;
import static se.softhouse.jargo.Arguments.fileArgument;
Expand All @@ -22,6 +23,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -39,6 +41,9 @@
import se.bjurr.violations.lib.ViolationsLogger;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;
import se.bjurr.violations.lib.parsers.JacocoParser;
import se.bjurr.violations.lib.parsers.JacocoParserSettings;
import se.bjurr.violations.lib.parsers.ViolationsParser;
import se.bjurr.violations.lib.reports.Parser;
import se.bjurr.violations.lib.util.Filtering;
import se.bjurr.violations.violationslib.com.google.gson.Gson;
Expand Down Expand Up @@ -171,6 +176,17 @@ public void main(final String args[]) throws Exception {
+ SHOW_JSON_CONFIG
+ ".")
.build();
final Argument<Integer> jacocoMinLineCount =
integerArgument("-jacoco-min-line-count", "-jmlc")
.description("Minimum line count in Jacoco that will generate a violation.")
.defaultValue(JacocoParserSettings.DEFAULT_MIN_LINE_COUNT)
.build();

final Argument<BigDecimal> jacocoMinCoverage =
bigDecimalArgument("-jacoco-min-coverage", "-jmc")
.description("Minimum coverage in Jacoco that will generate a violation.")
.defaultValue(BigDecimal.valueOf(JacocoParserSettings.DEFAULT_MIN_COVERAGE))
.build();

try {
final ParsedArguments parsed =
Expand All @@ -197,7 +213,9 @@ public void main(final String args[]) throws Exception {
maxSeverityColumnWidth, //
maxLineColumnWidth, //
maxMessageColumnWidth, //
gitRepoArg) //
gitRepoArg, //
jacocoMinLineCount, //
jacocoMinCoverage) //
.parse(args);
final String violationsConfigPropertyValue = System.getenv(VIOLATIONS_CONFIG);
final boolean violationsConfigPropertyValueGiven = violationsConfigPropertyValue != null;
Expand Down Expand Up @@ -232,6 +250,8 @@ public void main(final String args[]) throws Exception {
this.violationsConfig.setMaxLineColumnWidth(parsed.get(maxLineColumnWidth));
this.violationsConfig.setMaxMessageColumnWidth(parsed.get(maxMessageColumnWidth));
this.violationsConfig.setGitRepo(parsed.get(gitRepoArg));
this.violationsConfig.setJacocoMinCoverage(parsed.get(jacocoMinCoverage).doubleValue());
this.violationsConfig.setJacocoMinLineCount(parsed.get(jacocoMinLineCount));
if (parsed.wasGiven(codeClimateFileArg)) {
this.violationsConfig.setCodeClimateFile(parsed.get(codeClimateFileArg));
} else {
Expand Down Expand Up @@ -406,9 +426,17 @@ private Set<Violation> getFiltered(final Set<Violation> unfiltered, final SEVERI
private Set<Violation> getAllParsedViolations(final List<String> configuredViolation) {
final String reporter = configuredViolation.size() >= 4 ? configuredViolation.get(3) : null;

Parser parser = null;
ViolationsParser parser = null;
try {
parser = Parser.valueOf(configuredViolation.get(0));
final String parserName = configuredViolation.get(0);
if (parserName.equals(Parser.JACOCO.name())) {
final int minLineCount = this.violationsConfig.getJacocoMinLineCount();
final double minCoverage = this.violationsConfig.getJacocoMinCoverage();
final JacocoParserSettings settings = new JacocoParserSettings(minLineCount, minCoverage);
parser = new JacocoParser(settings);
} else {
parser = Parser.valueOf(parserName).getViolationsParser();
}
} catch (final Exception e) {
throw new RuntimeException(
Arrays.asList(Parser.values()).stream()
Expand All @@ -419,7 +447,7 @@ private Set<Violation> getAllParsedViolations(final List<String> configuredViola
final Set<Violation> parsedViolations =
violationsApi() //
.withViolationsLogger(this.violationsConfig.getViolationsLogger()) //
.findAll(parser) //
.withViolationsParser(parser) //
.inFolder(configuredViolation.get(1)) //
.withPattern(configuredViolation.get(2)) //
.withReporter(reporter) //
Expand Down
102 changes: 60 additions & 42 deletions src/main/java/se/bjurr/violations/main/ViolationsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,174 +28,192 @@ public class ViolationsConfig {
private File violationsFile;
private boolean showDebugInfo;
private ViolationsLogger violationsLogger;
private int jacocoMinLineCount;
private double jacocoMinCoverage;

public ViolationsConfig() {}

public List<List<String>> getViolations() {
return violations;
return this.violations;
}

public void setViolations(List<List<String>> violations) {
public void setViolations(final List<List<String>> violations) {
this.violations = violations;
}

public SEVERITY getMinSeverity() {
return minSeverity;
return this.minSeverity;
}

public void setMinSeverity(SEVERITY minSeverity) {
public void setMinSeverity(final SEVERITY minSeverity) {
this.minSeverity = minSeverity;
}

public ViolationsReporterDetailLevel getDetailLevel() {
return detailLevel;
return this.detailLevel;
}

public void setDetailLevel(ViolationsReporterDetailLevel detailLevel) {
public void setDetailLevel(final ViolationsReporterDetailLevel detailLevel) {
this.detailLevel = detailLevel;
}

public Integer getMaxViolations() {
return maxViolations;
return this.maxViolations;
}

public void setMaxViolations(Integer maxViolations) {
public void setMaxViolations(final Integer maxViolations) {
this.maxViolations = maxViolations;
}

public boolean isPrintViolations() {
return printViolations;
return this.printViolations;
}

public void setPrintViolations(boolean printViolations) {
public void setPrintViolations(final boolean printViolations) {
this.printViolations = printViolations;
}

public String getDiffFrom() {
return diffFrom;
return this.diffFrom;
}

public void setDiffFrom(String diffFrom) {
public void setDiffFrom(final String diffFrom) {
this.diffFrom = diffFrom;
}

public String getDiffTo() {
return diffTo;
return this.diffTo;
}

public void setDiffTo(String diffTo) {
public void setDiffTo(final String diffTo) {
this.diffTo = diffTo;
}

public SEVERITY getDiffMinSeverity() {
return diffMinSeverity;
return this.diffMinSeverity;
}

public void setDiffMinSeverity(SEVERITY diffMinSeverity) {
public void setDiffMinSeverity(final SEVERITY diffMinSeverity) {
this.diffMinSeverity = diffMinSeverity;
}

public File getGitRepo() {
return gitRepo;
return this.gitRepo;
}

public void setGitRepo(File gitRepo) {
public void setGitRepo(final File gitRepo) {
this.gitRepo = gitRepo;
}

public boolean isDiffPrintViolations() {
return diffPrintViolations;
return this.diffPrintViolations;
}

public void setDiffPrintViolations(boolean diffPrintViolations) {
public void setDiffPrintViolations(final boolean diffPrintViolations) {
this.diffPrintViolations = diffPrintViolations;
}

public Integer getDiffMaxViolations() {
return diffMaxViolations;
return this.diffMaxViolations;
}

public void setDiffMaxViolations(Integer diffMaxViolations) {
public void setDiffMaxViolations(final Integer diffMaxViolations) {
this.diffMaxViolations = diffMaxViolations;
}

public ViolationsReporterDetailLevel getDiffDetailLevel() {
return diffDetailLevel;
return this.diffDetailLevel;
}

public void setDiffDetailLevel(ViolationsReporterDetailLevel diffDetailLevel) {
public void setDiffDetailLevel(final ViolationsReporterDetailLevel diffDetailLevel) {
this.diffDetailLevel = diffDetailLevel;
}

public int getMaxReporterColumnWidth() {
return maxReporterColumnWidth;
return this.maxReporterColumnWidth;
}

public void setMaxReporterColumnWidth(int maxReporterColumnWidth) {
public void setMaxReporterColumnWidth(final int maxReporterColumnWidth) {
this.maxReporterColumnWidth = maxReporterColumnWidth;
}

public int getMaxRuleColumnWidth() {
return maxRuleColumnWidth;
return this.maxRuleColumnWidth;
}

public void setMaxRuleColumnWidth(int maxRuleColumnWidth) {
public void setMaxRuleColumnWidth(final int maxRuleColumnWidth) {
this.maxRuleColumnWidth = maxRuleColumnWidth;
}

public int getMaxSeverityColumnWidth() {
return maxSeverityColumnWidth;
return this.maxSeverityColumnWidth;
}

public void setMaxSeverityColumnWidth(int maxSeverityColumnWidth) {
public void setMaxSeverityColumnWidth(final int maxSeverityColumnWidth) {
this.maxSeverityColumnWidth = maxSeverityColumnWidth;
}

public int getMaxLineColumnWidth() {
return maxLineColumnWidth;
return this.maxLineColumnWidth;
}

public void setMaxLineColumnWidth(int maxLineColumnWidth) {
public void setMaxLineColumnWidth(final int maxLineColumnWidth) {
this.maxLineColumnWidth = maxLineColumnWidth;
}

public int getMaxMessageColumnWidth() {
return maxMessageColumnWidth;
return this.maxMessageColumnWidth;
}

public void setMaxMessageColumnWidth(int maxMessageColumnWidth) {
public void setMaxMessageColumnWidth(final int maxMessageColumnWidth) {
this.maxMessageColumnWidth = maxMessageColumnWidth;
}

public File getCodeClimateFile() {
return codeClimateFile;
return this.codeClimateFile;
}

public void setCodeClimateFile(File codeClimateFile) {
public void setCodeClimateFile(final File codeClimateFile) {
this.codeClimateFile = codeClimateFile;
}

public File getViolationsFile() {
return violationsFile;
return this.violationsFile;
}

public void setViolationsFile(File violationsFile) {
public void setViolationsFile(final File violationsFile) {
this.violationsFile = violationsFile;
}

public boolean isShowDebugInfo() {
return showDebugInfo;
return this.showDebugInfo;
}

public void setShowDebugInfo(boolean showDebugInfo) {
public void setShowDebugInfo(final boolean showDebugInfo) {
this.showDebugInfo = showDebugInfo;
}

public ViolationsLogger getViolationsLogger() {
return violationsLogger;
return this.violationsLogger;
}

public void setViolationsLogger(ViolationsLogger violationsLogger) {
public void setViolationsLogger(final ViolationsLogger violationsLogger) {
this.violationsLogger = violationsLogger;
}

public double getJacocoMinCoverage() {
return this.jacocoMinCoverage;
}

public void setJacocoMinCoverage(final double jacocoMinCoverage) {
this.jacocoMinCoverage = jacocoMinCoverage;
}

public int getJacocoMinLineCount() {
return this.jacocoMinLineCount;
}

public void setJacocoMinLineCount(final int jacocoMinLineCount) {
this.jacocoMinLineCount = jacocoMinLineCount;
}
}

0 comments on commit 10019b5

Please sign in to comment.