Maven PMD Plugin
  1. Maven PMD Plugin
  2. MPMD-84

Maven PMD plugin does not honour exclude-pattern in PMD rulesets

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: PMD
    • Labels:
      None
    • Number of attachments :
      1

      Description

      According to PMD documentation, exclude-patterns should be independendant on the program running PMD :
      http://pmd.sourceforge.net/howtomakearuleset.html

      But Maven scans through all the files, not taking into account the exclude-patterns and thus including files that shouldn't be.

      THose file should be filtered out by the maven plugin

        Activity

        Hide
        Ed Bras added a comment -

        It's not fixed!
        Yes, the "<excludes>" in maven works well, I use it, but the issue is about the <exclude-pattern> ...
        But, the "<exclude-pattern>" doesn't work in a ruleset xml file (like explained in the url listed in the original issue).

        I just tested it several times against 2.5. I changed the package pattern, etc... but didn't got it to work. The only way I got it to exclude to run the rule against the gwt pacakges was to exclude the complete file that contains the rulesets ... See below for details, I hope this helps.

        Example: I use it to exclude rules against google GWT code.
        My pom snippet:


        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>2.5</version>
        <configuration>
        <rulesets>
        <ruleset>../rulesets/basic.xml</ruleset>
        ....
        ....
        <ruleset>../rulesets/safeGwt.xml</ruleset>
        </rulesets>
        <linkXref>true</linkXref>-->
        <sourceEncoding>utf-8</sourceEncoding>
        <minimumTokens>100</minimumTokens>
        <targetJdk>$

        {java.version}

        </targetJdk>
        <excludes>
        <exclude>**/Assert.java</exclude>
        </excludes>
        </configuration>
        <dependencies>
        <dependency>
        <groupId>bla</groupId>
        <artifactId>project containing the rulesets in the classpath.</artifactId>
        <version>$

        {version.ited.gen}

        </version>
        </dependency>
        </dependencies>
        <executions>
        <execution>
        <phase>$

        {report.phase}

        </phase>
        <goals>
        <goal>check</goal>
        <goal>cpd-check</goal>
        </goals>
        </execution>
        </executions>
        </plugin>


        And the safeGwt.xml contains (not all rules included):


        <ruleset name="Custom ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
        http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

        <!-- Exclude the gwt packages -->
        <exclude-pattern>./gwt/.</exclude-pattern>

        <rule name="NonThreadSafeSingleton" message="Singleton is not thread safe"
        class="net.sourceforge.pmd.rules.design.NonThreadSafeSingleton"
        [... all rule details ...]
        </rule>

        </ruleset>


        Show
        Ed Bras added a comment - It's not fixed! Yes, the "<excludes>" in maven works well, I use it, but the issue is about the <exclude-pattern> ... But, the "<exclude-pattern>" doesn't work in a ruleset xml file (like explained in the url listed in the original issue). I just tested it several times against 2.5. I changed the package pattern, etc... but didn't got it to work. The only way I got it to exclude to run the rule against the gwt pacakges was to exclude the complete file that contains the rulesets ... See below for details, I hope this helps. Example: I use it to exclude rules against google GWT code. My pom snippet: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.5</version> <configuration> <rulesets> <ruleset>../rulesets/basic.xml</ruleset> .... .... <ruleset>../rulesets/safeGwt.xml</ruleset> </rulesets> <linkXref>true</linkXref>--> <sourceEncoding>utf-8</sourceEncoding> <minimumTokens>100</minimumTokens> <targetJdk>$ {java.version} </targetJdk> <excludes> <exclude>**/Assert.java</exclude> </excludes> </configuration> <dependencies> <dependency> <groupId>bla</groupId> <artifactId>project containing the rulesets in the classpath.</artifactId> <version>$ {version.ited.gen} </version> </dependency> </dependencies> <executions> <execution> <phase>$ {report.phase} </phase> <goals> <goal>check</goal> <goal>cpd-check</goal> </goals> </execution> </executions> </plugin> And the safeGwt.xml contains (not all rules included): <ruleset name="Custom ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd "> <!-- Exclude the gwt packages --> <exclude-pattern>. /gwt/. </exclude-pattern> <rule name="NonThreadSafeSingleton" message="Singleton is not thread safe" class="net.sourceforge.pmd.rules.design.NonThreadSafeSingleton" [... all rule details ...] </rule> </ruleset>
        Hide
        Dennis Lundberg added a comment -

        Ed,

        Can you please zip up a complete sample project that shows off this issue.
        Without one it is very difficult for us to verify it.

        Show
        Dennis Lundberg added a comment - Ed, Can you please zip up a complete sample project that shows off this issue. Without one it is very difficult for us to verify it.
        Hide
        Ed Bras added a comment -

        Sorry, not possible, too complex, too big (many maven parents, many projects...etc..), and the client will not allow me...

        > Without one it is very difficult for us to verify it.
        Why?
        My idea: create an eclipse project, copy the above to maven snippet in a maven pom.xml, create the ruleset, create some included and exlcuded pacakges, and test it..
        I don't understand your comment...

        BTW: I get the idea, from googling about this issue that the plugin exclude is the same as ruleset exclude-pattern and is only used in the "root" ruleset. I can't find the exact link anymore, but I read something about that....
        In my case the rulsets are all defined in the pom.xml, which is then the "root", and only the contained exclude in ht pom.xml is then used, any other nested excluded like exclude-pattern are simple ignored...
        In case of ANT, you are can include a ruleset directly in the ant file, which is then the "root" such that the contained exlude-pattern in the ruleset is then used and other nested exclude-pattern's are ignored..

        Ofcourse this is very restricted and confusing.. but seems a possible explication.

        Show
        Ed Bras added a comment - Sorry, not possible, too complex, too big (many maven parents, many projects...etc..), and the client will not allow me... > Without one it is very difficult for us to verify it. Why? My idea: create an eclipse project, copy the above to maven snippet in a maven pom.xml, create the ruleset, create some included and exlcuded pacakges, and test it.. I don't understand your comment... BTW: I get the idea, from googling about this issue that the plugin exclude is the same as ruleset exclude-pattern and is only used in the "root" ruleset. I can't find the exact link anymore, but I read something about that.... In my case the rulsets are all defined in the pom.xml, which is then the "root", and only the contained exclude in ht pom.xml is then used, any other nested excluded like exclude-pattern are simple ignored... In case of ANT, you are can include a ruleset directly in the ant file, which is then the "root" such that the contained exlude-pattern in the ruleset is then used and other nested exclude-pattern's are ignored.. Ofcourse this is very restricted and confusing.. but seems a possible explication.
        Hide
        Dennis Lundberg added a comment - - edited

        > Without one it is very difficult for us to verify it.

        Why?

        My idea: create an eclipse project, copy the above to maven snippet in a maven pom.xml, create the ruleset, create some included and excluded packages, and test it..

        I don't understand your comment...

        Well, it's quite simple really. You have a problem that you want help solving. You have the knowledge about your configuration, what files you are using and what is going wrong.

        Here's an idea: why don't you do what you suggested above, zip up the files and add them to this issue.

        Show
        Dennis Lundberg added a comment - - edited > Without one it is very difficult for us to verify it. Why? My idea: create an eclipse project, copy the above to maven snippet in a maven pom.xml, create the ruleset, create some included and excluded packages, and test it.. I don't understand your comment... Well, it's quite simple really. You have a problem that you want help solving. You have the knowledge about your configuration, what files you are using and what is going wrong. Here's an idea: why don't you do what you suggested above, zip up the files and add them to this issue.
        Hide
        Ed Bras added a comment -

        > Well, it's quite simple really. You have a problem that you want help solving.
        > You have the knowledge about your configuration, what files you are using
        > and what is going wrong.
        Of course, that's why I posted the above config, that's all I can do in my side.

        > Here's an idea: why don't you do what you suggested above, zip up the files and
        > add them to this issue.
        I still don't understand your reaction as writing your comment will cost you the same amount of time to setup the above, assuming you are a PMD plugin expert.
        Good luck.

        Show
        Ed Bras added a comment - > Well, it's quite simple really. You have a problem that you want help solving. > You have the knowledge about your configuration, what files you are using > and what is going wrong. Of course, that's why I posted the above config, that's all I can do in my side. > Here's an idea: why don't you do what you suggested above, zip up the files and > add them to this issue. I still don't understand your reaction as writing your comment will cost you the same amount of time to setup the above, assuming you are a PMD plugin expert. Good luck.

          People

          • Assignee:
            Unassigned
            Reporter:
            Denis Cabasson
          • Votes:
            9 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: