0

I've written a Sonar PMD extension plugin to add my custom written PMD ruleset into Sonar. It works perfectly fine. I also have written few rules where my rule type resolves to check whether my rule is applicable for a class or variable. In those cases, I have added the jars (which has those specific classes I look for) into my extension-plugin jar and it worked.

Now, I'm trying to write a rule where it checks a variable usage only if the type inherits from my interface. I used the same PMD TypeHelper and packaged the jar which contains my Interface. But, since the source code being analyzed is not loaded into the classpath, my TypeHelper is not really working.

This "How to write a PMD rule" page talks about Auxilary classpath. How to configure it when I'm running my analysis using Sonar MOJO. Also, it is possible to get it auto-configured with my maven project & its dependencies loaded into that?

Cœur
  • 37,241
  • 25
  • 195
  • 267
R Kaja Mohideen
  • 909
  • 1
  • 8
  • 24
  • This interface that the checked classes may implement, is it part of the source code of the project being analyzed? – barfuin Jan 19 '15 at 21:42
  • @Thomas Correct. I'm trying to detect usage of XmlObject (XmlBeans Lib). – R Kaja Mohideen Jan 20 '15 at 08:38
  • OK, well this should just work. Can you give the XML configuration of your XPath rule, please. You can get that be saving the PMD permalink on your quality profile. – barfuin Jan 20 '15 at 08:59
  • My rule is implemented in Java by extending from AbstractJavaRule. I check whether a Variable is of type generated from Xml schema using `if (TypeHelper.isA(variableDeclaratorIdNode.getNameDeclaration(), XmlObject.class))` – R Kaja Mohideen Jan 20 '15 at 15:48
  • 1
    The maven PMD plugin does auto-configure auxclasspath, as long as it's enabled (see https://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html#typeResolution). The default was originally false, but was recently changed to true. – Johnco Aug 02 '17 at 15:34

0 Answers0