Sonar Integration

Last modified by Andreea Popescu on 2021/03/18 11:28

cogShow how to display Sonar metrics in wiki pages
TypeSnippet
Category
Developed by

Vincent Massol

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Sonar offers a REST API (see also Definition of metrics).

Example

Displays some metrics (#ncloc - number of lines of code, tests - number of unit tests, classes - number of classes) from the XWiki Rendering project on Nemo:

{{groovy}}
def url = "http://nemo.sonarsource.org/api/resources?resource=org.xwiki.rendering:xwiki-rendering&metrics=ncloc,tests,classes&format=xml".toURL().text
def root = new XmlSlurper().parseText(url)

root.resource.msr.each() { measure ->
    println "{{box title='**${measure.key}**'}}"
    println "${measure.frmt_val}"
    println "{{/box}}"
    println ""
}
{{/groovy}}

Result:

sonar.jpg

Get Connected