-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18593cc
commit 9541b71
Showing
9 changed files
with
385 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/se/bjurr/violations/lib/parsers/CoverityParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package se.bjurr.violations.lib.parsers; | ||
|
||
import static se.bjurr.violations.lib.model.SEVERITY.ERROR; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.model.Violation.violationBuilder; | ||
|
||
import com.google.gson.Gson; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
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.CoveritySchema; | ||
import se.bjurr.violations.lib.model.generated.coverity.Issue; | ||
import se.bjurr.violations.lib.reports.Parser; | ||
|
||
public class CoverityParser implements ViolationsParser { | ||
|
||
@Override | ||
public Set<Violation> parseReportOutput( | ||
final String string, final ViolationsLogger violationsLogger) throws Exception { | ||
final CoveritySchema coverityReport = new Gson().fromJson(string, CoveritySchema.class); | ||
|
||
final Set<Violation> violations = new TreeSet<>(); | ||
for (final Issue issue : coverityReport.getIssues()) { | ||
|
||
violations.add( | ||
violationBuilder() // | ||
.setFile(issue.getMainEventFilePathname()) // | ||
.setMessage( | ||
issue.getCheckerProperties().getSubcategoryLocalEffect() | ||
+ "\n" | ||
+ issue.getCheckerProperties().getSubcategoryLocalEffect()) // | ||
.setParser(Parser.COVERITY) // | ||
.setCategory(issue.getCheckerProperties().getCategory()) | ||
.setRule(issue.getType() + "/" + issue.getSubtype()) // | ||
.setSeverity(this.toSeverity(issue.getCheckerProperties().getImpact())) // | ||
.setStartLine(issue.getMainEventLineNumber()) // | ||
.build()); | ||
} | ||
return violations; | ||
} | ||
|
||
private SEVERITY toSeverity(final String from) { | ||
if (from.equalsIgnoreCase("Medium")) { | ||
return WARN; | ||
} | ||
return ERROR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string" | ||
}, | ||
"formatVersion": { | ||
"type": "integer" | ||
}, | ||
"suppressedIssueCount": { | ||
"type": "integer" | ||
}, | ||
"issues": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/issue" | ||
} | ||
}, | ||
"desktopAnalysisSettings": { | ||
"type": "null" | ||
}, | ||
"error": { | ||
"type": "null" | ||
}, | ||
"warnings": { | ||
"type": "array", | ||
"items": {} | ||
} | ||
}, | ||
"definitions": { | ||
"issue": { | ||
"type": "object", | ||
"properties": { | ||
"mergeKey": { | ||
"type": "string" | ||
}, | ||
"occurrenceCountForMK": { | ||
"type": "integer" | ||
}, | ||
"occurrenceNumberInMK": { | ||
"type": "integer" | ||
}, | ||
"referenceOccurrenceCountForMK": { | ||
"type": "null" | ||
}, | ||
"checkerName": { | ||
"type": "string" | ||
}, | ||
"subcategory": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string" | ||
}, | ||
"subtype": { | ||
"type": "string" | ||
}, | ||
"code-language": { | ||
"type": "string" | ||
}, | ||
"extra": { | ||
"type": "string" | ||
}, | ||
"domain": { | ||
"type": "string" | ||
}, | ||
"language": { | ||
"type": "string" | ||
}, | ||
"mainEventFilePathname": { | ||
"type": "string" | ||
}, | ||
"strippedMainEventFilePathname": { | ||
"type": "string" | ||
}, | ||
"mainEventLineNumber": { | ||
"type": "integer" | ||
}, | ||
"properties": { | ||
"type": "object" | ||
}, | ||
"functionDisplayName": { | ||
"type": "string" | ||
}, | ||
"functionMangledName": { | ||
"type": "string" | ||
}, | ||
"localStatus": { | ||
"type": "null" | ||
}, | ||
"ordered": { | ||
"type": "boolean" | ||
}, | ||
"stateOnServer": { | ||
"type": "null" | ||
}, | ||
"events": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/event" | ||
} | ||
}, | ||
"checkerProperties": { | ||
"$ref": "#/definitions/checkerProperty" | ||
} | ||
} | ||
}, | ||
"event": { | ||
"type": "object", | ||
"properties": { | ||
"covLStrEventDescription": { | ||
"type": "string" | ||
}, | ||
"eventDescription": { | ||
"type": "string" | ||
}, | ||
"eventNumber": { | ||
"type": "integer" | ||
}, | ||
"eventTreePosition": { | ||
"type": "string" | ||
}, | ||
"eventSet": { | ||
"type": "integer" | ||
}, | ||
"eventTag": { | ||
"type": "string" | ||
}, | ||
"filePathname": { | ||
"type": "string" | ||
}, | ||
"strippedFilePathname": { | ||
"type": "string" | ||
}, | ||
"lineNumber": { | ||
"type": "integer" | ||
}, | ||
"main": { | ||
"type": "boolean" | ||
}, | ||
"moreInformationId": { | ||
"type": "null" | ||
}, | ||
"remediation": { | ||
"type": "boolean" | ||
}, | ||
"events": { | ||
"type": "null" | ||
} | ||
} | ||
}, | ||
"checkerProperty": { | ||
"type": "object", | ||
"properties": { | ||
"category": { | ||
"type": "string" | ||
}, | ||
"categoryDescription": { | ||
"type": "string" | ||
}, | ||
"cweCategory": { | ||
"type": "string" | ||
}, | ||
"issueKinds": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/issueKind" | ||
} | ||
}, | ||
"eventSetCaptions": { | ||
"type": "array", | ||
"items": {} | ||
}, | ||
"impact": { | ||
"type": "string" | ||
}, | ||
"impactDescription": { | ||
"type": "string" | ||
}, | ||
"subcategoryLocalEffect": { | ||
"type": "string" | ||
}, | ||
"subcategoryShortDescription": { | ||
"type": "string" | ||
}, | ||
"subcategoryLongDescription": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"issueKind": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static se.bjurr.violations.lib.TestUtils.getRootFolder; | ||
import static se.bjurr.violations.lib.ViolationsApi.violationsApi; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Set; | ||
import org.junit.Test; | ||
import se.bjurr.violations.lib.model.Violation; | ||
import se.bjurr.violations.lib.reports.Parser; | ||
|
||
public class CoverityTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeParsed() { | ||
final String rootFolder = getRootFolder(); | ||
|
||
final Set<Violation> actual = | ||
violationsApi() // | ||
.withPattern(".*/coverity/example1\\.json$") // | ||
.inFolder(rootFolder) // | ||
.findAll(Parser.COVERITY) // | ||
.violations(); | ||
|
||
assertThat(actual) // | ||
.hasSize(1); | ||
|
||
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."); | ||
assertThat(violation0.getFile()) // | ||
.isEqualTo("C:/Workspace/workspace/Build_jenkins_development/somefile.cs"); | ||
assertThat(violation0.getSeverity()) // | ||
.isEqualTo(WARN); | ||
assertThat(violation0.getCategory()) // | ||
.isEqualTo("Integer handling issues"); | ||
assertThat(violation0.getRule()) // | ||
.isEqualTo("constant_expression_result/bit_and_with_zero"); | ||
assertThat(violation0.getStartLine()) // | ||
.isEqualTo(79); | ||
} | ||
} |
Oops, something went wrong.