Running local analysis with Sonar Eclipse 2.0

by fabrice bellingard|

    Have you tried Sonar Eclipse? If you're a fan of Sonar and you monitor the quality of your code daily, you probably already have installed this set of plugins that brings the power of Sonar right into your IDE. As a developer, I personally find it really useful to fix the violations directly in the code editor - while you can not do much about it when you're browsing the web resource viewer of Sonar.

    However, even though version 1.0 of Sonar Eclipse was a great first step, a detail was annoying me. Indeed Sonar Eclipse 1.0 was really valuable to decorate on-the-fly source code with quality information available remotely on a Sonar server. But when lot of changes were made locally there wasn't any way to check the quality of those local changes before pushing back to version control. In such case, I had to:

    • Maintain a local instance of Sonar
    • Manually run "mvn sonar:sonar" and wait for it to complete before being able to refresh my workspace and see if I had introduced - or fixed! - any violation.

    Fortunately, Evgeny announced some days ago the availability of Sonar Eclipse 2.0 whose purpose is to run local Sonar analysis directly within Eclipse.

    In this new version, the process to configure Sonar Eclipse stays the same: you associate your local projects with remote projects, and by default Sonar Eclipse will grab data from the server to display it in your workbench. The main change is the ability to choose wether you want to stay in this mode (remote analyses and data transfered from the server to your Eclipse) or if you want to activate local analysis :

    If you want to run local analysis, just select "Locally": Sonar Eclipse will automatically run a first local analysis and refresh all the violations in your workspace. A local analysis uses the same quality profile as the one used on the server for the latest analysis. It currently only executes core plugin rules (Squid, Findbugs, PMD and Checkstyle) - but future work will make it possible to extend this set of rules and to compute metrics too.
    After fixing some violations or adding some extra code, you can launch it again by clicking on "Run Local Analysis":

    As Sonar Eclipse does not depend on Maven anymore, you can run local analysis on any Java project as long as the project is already defined in your Sonar server. This is now that simple to get Sonar violations directly into our code! And no more excuse to overlook our technical debt ;-)

    Enjoy!

    Links: