Add configuration and execution to FindBugs plugin 14/46914/12
authorTom Pantelis <tpanteli@brocade.com>
Thu, 13 Oct 2016 19:13:17 +0000 (15:13 -0400)
committerStephen Kitt <skitt@redhat.com>
Wed, 26 Oct 2016 07:33:23 +0000 (07:33 +0000)
Added the appropriate configuration and execution to the FindBugs plugin
so it can run during compile phase and report violations. failOnError is
set to false by default so it doesn't fail the build. Projects can override
this setting if they want enforcement.

Also added a findbugs project (similar to checkstyle) that defines the rule
filters to exclude. I added one to exclude b/c it's of low priority
and is a common pattern used in ODL. I also added package exclusions for
yang-generated classes and protobuff-generated classes.

Change-Id: Ie01507a23990280d4bee8c2aefdc6c2293a3c6db
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
Signed-off-by: Stephen Kitt <skitt@redhat.com>
findbugs/pom.xml [new file with mode: 0644]
findbugs/src/main/resources/findbugs-exclude.xml [new file with mode: 0644]
odlparent/pom.xml
pom.xml

diff --git a/findbugs/pom.xml b/findbugs/pom.xml
new file mode 100644 (file)
index 0000000..316972d
--- /dev/null
@@ -0,0 +1,52 @@
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.opendaylight.odlparent</groupId>
+    <artifactId>odlparent-lite</artifactId>
+    <version>1.8.0-SNAPSHOT</version>
+    <relativePath>../odlparent-lite</relativePath>
+  </parent>
+
+  <artifactId>findbugs</artifactId>
+  <name>ODL :: odlparent :: ${project.artifactId}</name>
+
+  <!--
+    Maven Site Configuration
+
+    The following configuration is necessary for maven-site-plugin to
+    correctly identify the correct deployment path for OpenDaylight Maven
+    sites.
+  -->
+  <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+  <distributionManagement>
+    <site>
+      <id>opendaylight-site</id>
+      <url>${nexus.site.url}/${project.artifactId}/</url>
+    </site>
+  </distributionManagement>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.5.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.0.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.0.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.19.1</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/findbugs/src/main/resources/findbugs-exclude.xml b/findbugs/src/main/resources/findbugs-exclude.xml
new file mode 100644 (file)
index 0000000..fdd6c2c
--- /dev/null
@@ -0,0 +1,16 @@
+<FindBugsFilter>
+  <Match>
+    <Or>
+      <Package name="~.*protobuff\.messages.*" />
+      <Package name="~org\.opendaylight\.yang\.gen\..*" />
+      <Package name="~org\.opendaylight\.controller\.config\.yang\.config\..*" />
+    </Or>
+  </Match>
+
+  <Match>
+    <Or>
+      <!-- Anonymous inner classes are very common in ODL. -->
+      <Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON" />
+    </Or>
+  </Match>
+</FindBugsFilter>
index f03bf9ce1621cba11717e2a7dbf9b75fde3af8ca..6dd4d224f735d01f10ad6b39a078588759d7dfee 100644 (file)
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>findbugs-maven-plugin</artifactId>
-          <version>3.0.3</version>
+          <version>3.0.4</version>
+          <dependencies>
+            <dependency>
+              <groupId>org.opendaylight.odlparent</groupId>
+              <artifactId>findbugs</artifactId>
+              <version>1.8.0-SNAPSHOT</version>
+            </dependency>
+          </dependencies>
+          <configuration>
+            <!--
+              Enables analysis which takes more memory but finds more bugs.
+              If you run out of memory, changes the value of the effort element
+              to 'Low'.
+            -->
+            <effort>Max</effort>
+            <!-- Reports all bugs (other values are medium and max) -->
+            <threshold>Low</threshold>
+            <!-- Build doesn't fail if problems are found -->
+            <failOnError>false</failOnError>
+            <!-- References the excluded rules -->
+            <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
+            <!-- Produces XML report -->
+            <xmlOutput>true</xmlOutput>
+            <!-- Configures the directory in which the XML report is created -->
+            <findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
+            </configuration>
+            <executions>
+              <!--
+                Ensures that FindBugs inspects source code when project is compiled.
+              -->
+              <execution>
+                <id>analyze-compile</id>
+                <phase>compile</phase>
+                <goals>
+                  <goal>check</goal>
+                </goals>
+              </execution>
+            </executions>
         </plugin>
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
         <artifactId>maven-project-info-reports-plugin</artifactId>
         <version>${projectinfo}</version>
       </plugin-->
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>findbugs-maven-plugin</artifactId>
-        <configuration>
-          <effort>Max</effort>
-          <threshold>Low</threshold>
-          <goal>site</goal>
-        </configuration>
-      </plugin>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>jdepend-maven-plugin</artifactId>
diff --git a/pom.xml b/pom.xml
index 6303d705ea9a17cc0b5be03b9a76c8f669209d6e..5c156d9186db95d22cedfb01c1f0449021fa73bd 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -29,6 +29,7 @@
     <modules>
         <!-- odlparent tools -->
         <module>checkstyle</module>
+        <module>findbugs</module>
         <module>license</module>
         <module>features-test</module>