1
votes

I am using PMD Plugin for Sonar on Jenkins for the static analysis of my code. I am also running the PMD Plugin for Eclipse (eclipse-pmd 1.5 to be exact ( http://marketplace.eclipse.org/content/eclipse-pmd )).

My problem is the following : I wanto to suppress a certain PMD warning. Lets say that I want to suppress the warning ShortClassName (http://pmd.sourceforge.net/pmd-5.1.1/rules/java/naming.html) on my class named Rule. Look at the following example :

@SuppressWarnings("pmd:ShortClassName")
public class Role {
    //The class fields, constructors, methods ...
}

That works fine to suppress the warning on Sonar. However, it does not suppress the warning on eclipse-pmd. To do a such thing, I must do the following :

@SuppressWarnings({ "pmd:ShortClassName" , "PMD.ShortClassName" })
public class Role {
    //The class fields, constructors, methods ...
}

That works, of course, but it bloats the code. Basically, to be consistent with my two plugins, I have to write (almost) the same suppress warning twice.

So my question is the following : is there a way to change the warning name prefix from eclipse-pmd plugin from PMD. to pmd: , so the same @SuppressWarnings will suppress both warnings from Sonar and eclipse-pmd ?

2

2 Answers

1
votes

No, it is not possible to change the prefix from "PMD." to "pmd:" in eclipse-pmd (I know because I created eclipse-pmd).

It is however possible to use only one of the formats. The reason the two formats exists is that Sonar and eclipse-pmd use different rule engines to analyse the code. eclipse-pmd uses the original PMD engine. Sonar used to use the same engine in the past but a couple of years ago they decided to write their own engine and rewrite most PMD rules for their engine instead. The rules are mostly the same but unfortunately not 100% compatible. The SuppressWarnings format is one of those incompatibilities.

You have to decide which engine you want to use. If you want to use the Sonar engine, then use the SonarQube Eclipse Plugin and of course Sonar. If you want to use the original PMD engine then use eclipse-pmd and the PMD plugin for Sonar (which uses the PMD engine instead of the Sonar engine for the PMD rules).

Both ways have their advantages and disadvantages. If you use the Sonar engine the analysis should be faster, especially if you also use the Checkstyle and Findbugs rules. SonarSource is however still in the process of rewriting the rules so you currently will not have all the rules that are available in PMD (or Checkstyle and Findbugs).

2
votes

I don't believe this is possible, but you can probably get rid of the Eclipse PMD plugin and use the SonarQube plugin for Eclipse. This way you only have to silence the issue on SonarQube (either by annotation, or by marking the issue as false positive).