Sonar 1.9 has just been released : installing this new version implies to be aware a few things. I’m not talking here about any technical complexity to upgrade from previous releases but about functional evolutions.
So far, the standard metrics (number of classes, number of comments, cyclomatic complexity…) were gathered using the well known JavaNCSS. However, as mentioned in a previous post, the metrics calculated by the current version of JavaNCSS has some flaws (creating new metrics is pretty difficult, comments are not available at class level), suffers approximations (nested classes are not managed) and crashes on certain code patterns (annotations, generics, none UTF8 characters). Therefore we have decided to proceed with a complete rewrite of JavaNCSS that we named sonar-squid.
Read the rest of this page »
JavaNCSS is an open source tool that generally does not require much introduction to Java developers : indeed it was born at the same time the Java community started to grow (precisely in 1997).
JavaNCSS is a tool that analyzes java source code and reports on what we call the standard metrics : cyclomatic complexity, number of non commenting statements, number of classes, number of methods… Sonar uses the tool during the analysis phase to calculate those standard metrics, establish the Rules Compliance Index (RCI), the percentage of duplicated lines, etc.
Throughout time it has occurred to us that JavaNCSS has got some limitations that make the data reported in Sonar sometimes slightly incorrect :
- Nested classes are ignored
- Javadoc information is not available at class/method level
- Number of physical lines of code is not available
- No way to ignore header comments which usually contain license description
- Annotations and Generics are only partially supported
Those limitations are mainly due to a technical flaw : java grammar and code to calculate metrics were originally developed in a single file. As a consequence, it has become more and more difficult to make the grammar evolve to support new Java versions and it is a bit cumbersome to change the code to calculate new metrics or change existing ones. During the last 10 years, Clemens Lee (the project initiator and leader) kept on maintaining and improving the tool. 10 years is a long time for a software, time has come to build a new house for this old lady !
That is where the Sonar Team comes into play : we thought we could make a contribution to JavaNCSS in order to bypass the current issues. This type of issues has already been solved by others OSS tools such as Checkstyle and PMD : they only use the grammar to generate an Abstract Syntax Tree (AST) that can subsequently be browsed with a visitor pattern. That is what we did when we built a proof of concept based on a checkstyle architecture.
A version of the new tool is currently being packaged as a Sonar plugin (SONARPLUGINS-36) and in the same time we are actively working with the JavaNCSS team to release a new version of the product that leaves behind all the limitations. From there, we will be capable of calculating new metrics such as NPath, Maintainability Index …
Here is an example of impacts on the Project dashboard service :