Reorder the results of sonarqube and display it back in sonarqube dashboard/code section

I am using Sonarqube Community Edition Version 9.8. Is it possible to display the already scanned data in sonarqube dashboard by reordering the files in code section?

For Eg: Folder A contains file1,file2,file3 and Folder B contains file4,file5,file6. And the output should be Package A → file2,file4 and Package B->file3,file6.

Or Is there any way to modify the results of sonarqube and display it back in the sonarqube dashboard ?

Hey there.

What your describing doesn’t sound possible (SonarQube reflects what you would see in the filesystem). Can you describe why you want to do this?

Hi Colin ,
Thanks for the reply.

The files available in the various directories of the source code are owned by various owners. Based on ownership, I wish to group the files and show the coverage.

If sonarqube cannot do it, I will develop an external script to group it by retrieving the scanned result from sonarqube. However, I want to display that output in SonarQube. Is there any way to do this? Kindly suggest.

It’s not possible to split out specific directories (that aren’t already in a hierarchy that indicates ownership, like Owner 1 owns all subdirectories under /Directory1/, at which point you could just use the Code tab of a project)

You would either need to analyze these as separate projects (adjusting the analysis scope to only include specific directories), or manage this via external reporting.

1 Like

Got it. Thanks for the clarification Colin!

Hi @Colin ,
As per the above discussion, I planned to write an external script to get the coverage details for specific files/folders from sonarqube using web api. I want to group those files/folders and to provide overall coverage for that.
For eg :
Group1 → File1, File2, File3, Folder1, Folder2
Group2 → File4, File5, File6, Folder3, Folder4

I want to calculate the overall coverage for the Group1 and Group2 manually. In sonarqube documentation, I found the below formula.

Coverage = (CT + CF + LC)/(2*B + EL)
where:
CT = conditions that have been evaluated to ‘true’ at least once
CF = conditions that have been evaluated to ‘false’ at least once
LC = covered lines = linestocover - uncovered_lines
B = total number of conditions
EL = total number of executable lines

  • Is this formula applicable to calculate the overall coverage group wise?
  • And how to get the values for the below terms using the web API ?
    CT = conditions that have been evaluated to ‘true’ at least once
    CF = conditions that have been evaluated to ‘false’ at least once

Kindly clarify.

You should only need to worry about the overall coverage metric, instead of trying to recalculating it from measures like lines_to_cover and uncovered_conditions.

Ya, I can get the coverage directly for the specific files with the ‘coverage’ metric using the web api. But my requirement is to provide overall coverage for specific files/folders.

For eg: 100’s of files/folders coverage result is displayed in the sonarqube dashboard. Among the 100’s of files/folders, I can retrieve the coverage results of 3 particular files and 1 folder using ‘coverage’ metric in sonarqube web api.

File1 : 7% coverage
File2 : 5% coverage
File3 : 3% coverage
Folder1 : 6% coverage
Overall coverage: ?

Now, I want to calculate overall coverage of those 3 files and 1 folder manually. For that, I found the coverage formula in sonar documentation. But the formula requires these 2 values ( CT = conditions that have been evaluated to ‘true’ at least once
CF = conditions that have been evaluated to ‘false’ at least once). I couldn’t find a way to retrieve those 2 values using sonarqube web api for those specific files/folders.
Is there any possibilities to find these values using sonarqube web api? I would like to know whether this is possible via sonarqube web api or Is there any other way to calculate the overall coverage manually?
Plz clarify this.

You can use these metrics when calculating coverage:

Coverage = (conditions_to_cover - uncovered conditions + lines_to_cover - uncovered_lines ) / (conditions_to_cover + lines_to_cover )

Thanks much @Colin !
Able to compute the overall coverage manually using this formula.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.