GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Include SARIF renderer by mmoyaferrer · Pull Request #3073 · pmd/pmd

Conversation

@mmoyaferrer

@mmoyaferrer mmoyaferrer commented Jan 19, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Support SARIF Output Format

Inclusion of a SARIF renderer in pmd-core

SARIF 2.1.0 Schema:

  • https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json

SARIF Docs:

  • https://github.com/microsoft/sarif-tutorials/tree/main/docs

SARIF Validators:

  • https://sarifweb.azurewebsites.net/Validation
  • https://microsoft.github.io/sarif-web-component/
  • https://github.com/microsoft/sarif-vscode-extension

Related issues

  • Fixes [core] Support SARIF JSON Format #2953

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rsoesemann and adangel reacted with hooray emoji rsoesemann reacted with rocket emoji
All reactions
  • 🎉 2 reactions
  • 🚀 1 reaction
mmoyaferrer added 6 commits January 18, 2021 16:32
@mmoyaferrer
Basic sarif renderer with unit tests
615b33b
@mmoyaferrer
cleaning code
51b1c1b
@mmoyaferrer
Cleaning code
e008f2b
@mmoyaferrer
Fix checkstyle issues
52a6ab2
@mmoyaferrer
Update SarifRenderer.java
2e2b763
Cleaning code
@mmoyaferrer
Sarif format refinement
fbb7337
@mmoyaferrer mmoyaferrer changed the title Include SARIF renderer #2953 Include SARIF renderer Jan 19, 2021
@rsoesemann
rsoesemann requested a review from adangel January 19, 2021 10:16
@rsoesemann

rsoesemann commented Jan 19, 2021

Copy link
Copy Markdown
Member

@josepalafox & @swinton:

@mmoyaferrer and me would also love to get your feedback on our v1 implementation of SARIF.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann
rsoesemann requested a review from oowekyala January 19, 2021 10:20
@rsoesemann rsoesemann added this to the 6.31.0 milestone Jan 19, 2021
@rsoesemann rsoesemann added the in:documentation Affects the documentation [doc] label Jan 19, 2021
@mmoyaferrer

mmoyaferrer commented Jan 19, 2021 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

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": []
        }
      ]
    }
  ]
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mmoyaferrer added 7 commits January 19, 2021 11:59
@mmoyaferrer
Adding doc
a5ac240
@mmoyaferrer
Update pmd_report_formats.md
2aae644
@mmoyaferrer
Initialising vars in start method
68eb429
@mmoyaferrer
Including a SarifLogBuilder and error display
f16269a
@mmoyaferrer
Fix checkstyle
69bd898
@mmoyaferrer
Cleaning code
3e9fd7b
@mmoyaferrer
Improved sarif with runtime and configuration errors
944058f
Added those in toolConfigurationNotifications and toolExecutionNotifications components of invocations (part of sarif standard)
@rsoesemann

rsoesemann commented Jan 21, 2021

Copy link
Copy Markdown
Member

@mmoyaferrer can you solve the unsuccessful check that are reported above?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala requested changes Jan 21, 2021
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

mmoyaferrer reacted with thumbs up emoji rsoesemann reacted with confused emoji
All reactions
  • 👍 1 reaction
  • 😕 1 reaction
Comment thread pmd-core/pom.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel requested changes Jan 22, 2021
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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:

pmd/pmd-core/src/test/java/net/sourceforge/pmd/renderers/JsonRendererTest.java

Line 83 in f8c091b

.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.

Uh oh!

There was an error while loading. Please reload this page.

mmoyaferrer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread pmd-core/pom.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/renderers/SarifRenderer.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class SarifRenderer extends AbstractIncrementingRenderer {

@adangel adangel Jan 22, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

rsoesemann reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@mmoyaferrer mmoyaferrer Jan 25, 2021

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/renderers/SarifLog.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/renderers/SarifRenderer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mmoyaferrer
PR Comments
7cb3b68
@mmoyaferrer
mmoyaferrer requested review from adangel and oowekyala January 25, 2021 10:40
@ghost

ghost commented Jan 25, 2021

Copy link
Copy Markdown
1 Message
📖 This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

rsoesemann commented Jan 26, 2021

Copy link
Copy Markdown
Member

@adangel @oowekyala Lombok is removed. If you are happy with the rest please merge it. Or should I just do it?
I am unsure about all the housekeeping (documentation, etc...) needed to get this into 6.31.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel changed the title Include SARIF renderer [core] Include SARIF renderer Jan 26, 2021
adangel
adangel approved these changes Jan 26, 2021
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

mmoyaferrer reacted with hooray emoji rsoesemann reacted with heart emoji
All reactions
  • 🎉 1 reaction
  • ❤️ 1 reaction
@adangel adangel self-assigned this Jan 26, 2021
oowekyala
oowekyala approved these changes Jan 27, 2021
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

mmoyaferrer reacted with heart emoji rsoesemann reacted with rocket emoji
All reactions
  • ❤️ 1 reaction
  • 🚀 1 reaction
@rsoesemann rsoesemann mentioned this pull request Jan 27, 2021
Support SARIF JSON Format forcedotcom/code-analyzer#309
Closed
@adangel adangel added an:enhancement An improvement on existing features / rules and removed in:documentation Affects the documentation [doc] labels Jan 28, 2021
adangel added a commit that referenced this pull request Jan 28, 2021
@adangel
[doc] Update release notes, refs #2953, refs #3073
33a8aa3
adangel added a commit that referenced this pull request Jan 28, 2021
@adangel
Merge pull request #3073 from CopadoSolutions:include-sarif-renderer
df80080
[core] Include SARIF renderer #3073
@adangel
adangel merged commit 7cb3b68 into pmd:master Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rsoesemann rsoesemann rsoesemann left review comments
@adangel adangel adangel approved these changes
@oowekyala oowekyala oowekyala approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

an:enhancement An improvement on existing features / rules

Projects

None yet

Milestone

6.31.0

Development

Successfully merging this pull request may close these issues.

[core] Support SARIF JSON Format

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@mmoyaferrer @rsoesemann @adangel @oowekyala
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.