Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export FindBugs/PMD/Checkstyle rules from Sonar and import into Netbeans

My company has sonar set up to with various plugins (PMD, FindBugs, CheckStyle), and although it is very useful as is (it runs after every Jenkins build that was triggered by a check-in to SVN), I would like it if I could run these various plugins on my local machine before I check the code in.

We have a set of rules already set up in Sonar, so ideally I would like to be able to export that ruleset, perhaps do some munging of the data, and then import the resulting rules into my IDE (Netbeans 7.0.1) into the respective plugins. Is there any way to do this? I've searched all over and short of going through and manually adding each rule to the various plugins, there doesn't appear to be a way to do this. Is there something I'm missing?

TL;DR (Summary): I'd like to export a profile from sonar and import the rule settings into the PMD, Findbugs, and CheckStyle plugins in Netbeans.

like image 233
jalsk Avatar asked Nov 16 '11 16:11

jalsk


People also ask

Is SonarQube replacing Checkstyle PMD FindBugs?

Yes and no. In addition to the other answers. SonarQube is currently on the way to deprecate PMD, Checkstyle and Findbugs and use their own technology to analyze Java code (called SonarJava).

What is PMD Checkstyle FindBugs?

PMD, FindBugs and Checkstyle, are the most popular open-source code analyzers, they are extensively used in Java development to improve the codebase and identify potential vulnerabilities along with design flaws; every tool has its feature, purpose and strength, targeting a specific type of coding rules.

Does SonarQube use Checkstyle?

SonarQube, natively, cannot run PMD and Checkstyle, only consume the reports those tools generate. You'll need to run those tools to generate the reports prior to your SonarQube analysis.


2 Answers

Each Sonar profile publishes it's Checkstyle, FIndbugs and PMD configuration under the permalinks tab.

Assuming you've got Sonar installed locally, the following link shows the configuration files used by the "Sonar Way" profile:

http://localhost:9000/profiles/permalinks/2

like image 156
Mark O'Connor Avatar answered Sep 30 '22 07:09

Mark O'Connor


You don't need your own Sonar installation. You can get the configuration of any of Sonar's built-in Quality Profiles from Sonar's Nemo site:

There are about a dozen Java Quality Profiles. A commonly used profile - Sonar way with Findbugs - is available at:

http://nemo.sonarsource.org/rules_configuration/index/135

The initial Profile view just lists all the rules. Don't use the "Download" link on that view. That just gives you a CSV listing of the merged rules across all tools. Helpful for review, but not what you're asking for.

To export the tool-specific configuration, select the Permalinks tab/view. Those links return the configuration file in the form expected by each tool. For example, here's the link for the FindBugs XML configuration file:

http://nemo.sonarsource.org/profiles/export?format=findbugs&language=java&name=Sonar%2520way%2520with%2520Findbugs

like image 25
Xris - Flatbush Gardener Avatar answered Sep 30 '22 05:09

Xris - Flatbush Gardener