LOC

40 views
Skip to first unread message

Betty

unread,
Dec 4, 2017, 6:38:15 PM12/4/17
to SonarQube
Hi there,
Hope this message finds you well.

I want to know how many LOC (global amount) are we currently processing in SonarQube? We only need the main project (for example: develop branch), not LOC for all other branches. 

Our QunarQube version is 6.4 (build 25310). 

Based on this docs, it's to query the dabtebase. 

My questions:
1. How to query the SonarQube directly? 
2. Which table used to store the global amount LOC?
3. Can you please share some example codes for getting accurate of LOC without the lines for other branches?

Thank you very much,
Betty

Colin Mueller

unread,
Dec 4, 2017, 7:07:36 PM12/4/17
to SonarQube
You could update to 6.7 and find that information on the System Info page, but if that isn't an option, you will need reader access to the database backing your SonarQube instance and run that query against it. 

The documentation you linked to contains the exact query you need to run (no need to understand the table structure) and whether a query exists that excludes branches. All the info and that code is in that documentation.

nicolas...@sonarsource.com

unread,
Dec 5, 2017, 5:56:40 AM12/5/17
to SonarQube
Hi Betty,

Adding to Colin's response, when it comes to branches, do remain aware of the branch-specific note mentioned in that documentation page: This query is accurate only if projects with branches are also analysed once without sonar.branch. You seem to suggest that your main project can be the one with branch develop (i.e. sonar.branch is used even for the main project), in which case the SQL query will not be able to distinguish branches of one same project (and will count LOCs for each branches).

Keep in mind though: these SQL queries are just potential helpers. If they don't apply to your case (e.g. because sonar.branch is systematically used) then you still have other options moving forward. The basic one being to manually review the main projects (i.e. the ones you don’t consider as branches) and aggregate LOCs (measure reported under the Measures page, Size tab). And if needed you can also do that programmatically , using the SonarQube WebAPI (documentation embedded in your server, see for example api/projects and api/measures ).

Best regards,
Nicolas
Reply all
Reply to author
Forward
0 new messages