Sonar is a free OpenSource product that provides you with a general dashboard displaying information about the codebase of each configured project, such as:
- Number of failed tests,
- % of code coverage,
- % of rules compliance (more later),
- % of duplicated lines,
- and much more.
Then you get an additional graphical information showing:
- a square for the size of your project’s codebase relative to the entire codebase’s size,
- a color (from red to green) for the % of rules compliance.
Yet, what are considered rules compliance? These are rules defined by products you (may) already know:
Sonar provides you with the means to configure these rules in 3 categories: mandatory _(error), _optional (warning) or inactive. Some rules can even be configured with parameters, i.e: the maximum number of lines of a method. In this case, you can override the default value.
Sonar uses two modules:
- a Maven plugin that does the real analysis,
- a web application for configuring rules and displaying information.
Analysis results are saved in a database. This enables to you to display the trend of your projects. In Sonar, it is called the Time Machine: if codebase’size stays the same, are there more violations? Or if the codebase’s size increases, does the number of violations increases too?
By default, Sonar uses a Derby (sorry, JavaDB) database but it can easily be configured with a 3rd party database such as Sun MySQL.
Sonar is very simple to use. Just type this line on your Maven2 project directory to do the analysis:
mvn clean install org.codehaus.sonar:sonar-maven-plugin:1.5.1:sonar
The web application must be separately installed but the install process is on par with the analysis. You can have a running Sonar instance in less than 2 minutes (I did it, so anyone can do!).
Since Sonar is a Maven plugin, it should be a breeze to integrate the analysis on a Continuous Integration platform.
All in all, Sonar is a nice easy-to-use product intended for quality managers, project managers and architects alike. Some features, such as the Time Machine, are not provided by any other OpenSource projects that I know of. If you already use one of Checkstyle / PMD / Findbugs, I can’t recommend enough taking a very thorough look at Sonar, you won’t regret it.