By using findbugs we can avoid some performance issues before deployment.
To use findbugs in project, 2 plugins required. One for execute findbugs check on the code, another for print the report in console or generate html report.
<project>
......
<build>
<plugins>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<inherited>true</inherited>
<configuration>
<!-- skip findbugs execution set value "true" -->
<skip>false</skip>
<effort>Max</effort>
<threshold>Medium</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<id>findbugs-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<!-- break the build if findbugs has found errors on code -->
<failOnError>true</failOnError>
</configuration>
</execution>
</executions>
</plugin>
<!-- this plugin used to print findbugs validation findings in console -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>echo-findbugs-errors</id>
<!-- this should execute before integration test to print reports -->
<phase>post-integration-test</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>target</dir>
<includes>
<!-- this file will be generated while running findbugs check -->
<include>findbugs.xml</include>
</includes>
<!-- XSL file to convert xml report into text -->
<stylesheet>${basedir}/src/main/resources/echo-findbugs-errors.xsl</stylesheet>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<!-- Saxon used parse the finbugs report xml file -->
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
....
</build>
.....
</project>
Findbugs: http://findbugs.sourceforge.net/
Here is the sample XSL for report:
<?xml version="1.0"?>
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:message>
</xsl:message>
<xsl:apply-templates select="//BugInstance"/>
<xsl:message>
</xsl:message>
</xsl:template>
<xsl:template match="BugInstance">
<xsl:message>
<xsl:call-template name="toText"/>
</xsl:message>
</xsl:template>
<xsl:template name="toText">
<xsl:text>FindBugs: </xsl:text>
<xsl:value-of select="@category"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="@type"/>
<xsl:text> </xsl:text>
<xsl:value-of select="../@classname"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="@lineNumber"/>
<xsl:text>] "</xsl:text>
<xsl:value-of select="@message"/>
<xsl:text>"</xsl:text>
</xsl:template>
</xsl:transform>
Here is the sample XSL for report:
<?xml version="1.0"?>
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:message>
</xsl:message>
<xsl:apply-templates select="//BugInstance"/>
<xsl:message>
</xsl:message>
</xsl:template>
<xsl:template match="BugInstance">
<xsl:message>
<xsl:call-template name="toText"/>
</xsl:message>
</xsl:template>
<xsl:template name="toText">
<xsl:text>FindBugs: </xsl:text>
<xsl:value-of select="@category"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="@type"/>
<xsl:text> </xsl:text>
<xsl:value-of select="../@classname"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="@lineNumber"/>
<xsl:text>] "</xsl:text>
<xsl:value-of select="@message"/>
<xsl:text>"</xsl:text>
</xsl:template>
</xsl:transform>
Comments
Post a Comment