The Sonar Perspective
Sonar Eclipse provides one Eclipse perspective and four Eclipse views. Those Eclipse views can of course be used outside the "Sonar" Eclipse perspective, but this tutorial describes the default "Sonar" Eclipse perspective layout.
To activate the "Sonar" Eclipse perspective, click on "Windows -> Open Perspective -> Other..." and select "Sonar":
The Measures View
The Measures view allows to gather all available measures on the selected ressource. Most of the time, developers focus their attention on only a few 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 possible by right clicking on the metric name:
The Violations View
The Violations view displays the list of violations to quality rules for the selected ressource:
A double-click on a violation opens the source code editor and highlights 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
The Hotspots view allows to quickly identify hotspots on files according to favourite metrics (defined in the Measures view). You can for instance look at files with the greatest number of duplicated lines, greatest number of violations, greatest number of uncovered lines by unit tests...
The Web View
The Web view displays the web Sonar dashboard (for projects and packages) or the web Sonar ressource viewer (for files). This web page can be used to access information and services (cloud, treemap, ...) that are not yet natively available in Sonar Eclipse:
Run Local Analyses
By default Sonar Eclipse takes care to automatically collect information from the Sonar Web server and decorates the source code on-the-fly. This default behavior is pretty useful as it doesn't consume any CPU or memory on the developer's computer while quickly displaying valuable quality information as soon as a new source file is opened. But if lots of source code is modified locally, quality information available remotely might be desynchronized after a while. In that case, a local quality analysis can be run before committing any changes to the source code repository and with the same quality profile used to analyze the project remotely.
Switching from the remote to the local mode can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Sonar -> Analyse -> Locally". As soon as this mode is selected a local analysis is launched to update Violations and Measures views.
Later, at any time, you can run a new local analysis by choosing "Configure -> Sonar -> Run Local Analysis.
A Sonar Mylyn connector allows to track all open reviews assigned to the current user. To start using this feature, a new Sonar task repository and a query to get all reviews assigned to the current user must be created first (see the Mylyn documentation page):
Then the "Task List" view must be used to start working on all those assigned reviews:
From there, double clicking on a review open the detail of that review:
All operations on reviews available through the Sonar web interface are also available in Mylyn, so a review can be commented, fixed, reassigned, flagged as false-positive and reopened. Moreover a review can be created directly from the Eclipse source code editor on an existing violation:
This Mylyn extension has currently the following limitations that should be quickly fixed:
- There is no way to create a review that doesn't relate to an existing violation
- There is no way to create a Mylyn query with filters in order for instance to retrieve reviews only on a project, or reviews assigned to another user
- There is non way to add a review to an action plan: SONARIDE-286