Skip to content
This repository has been archived by the owner on Oct 7, 2019. It is now read-only.

findbugs-maven-plugin ignores the configuration inside the <execution> node #54

Open
rainbow702 opened this issue Mar 21, 2017 · 1 comment

Comments

@rainbow702
Copy link

rainbow702 commented Mar 21, 2017

The following is my project structure:

|-- etc
|   `-- excludeFilter.xml
|-- pom.xml
|-- src
|   |-- main
|   |   |-- java
|   |   |   `-- org
|   |   |       `-- rainbow
|   |   |           `-- test
|   |   |               `-- BugController.java
|   |   `-- resources
|   `-- test
|       `-- java

The content of BugController.java is:

package org.rainbow.test;

public class BugController {
    public void test() {
        int a = 1 / 0;
    }
}

The pom.xml is like the following at the beginning:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.rainbow</groupId>
    <artifactId>fb-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>3.0.4</version>
                <executions>
                    <execution>
                        <id>check</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Then, I ran the command:

mvn clean compile

Obviously, the findbugs failed, and it printed out the reason:

[INFO] Dead store to a in org.rainbow.test.BugController.test() [org.rainbow.test.BugController] At BugController.java:[line 5] DLS_DEAD_LOCAL_STORE

Then, I wanted to ignore this bug. After reading the Filter File Doc, I just wrote the following exclude-file (named excludeFilter.xml, showed in the project structure):

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Class name="~.*"/>   <!-- ignore all bug warnings -->
    </Match>
</FindBugsFilter>

And I added a configuration to the plugin execution as following:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>3.0.4</version>
    <executions>
        <execution>
            <configuration>
                <effort>default</effort>
                <failOnError>true</failOnError>
                <excludeFilterFile>${project.basedir}/etc/excludeFilter.xml</excludeFilterFile>
            </configuration>
            <id>check</id>
            <phase>compile</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Then I ran the command again:

mvn clean compile

I thought the bug should be ignored, but unfortunately, it was still there.

And then I ran the command again with -X option to see the detail:

mvn clean compile -X

The following is a snippet from the output of the above command:

[INFO] --- findbugs-maven-plugin:3.0.4:check (check) @ fb-test ---
[DEBUG] Configuring mojo org.codehaus.mojo:findbugs-maven-plugin:3.0.4:check from plugin realm ClassRealm[plugin>org.codehaus.mojo:findbugs-maven-plugin:3.0.4, parent: sun.misc.Launcher$AppClassLoader@d16e5d6]
[DEBUG] Configuring mojo 'org.codehaus.mojo:findbugs-maven-plugin:3.0.4:check' with basic configurator -->
[DEBUG]   (s) classFilesDirectory = /home/rainbow/workspace/study/fb-test/target/classes
[DEBUG]   (s) compileSourceRoots = [/home/rainbow/workspace/study/fb-test/src/main/java]
[DEBUG]   (s) debug = false
[DEBUG]   (s) effort = default
[DEBUG]   (s) excludeFilterFile = /home/rainbow/workspace/study/fb-test/etc/excludeFilter.xml
[DEBUG]   (s) failOnError = true
[DEBUG]   (s) findbugsXmlOutput = true
[DEBUG]   (s) findbugsXmlOutputDirectory = /home/rainbow/workspace/study/fb-test/target
[DEBUG]   (s) fork = true
[DEBUG]   (s) includeTests = false
[DEBUG]   (s) localRepository =       id: local

We can see that the check execution goal got the configuration excludeFilterFile, but it still printed out the bug:

[DEBUG] Executing findbugs:check
[DEBUG] Here goes...............Executing findbugs:check
[INFO] BugInstance size is 1
[INFO] Error size is 0
[INFO] Total bugs: 1
[INFO] Dead store to a in org.rainbow.test.BugController.test() [org.rainbow.test.BugController] At BugController.java:[line 5] DLS_DEAD_LOCAL_STORE
[INFO] 

And at last, I tried to move the configuration to be outside of the execution node, as following:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>3.0.4</version>
    <configuration>
        <effort>default</effort>
        <failOnError>true</failOnError>
        <excludeFilterFile>${project.basedir}/etc/excludeFilter.xml</excludeFilterFile>
    </configuration>
    <executions>
        <execution>
            <id>check</id>
            <phase>compile</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And the plugin worked fine, and the bug was ignored.

So, my question is: Is the way of configuration I tried a bug? Or, I misconfigured something? Or, I misunderstood the configuration of maven plugin?

@rainbow702
Copy link
Author

I found an explanation from guide-configuring-plugins:

Note: 
Configurations inside the <executions> tag differ from those that are outside <executions> in that they cannot be used from a direct command line invocation.
Instead they are only applied when the lifecycle phase they are bound to are invoked. 
Alternatively, if you move a configuration section outside of the executions section,
it will apply globally to all invocations of the plugin.

But I think the command mvn clean compile does not match the case of 'direct command line invocation'.

@rainbow702 rainbow702 changed the title findbugs-maven-plugin ignore the configuration inside the <execution> node findbugs-maven-plugin ignores the configuration inside the <execution> node Mar 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant