Quality gate for coverage of complex methods in SonarQube 6.3

260 views
Skip to first unread message

matya...@gmail.com

unread,
Mar 21, 2017, 1:00:30 AM3/21/17
to SonarQube
Hi,

I am trying to measure coverage on complex methods, but so far with very limited success.

Is it possible to define a custom metric and set up a quality gate in 6.x (or 5.x for that matter) for "coverage on complex method", i.e. coverage on methods that have a complexity of over "N" (likely N=2)?
Or if this is not possible, can coverage calculation report be restricted to only classes (speaking about JAVA here) with complexity/method > 2?
Third, can the Complexity "TreeMap" be somehow customized so that the size would be COMPLEXITY instead of LINES of CODE?

Thanks for the help in advance. 
M.

G. Ann Campbell

unread,
Mar 21, 2017, 4:02:36 AM3/21/17
to SonarQube, matya...@gmail.com
Hi M,

What you're describing falls into the 'custom plugin' territory. That would allow you to define your own metric and determine how it counted. It would also allow you to extend the interface to add your own graphs. The Extension Guide should get you started. Feel free to open new threads with specific coding questions.


Ann

matya...@gmail.com

unread,
Apr 21, 2017, 7:24:35 AM4/21/17
to SonarQube, matya...@gmail.com
I understand 1 and 2 can be done in an extension. But surely, #3 (make the Complexity "TreeMap" customizable so that the size would be either LINES of CODE or COMPLEXITY) should be easier to do in the core.
Anyway, I'd also appreciate, if you could point me to the correct file in the sources that provides this treeView map for the coverage report. Thanks in advance.

Stas Vilchik

unread,
Apr 21, 2017, 7:47:03 AM4/21/17
to SonarQube, matya...@gmail.com
Hello,

It is not possible to customize the treemap widget, and we currently have no plans to change this.

As Ann said, you can create your own plugin and extend the UI with any charts.

Regards,


On Tuesday, 21 March 2017 06:00:30 UTC+1, matya...@gmail.com wrote:

matya...@gmail.com

unread,
Apr 21, 2017, 8:12:02 AM4/21/17
to SonarQube, matya...@gmail.com
So where exactly can I find the current implementation of the Coverage Treemap for inspiration?

Stas Vilchik

unread,
Apr 21, 2017, 8:16:04 AM4/21/17
to matya...@gmail.com, SonarQube
You can have a look in this file to get the generic treemap implementation, and in this file to understand how to use this component.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/wlEEidc8f10/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/7bcc6315-f01b-40e6-974e-3921d2225103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

matya...@gmail.com

unread,
Apr 24, 2017, 8:42:31 AM4/24/17
to SonarQube, matya...@gmail.com
Thanks.
I am looking into the sample-plugin. In there, it seems I need to write a MeasureComputer. Inside the compute() method, I'd like to go to method level and get the coverage and complexity values of those components to be able to calculate a new measure. However, it seems, I can only go to file level and not deeper. Am I missing something? What are the "VIEW" "SUBVIEW" and "MODULE" component types? The page http://javadocs.sonarsource.org/6.3/apidocs/org/sonar/api/ce/measure/Component.Type.html is not really helpful.

Julien Lancelot

unread,
Apr 25, 2017, 7:17:53 AM4/25/17
to matya...@gmail.com, SonarQube
Hi,

A MeasureComputer can be used to compute measure at any level, as long as the measures exist on lower level.
Why are you saying that "I can only go to file level and not deeper" ? 

+++

You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/36455283-696e-4df4-b942-67ea65f62c57%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Julien LANCELOT | SonarSource

matya...@gmail.com

unread,
Apr 25, 2017, 2:08:11 PM4/25/17
to SonarQube, matya...@gmail.com
Hi,

Thanks for the quick follow up. I was saying I can't go below file level, is the following:

In there I'd like iterate over the methods of a file, but there's no component level for METHOD. But since you say this must be possible I must be obviously looking at the wrong place.
So how would I create a measure called, say "MAX COMPLEXITY" which should show the "complexity of the most complex method among all the methods in a given file/class [in java]"?

M.

matya...@gmail.com

unread,
May 10, 2017, 5:03:12 PM5/10/17
to SonarQube, matya...@gmail.com
Any hint how to proceed?


On Tuesday, April 25, 2017 at 7:08:11 PM UTC+1, matya...@gmail.com wrote:
Hi,

Thanks for the quick follow up. Reason I was saying I can't go below file level, is the following:
Reply all
Reply to author
Forward
0 new messages