Skip to content

Commit

Permalink
Merge pull request #743 from jenkinsci/sarif
Browse files Browse the repository at this point in the history
Add support for SARIF
  • Loading branch information
uhafner authored Dec 17, 2021
2 parents 5efe467 + b6abdf4 commit 5710461
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 1 deletion.
18 changes: 17 additions & 1 deletion SUPPORTED-FORMATS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--- DO NOT EDIT - Generated by ParserRegistry at 2021-12-17T10:47:02.557070-->
<!--- DO NOT EDIT - Generated by ParserRegistry at 2021-12-17T14:16:10.174924-->
# Supported Report Formats

The static analysis model supports the following report formats.
Expand Down Expand Up @@ -1667,6 +1667,22 @@ analyze - iccxxxxcompiler_opts cstat2.c</pre></code>For details check the IAR C-
:bulb: Use commandline <code>rubocop --format progress</code>.
</td>
</tr>
<tr>
<td>
sarif
</td>
<td>
-
</td>
<td>
<a href="https://github.com/oasis-tcs/sarif-spec">
SARIF
</a>
</td>
<td>
-
</td>
</tr>
<tr>
<td>
sunc
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class ParserRegistry {
new RfLintDescriptor(),
new RoboCopyDescriptor(),
new RuboCopDescriptor(),
new SarifDescriptor(),
new ScalaDescriptor(),
new SimianDescriptor(),
new SonarQubeDescriptor(),
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/registry/SarifDescriptor.java
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";
}
}
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 src/test/resources/edu/hm/hafner/analysis/parser/violations/sarif.json
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": []
}

0 comments on commit 5710461

Please sign in to comment.