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
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: PMD
    • Labels:
      None

      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

      1. mpmd84-20100716.patch
        3 kB
        David Matějček

        Activity

        Hide
        david added a comment -

        he..

        i have the same problem with it. It seems that this issue is too unimportant to change.

        So i looked into the source... and i asked me, why isn't the pmd.main() used to call pmd ?!
        (ok, there is not so much configuration possible... )
        But the latest pmd version can easily be configured...

        any suggestions?

        thanks...

        Show
        david added a comment - he.. i have the same problem with it. It seems that this issue is too unimportant to change. So i looked into the source... and i asked me, why isn't the pmd.main() used to call pmd ?! (ok, there is not so much configuration possible... ) But the latest pmd version can easily be configured... any suggestions? thanks...
        Hide
        Paul Panzer added a comment -

        Hi,

        i have the same problem.
        It would be nice if this bug will be fixed.

        Thank you.

        Show
        Paul Panzer added a comment - Hi, i have the same problem. It would be nice if this bug will be fixed. Thank you.
        Hide
        Frans van Buul added a comment -

        Hi,

        I'm having the same problem. In our case, it's quite important and in fact a showstopper for using the plugin in our project.

        The use case is as follows: I need to work with some complex XML schema's. After ws-import/xjc compilation, I end up with more than a 1000 generated classes, that cause many PMD violations. These classes need to be excluded to get useful reports, and to get acceptable PMD plugin
        performance.

        Kind regards,
        Frans van Buul

        Show
        Frans van Buul added a comment - Hi, I'm having the same problem. In our case, it's quite important and in fact a showstopper for using the plugin in our project. The use case is as follows: I need to work with some complex XML schema's. After ws-import/xjc compilation, I end up with more than a 1000 generated classes, that cause many PMD violations. These classes need to be excluded to get useful reports, and to get acceptable PMD plugin performance. Kind regards, Frans van Buul
        Hide
        Hervé Boutemy added a comment -

        if somebody gives a patch, I'm ready to review it

        Show
        Hervé Boutemy added a comment - if somebody gives a patch, I'm ready to review it
        Hide
        David Matějček added a comment -

        I'm not sure if it is perfect, but it looks it works in the test and also in my own project.

        Show
        David Matějček added a comment - I'm not sure if it is perfect, but it looks it works in the test and also in my own project.
        Hide
        Murtuza Akhtari added a comment - - edited

        Is this bug still open?? Because I just tried the same thing and it works for me. I put this in the configuration section

        <excludes>
           <exclude>**/jaxb/**/*.java</exclude>
        </excludes>
        

        I am using maven-pmd-plugin version 2.6. Maybe the bug status needs to be updated.

        Show
        Murtuza Akhtari added a comment - - edited Is this bug still open?? Because I just tried the same thing and it works for me. I put this in the configuration section <excludes> <exclude> **/jaxb/**/*.java </exclude> </excludes> I am using maven-pmd-plugin version 2.6. Maybe the bug status needs to be updated.
        Hide
        Dennis Lundberg added a comment -

        Does anyone have a sample project that we can use to test this?

        Show
        Dennis Lundberg added a comment - Does anyone have a sample project that we can use to test this?
        Hide
        Dennis Lundberg added a comment -

        This has been fixed, but I don't know in which version. I have projects that successfully uses <excludes> to exclude files from PMD.

        Show
        Dennis Lundberg added a comment - This has been fixed, but I don't know in which version. I have projects that successfully uses <excludes> to exclude files from PMD.
        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:
            8 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development