Local and Remote Mode Concepts
Within the remote mode, resources (projects, files, etc.) are decorated in Eclipse with data (measures, violations, etc.) coming from the previous Sonar server analysis.
- You will not see any violation introduced in the code that you just added.
- Metrics (number of lines for example) will display values that will not match what you see in Eclipse if you added some code.
- You will see the violations introduced in the code that you just added.
- Metrics (number of lines for example) will display values that will match what you see in Eclipse if you added some code.
Switch from one mode to another
To switch from one mode to another, right-click on the project, then select Sonar => Analyse... => Remotely or Locally
Features below will be tagged as Remote or/and Local depending on their availability.
The Sonar Eclipse 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 (Remote and Local)
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, etc. 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 (Remote and Local)
The Violations view displays the list of violations of the selected resource (project, file, etc.):
The Hotspots View (Remote)
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, the greatest number of violations, the greatest number of uncovered lines by unit tests, etc.
The Web View (Remote)
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:
Fix violations on the fly
Sonar Eclipse has been designed to help you quickly fix violations as soon as you bump into them.
Fix a violation right away (Remote and Local)
Go through the Violations view that displays the list of violations of the selected resource (project, file, etc.):
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:
Create a review (Remote)
If, for any reason, you cannot fix a violation right away but you think that it is valuable to fix it quickly, you can create a review on it.
Manage your quality improvement tasks (Remote)
The reviews can be browsed through the Task List view:
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.
Check that you are not adding any technical debt in your code (Local)
Run Local Analysis (Local)
By default Sonar Eclipse takes care to automatically collect information from the Sonar Web server and decorates the source code on-the-fly (remote mode). This default mode is pretty useful as it does not 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 has been modified locally, quality information available remotely might be quite desynchronized after a while. In that case, a local 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.
To run a local analysis, switch to the local mode. As soon as this mode is selected a local analysis is launched to update the Violations and Measures views.
Later, at any time, you can run a new local analysis by choosing Sonar => Run Local Analysis.