GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||
GeezerVison is showing github.com — [core] Include SARIF renderer by mmoyaferrer · Pull Request #3073 · pmd/pmd Conversation
|
|
@mmoyaferrer and me would also love to get your feedback on our v1 implementation of SARIF. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Example of PMD Sarif Output (generated with snapshot bin): {
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "PMD",
"version": "unknown",
"informationUri": "https://pmd.github.io/pmd/",
"rules": [
{
"id": "ApexCRUDViolation",
"shortDescription": {
"text": "Validate CRUD permission before SOQL/DML operation"
},
"helpUri": "https://pmd.github.io/pmd/pmd_rules_apex_security.html#apexcrudviolation",
"properties": {
"ruleset": "Security",
"priority": 3
}
},
{
"id": "ApexDoc",
"shortDescription": {
"text": "Missing ApexDoc comment"
},
"helpUri": "https://pmd.github.io/pmd/pmd_rules_apex_documentation.html#apexdoc",
"properties": {
"ruleset": "Documentation",
"priority": 3
}
},
{
"id": "AvoidLogicInTrigger",
"shortDescription": {
"text": "Avoid logic in triggers"
},
"helpUri": "https://pmd.github.io/pmd/pmd_rules_apex_bestpractices.html#avoidlogicintrigger",
"properties": {
"ruleset": "Best Practices",
"priority": 3
}
}
]
}
},
"results": [
{
"ruleId": "ApexCRUDViolation",
"ruleIndex": 0,
"message": {
"text": "Validate CRUD permission before SOQL/DML operation"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/Users/user/pmd/unhappy-soup/force-app/main/default/classes/ApexCRUDViolation.cls"
},
"region": {
"startLine": 4,
"startColumn": 15,
"endLine": 4,
"endColumn": 56
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "/Users/user/pmd/unhappy-soup/force-app/main/default/classes/ApexCRUDViolation.cls"
},
"region": {
"startLine": 6,
"startColumn": 3,
"endLine": 6,
"endColumn": 11
}
}
}
]
},
{
"ruleId": "ApexDoc",
"ruleIndex": 1,
"message": {
"text": "Missing ApexDoc comment"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/Users/user/pmd/unhappy-soup/force-app/main/default/classes/ApexCRUDViolation.cls"
},
"region": {
"startLine": 1,
"startColumn": 27,
"endLine": 8,
"endColumn": 1
}
}
},
{
"physicalLocation": {
"artifactLocation": {
"uri": "/Users/user/pmd/unhappy-soup/force-app/main/default/classes/ApexCRUDViolation.cls"
},
"region": {
"startLine": 3,
"startColumn": 14,
"endLine": 7,
"endColumn": 2
}
}
}
]
},
{
"ruleId": "AvoidLogicInTrigger",
"ruleIndex": 2,
"message": {
"text": "Avoid logic in triggers"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/Users/user/pmd/unhappy-soup/force-app/main/default/triggers/VoldemortTrigger.trigger"
},
"region": {
"startLine": 1,
"startColumn": 9,
"endLine": 11,
"endColumn": 1
}
}
}
]
}
],
"invocations": [
{
"executionSuccessful": true,
"toolConfigurationNotifications": [],
"toolExecutionNotifications": []
}
]
}
]
} |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Added those in toolConfigurationNotifications and toolExecutionNotifications components of invocations (part of sarif standard)
|
@mmoyaferrer can you solve the unsuccessful check that are reported above? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for working on this!
I don't like that you added lombok for this though. It looks like it saves space in the schema, but we don't use lombok anywhere else and I'd like to keep it that way, at least for now. If you want to keep using lombok, then those classes should be in another library. If that's too much of a hassle, then please desugar them, and put them into an internal package. An IDE can do that automatically.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
I've three points:
I'd also prefer not to use lombok. You can either delombok it - or alternatively, we could use a library that brings in the SARIF format, e.g. https://github.com/Contrast-Security-OSS/java-sarif (this actually uses lombok as well, but since we would use this lib as a dependency, that would be ok) or https://github.com/VillageChief/sarif-java . See also https://search.maven.org/search?q=sarif for the available libs.
Please also remove the ".DS_Store" files/directories. Maybe add this even to the top-level .gitignore file.
The build + tests seems to run successfully under linux, just Windows has problems... I guess, it's about the different line endings. For the JSON renderer, we solved that by implementing the filter-method in the test, which normalizes the line endings:
| .replaceAll("\r\n", "\n"); // make the test run on Windows, too |
That means, the expected json files are stored with "\n", and the produced output of the renderer in the test will be normalized to the same line ending.
I can confirm, that this fixes the unit tests.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
|
|
||
| public class SarifRenderer extends AbstractIncrementingRenderer { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just a note for future improvements: An incrementing renderer usually outputs data as soon it is available. That means, as soon as a violation is found, it is send to the renderer and this outputs it on the writer.
That's in contrast to AbstractAccumulatingRenderer, which collects all violations and outputs it at the end, when everything is done.
Your implementation behaves now like a accumulating renderer, since the report is only written at the end. That makes the super class AbstractIncrementingRenderer misleading and maybe AbstractAccumulatingRenderer would be better.
I also don't know, whether SARIF would actually support such an incremental output. Such an optimization is not always possible for all file formats.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with your point. As a future improvement a new AbstractIncrementingRenderer could be created to give this optimization to the SARIF use case (the current AbstractIncrementingRenderer does not support it for SARIF)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@adangel @oowekyala Lombok is removed. If you are happy with the rest please merge it. Or should I just do it? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good now!
I'll merge it probably on Thursday.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm glad this will be part of 6.31, thanks for your work
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[core] Include SARIF renderer #3073
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[core] Support SARIF JSON Format
There was an error while loading. Please reload this page.