问题
How does Sonar calculates software metrics particularly LOC and cyclomatic complexity? Does it uses any particular tools? IF yes, please also give the names.
回答1:
For each supported language, a "squid" plugin is used to parse the source code and determine some base metrics such as LOC and complexity. How the complexity is calculated varies based on the plugin.
For example, here's the source code files for the JavaScript plugin: https://github.com/SonarCommunity/sonar-javascript/tree/master/javascript-squid/src/main/java/org/sonar/javascript/metrics In this case, the complexity is calculated in the plugin itself using a very simple formula.
And here is the same set of classes for the C# support: https://github.com/SonarCommunity/sonar-dotnet/tree/master/sonar/csharp/sonar-csharp-squid/csharp-squid/src/main/java/com/sonar/csharp/squid/metric
The creation of metrics, though, can be done by any plugin, so you could write your own plugin if you wanted to supplement the data, or display the data in a different way.
Also take a look at the answer to this question (about creating a new plugin) by Fabrice, one of the .Net plugin maintainers: SonarQube - help in creating a new language plugin
回答2:
You can browse http://docs.codehaus.org/display/SONAR/Metric+definitions for more details.
来源:https://stackoverflow.com/questions/19178315/sonar-loc-cyclomatic-complexity