Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar Report Format v7.5 not Supported #80

Closed
Zakinator123 opened this issue Dec 31, 2019 · 4 comments
Closed

Sonar Report Format v7.5 not Supported #80

Zakinator123 opened this issue Dec 31, 2019 · 4 comments

Comments

@Zakinator123
Copy link

Hello again!

I got everything working with the Violation Comments To Bitbucket Server Command Line library except for one small thing. The SonarParser.java appears to have a small incompatibility between the SonarReportIssue static class and the SonarQube issues API output format from my SonarQube Server (running version 7.5). The inconsistency exists specifically with the location of the startLine and endLine fields. Your parser and report examples expect those fields to be in the top level issues list item, whereas my report has those fields under a new field called textRange. See my sample output below (some information is redacted with "..."):

{
	"total": 324,
	"p": 1,
	"ps": 100,
	"paging": {
		"pageIndex": 1,
		"pageSize": 100,
		"total": 324
	},
	"effortTotal": 10545,
	"debtTotal": 10545,
	"issues": [{
		"key": "AW9ZELWqZbXQApVMssTY",
		"rule": "squid:S1135",
		"severity": "INFO",
		"component": "...",
		"project": "...",
		"subProject": "...",
		"line": 56,
		"hash": "32d0b2527b9a7178c1c08532020e1630",
		"textRange": {
			"startLine": 56,
			"endLine": 56,
			"startOffset": 0,
			"endOffset": 83
		},
		"flows": [],
		"status": "OPEN",
		"message": "Complete the task associated to this TODO comment.",
		"author": "",
		"tags": ["cwe"],
		"creationDate": "2019-12-30T18:06:54-0500",
		"updateDate": "2019-12-30T18:06:54-0500",
		"type": "CODE_SMELL",
		"organization": "default-organization",
		"fromHotspot": false
	}]
}

So what's happening as a result is the SonarParser.java is saying that all the issues are happening in line 0 of every file, which doesn't exist according to Bitbucket.

I see a couple of possible solutions:

  1. Adding a new possible argument to the violations library for choosing a parser version. The library will then delegate to the correct parser based on the version. I think this is probably the most well factored approach, but also requires the most work.
  2. Adding a new parser. Something like SonarParser7_5AndUp.java or something like that and having two parser names of SONAR and SONAR7_5AndUp. The new parser would have the updated model.
  3. Adding some code to SonarParser.java to fix this specific issue. This is not ideal, but definitely requires the least effort. It could be something like this block being added between line 101 and 102 in SonarParser.java:
      if (issue.startLine == 0 && issue.endLine == 0) {
        issue.startLine = issue.line;
        issue.endLine = issue.line;
      }

This last approach is very brittle, and may break some usages of the current implementation (although I doubt it since I don't think Sonar ever outputs an issue to be at line 0), but it is also very easy :)

Please let me know what you think the best course of action is - I'd be happy to help as much as I can to get this to work since I think this library is awesome.

~ Zakey

@Zakinator123
Copy link
Author

One other option I just thought about was just manually manipulating the sonar output myself so that the format is in the format expected by your parser.. I am fine with this approach as well.

@tomasbjerre
Copy link
Owner

tomasbjerre commented Dec 31, 2019 via email

@Zakinator123
Copy link
Author

Ok I'll try to put up a fix for the existing parser in the next day or two.

@Zakinator123 Zakinator123 changed the title Newer Sonar Report Format not Supported Sonar Report Format v7.5 not Supported Jan 2, 2020
tomasbjerre added a commit to tomasbjerre/violations-git-lib that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violations-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violations-gradle-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violations-maven-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-bitbucket-cloud-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-bitbucket-cloud-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-bitbucket-server-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-github-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-github-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-github-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-github-gradle-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-github-maven-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-gitlab-command-line that referenced this issue Jan 3, 2020
tomasbjerre added a commit to jenkinsci/violation-comments-to-github-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-gitlab-gradle-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-gitlab-gradle-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to tomasbjerre/violation-comments-to-gitlab-maven-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to jenkinsci/violation-comments-to-gitlab-plugin that referenced this issue Jan 3, 2020
tomasbjerre added a commit to jenkinsci/violation-comments-to-stash-plugin that referenced this issue Jan 3, 2020
@tomasbjerre
Copy link
Owner

Should be released in all the plugins now.

aakoch pushed a commit to aakoch/violation-comments-to-stash-plugin that referenced this issue Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants