LOC Count Report or REST API

  • SonarQube 10.6
  • how is SonarQube deployed: zip
    Hi,
    if we summarize all the LOCs in the aggregated portfolios, we get 2,533,000 LOCs, but if we look at the License Manager, we see 5,458,000 LOCs. Is there any report or REST API that can be used to get the real LOC for all projects to determine which ones occupy LOC.

You may use the web api GET api/measures/component with parameter metricKeys=ncloc
https://<yoursonarhost>/api/measures/component?component=com.foo:foobar&metricKeys=ncloc

This will give you the LOC for the main branch by default. To get LOC for other branches, you’ll need to add the branch parameter to your request.

To get the overall LOC you’ll need some scripting to combine web api calls and loop over all projects (the web api is pageinated).

see web api docs
https://<yoursonarhost>/web_api/api/measures/component

If you use Python, another option beside the Sonarqube web api is sonar-loc from the sonar-tools

sonar-loc: Computes lines of code per project and in total, as they would be computed by SonarQube (and the licensing system on commercial editions)

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