Skip to content

Commit

Permalink
fix: avoid repeated message in the Coverity parser (refs #188)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 2, 2024
1 parent 0a0daa0 commit 6c14711
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.25.3'
testImplementation 'uk.co.jemos.podam:podam:8.0.1.RELEASE'
testImplementation 'com.approvaltests:approvaltests:23.0.0'
testImplementation 'com.approvaltests:approvaltests:23.0.1'
testImplementation 'com.networknt:json-schema-validator:1.4.0'
}
29 changes: 25 additions & 4 deletions src/main/java/se/bjurr/violations/lib/parsers/CoverityParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
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.model.generated.coverity.CheckerProperty;
import se.bjurr.violations.lib.model.generated.coverity.CoveritySchema;
import se.bjurr.violations.lib.model.generated.coverity.Issue;
import se.bjurr.violations.lib.reports.Parser;
import se.bjurr.violations.lib.util.Utils;

public class CoverityParser implements ViolationsParser {

Expand All @@ -32,10 +34,7 @@ public Set<Violation> parseReportOutput(
violations.add(
violationBuilder() //
.setFile(issue.getMainEventFilePathname()) //
.setMessage(
issue.getCheckerProperties().getSubcategoryLocalEffect()
+ "\n"
+ issue.getCheckerProperties().getSubcategoryLocalEffect()) //
.setMessage(this.getMessage(issue.getCheckerProperties())) //
.setParser(Parser.COVERITY) //
.setCategory(issue.getCheckerProperties().getCategory())
.setRule(issue.getType() + "/" + issue.getSubtype()) //
Expand All @@ -46,6 +45,28 @@ public Set<Violation> parseReportOutput(
return violations;
}

private String getMessage(final CheckerProperty checkerProperty) {
final boolean hasLongDescription =
!Utils.isNullOrEmpty(checkerProperty.getSubcategoryLongDescription());
final boolean hasLocalEffect =
!Utils.isNullOrEmpty(checkerProperty.getSubcategoryLocalEffect());
if (hasLongDescription && hasLocalEffect) {
if (checkerProperty
.getSubcategoryLongDescription()
.contains(checkerProperty.getSubcategoryLocalEffect())) {
return checkerProperty.getSubcategoryLongDescription();
}
return checkerProperty.getSubcategoryLongDescription()
+ ".\n"
+ checkerProperty.getSubcategoryLocalEffect();
} else if (hasLongDescription) {
return checkerProperty.getSubcategoryLongDescription();
} else if (hasLocalEffect) {
return checkerProperty.getSubcategoryLocalEffect();
}
return checkerProperty.getImpactDescription();
}

private SEVERITY toSeverity(final String from) {
if (from.equalsIgnoreCase("Medium")) {
return WARN;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/se/bjurr/violations/lib/CoverityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testThatViolationsCanBeParsed() {
final Violation violation0 = new ArrayList<>(actual).get(0);
assertThat(violation0.getMessage()) //
.isEqualTo(
"The expression's value is always zero; construct may indicate an inadvertent logic error.\nThe expression's value is always zero; construct may indicate an inadvertent logic error.");
"Bitwise-and ('&amp;') operation applied to zero always produces zero.\nThe expression's value is always zero; construct may indicate an inadvertent logic error.");
assertThat(violation0.getFile()) //
.isEqualTo("C:/Workspace/workspace/Build_jenkins_development/somefile.cs");
assertThat(violation0.getSeverity()) //
Expand Down

0 comments on commit 6c14711

Please sign in to comment.