-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #743 from jenkinsci/sarif
Add support for SARIF
- Loading branch information
Showing
6 changed files
with
215 additions
and
1 deletion.
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
17 changes: 17 additions & 0 deletions
17
src/main/java/edu/hm/hafner/analysis/parser/violations/SarifAdapter.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,17 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.SarifParser; | ||
|
||
/** | ||
* Parses SARIF files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class SarifAdapter extends AbstractViolationAdapter { | ||
private static final long serialVersionUID = -5699747899173867285L; | ||
|
||
@Override | ||
SarifParser createParser() { | ||
return new SarifParser(); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/edu/hm/hafner/analysis/registry/SarifDescriptor.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,28 @@ | ||
package edu.hm.hafner.analysis.registry; | ||
|
||
import edu.hm.hafner.analysis.IssueParser; | ||
import edu.hm.hafner.analysis.parser.violations.SarifAdapter; | ||
|
||
/** | ||
* A descriptor for the SARIF parser. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
class SarifDescriptor extends ParserDescriptor { | ||
private static final String ID = "sarif"; | ||
private static final String NAME = "SARIF"; | ||
|
||
SarifDescriptor() { | ||
super(ID, NAME); | ||
} | ||
|
||
@Override | ||
public IssueParser createParser(final Option... options) { | ||
return new SarifAdapter(); | ||
} | ||
|
||
@Override | ||
public String getUrl() { | ||
return "https://github.com/oasis-tcs/sarif-spec"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/edu/hm/hafner/analysis/parser/violations/SarifAdapterTest.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,34 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import edu.hm.hafner.analysis.AbstractParserTest; | ||
import edu.hm.hafner.analysis.Report; | ||
import edu.hm.hafner.analysis.Severity; | ||
import edu.hm.hafner.analysis.assertions.SoftAssertions; | ||
|
||
/** | ||
* Tests the class {@link SarifAdapter}. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
class SarifAdapterTest extends AbstractParserTest { | ||
SarifAdapterTest() { | ||
super("sarif.json"); | ||
} | ||
|
||
@Override | ||
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { | ||
softly.assertThat(report).hasSize(2); | ||
softly.assertThat(report.get(0)) | ||
.hasMessage("asdasd asdasd") | ||
.hasFileName("/whatever/path.c") | ||
.hasLineStart(123) | ||
.hasType("Cyclomatic complexity") | ||
.hasSeverity(Severity.WARNING_HIGH); | ||
} | ||
|
||
@Override | ||
protected SarifAdapter createParser() { | ||
return new SarifAdapter(); | ||
} | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
src/test/resources/edu/hm/hafner/analysis/parser/violations/sarif.json
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,118 @@ | ||
{ | ||
"runs": [ | ||
{ | ||
"invocations": [], | ||
"language": "en-US", | ||
"versionControlProvenance": [], | ||
"artifacts": [], | ||
"logicalLocations": [], | ||
"graphs": [], | ||
"results": [ | ||
{ | ||
"ruleId": "", | ||
"ruleIndex": -1, | ||
"kind": "FAIL", | ||
"level": "NONE", | ||
"message": { | ||
"text": "asdasd", | ||
"arguments": [] | ||
}, | ||
"locations": [ | ||
{ | ||
"id": -1, | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "/whatever/path.c", | ||
"index": -1 | ||
}, | ||
"region": { | ||
"startLine": 123, | ||
"endLine": 123, | ||
"charOffset": -1, | ||
"byteOffset": -1, | ||
"message": { | ||
"text": "asdasd", | ||
"arguments": [] | ||
} | ||
} | ||
}, | ||
"logicalLocations": [], | ||
"annotations": [], | ||
"relationships": [] | ||
} | ||
], | ||
"stacks": [], | ||
"codeFlows": [], | ||
"graphs": [], | ||
"graphTraversals": [], | ||
"relatedLocations": [], | ||
"suppressions": [], | ||
"rank": -1.0, | ||
"attachments": [], | ||
"workItemUris": [], | ||
"fixes": [], | ||
"taxa": [] | ||
}, | ||
{ | ||
"ruleId": "Cyclomatic complexity", | ||
"ruleIndex": -1, | ||
"kind": "FAIL", | ||
"level": "ERROR", | ||
"message": { | ||
"text": "asdasd", | ||
"arguments": [] | ||
}, | ||
"locations": [ | ||
{ | ||
"id": -1, | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "/whatever/path.c", | ||
"index": -1 | ||
}, | ||
"region": { | ||
"startLine": 123, | ||
"endLine": 123, | ||
"charOffset": -1, | ||
"byteOffset": -1, | ||
"message": { | ||
"text": "asdasd", | ||
"arguments": [] | ||
} | ||
} | ||
}, | ||
"logicalLocations": [], | ||
"annotations": [], | ||
"relationships": [] | ||
} | ||
], | ||
"stacks": [], | ||
"codeFlows": [], | ||
"graphs": [], | ||
"graphTraversals": [], | ||
"relatedLocations": [], | ||
"suppressions": [], | ||
"rank": -1.0, | ||
"attachments": [], | ||
"workItemUris": [], | ||
"fixes": [], | ||
"taxa": [] | ||
} | ||
], | ||
"runAggregates": [], | ||
"redactionTokens": [], | ||
"newlineSequences": [ | ||
"\r\n", | ||
"\n" | ||
], | ||
"threadFlowLocations": [], | ||
"taxonomies": [], | ||
"addresses": [], | ||
"translations": [], | ||
"policies": [], | ||
"webRequests": [], | ||
"webResponses": [] | ||
} | ||
], | ||
"inlineExternalProperties": [] | ||
} |