Sonar Eclipse provides a comprehension Sonar integration for Eclipse. With this Eclipse plugin, java developers don't need anymore to leave their favorite IDE in order to get valuable information about the source code quality. Most of the information displayed in the Sonar Web interface is now available in Eclipse. Sonar Eclipse takes care to automatically collect information from the Sonar Web server and decorates the source code on-the-fly.
Installing Sonar Eclipse is straightforward, for instructions, prerequisites, and a demonstration video, go to Installing Sonar Eclipse.
- Get all quality measures on project, package and file ressources
- Find quality hotspots according to selectable metric : files with most duplicated lines, most complex files, files with most uncovered lines by unit tests, ...
- On-the-fly decoration of the source code with violation to quality rules
- List of all known violations to quality rule on selected ressources (project, package, file)
- Bridge with the Sonar Web ressource viewer to display additional information not yet fully integrated into the Eclipse GUI like the lines and branches uncovered by unit tests.
Configure Sonar Eclipse
Sonar Eclipse is pre-configured to work with local Sonar server listening on http://localhost:900/. If you want to use your corporate Sonar server(s), you must first define this server by using the Eclipse global Preferences window :
Once your Sonar server has been defined, the next step is to "link" your eclipse projects with projects defined and analysed in your corporate Sonar server(s). This linkage operation can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Associate with Sonar..." :
You can now start to use Sonar Eclipse and fix quality flaws.
Use Sonar Eclipse
Sonar Eclipse provides one eclipse perspective and four eclipse views. Those eclipse views can of course be used outside the "Sonar" eclipse perspective, but in the following tutorial we are going to work with the provided perspective.
To activate the "Sonar" eclipse perspective, click on "Windows -> Open Perspective -> Other ..." and select "Sonar" :
The Measure view allows to get all available measures on the selected ressources. Most of the time, developers focus their attention on only few important metrics like complexity, uncovered lines of code by unit tests, duplicated lines, ... and want to get a quick overview on those metrics. That's why favourite metrics are displayed on the top of the Measures view. Adding or Removing a metric from the favourites list is made possible by right clicking on the metric name :
The Violations view displayed the list of all violations to quality rules for the selected ressources (project, package, file) :
A double-click on a violation open the source code editor and highlight the violation :
Once a violation has been fixed, you can simply delete it by clicking on the violation icon and then by selecting the "Delete violation" item. Deleting a violation also removes it from the Violations view :
The Hotspots view allows to quickly identify hotspots (files) according to favourite metrics (defined in the Measures view). You can for instance look for files with the greatest number of duplicated lines, greatest number of violations, greatest number of uncovered lines by unit tests, ... :
The Web view displays the web Sonar dashboard (for projects and packages) or the web Sonar ressource viewer (for files). This web page could be used to access quality information or tools (like clouds, treemap, ...) that are not yet natively available in Sonar Eclipse :