>Adding FindBugs to Athena Common Builder

>After my post about FindBugs, I was pointed to bug 247073 which asked for FindBugs to be Integrated into the eclipse build infrastructure. Unfortunately it was resolved as won’t fix. Since the creation of that bug, we now have the Athena Common Builder. So if it can’t be added to the base builder there is an alternative using Athena.

FindBugs Target:

The following target is being used during the PsychoPath XPath 2.0 Processor CI build.

<target name="findbugs" description="Run a find bugs analysis based on a ZIP file contents.">
<get src="http://downloads.sourceforge.net/project/findbugs/findbugs/1.3.9/findbugs-1.3.9.zip?use_mirror=voxel" dest="${writableBuildRoot}/downloads/findbugs.zip"/>
<unzip src="${writableBuildRoot}/downloads/findbugs.zip" dest="${writableBuildRoot}/3rdPartyJars/findbugs"/>
<get src="${sdkzipUrl}${zipPrefix}-SDK-${buildType}${buildTimestamp}.zip" dest="${writableBuildRoot}/eclipse.zip"/>

<mkdir dir="${writableBuildRoot}/athena/findbugs"/>
<unzip src="${writableBuildRoot}/eclipse.zip" dest="${writableBuildRoot}/athena/findbugs/">
<include name="eclipse/plugins/org.eclipse.wst.xml.xpath2.processor*.jar"/>
<unzip dest="${writableBuildRoot}/athena/findbugsclasses/">
<fileset dir="${writableBuildRoot}/athena/findbugs/">
<include name="**/*.jar"/>

<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
<fileset dir="${writableBuildRoot}/3rdPartyJars/findbugs/findbugs-1.3.9/lib" includes="*.jar"/>

<findbugs home="${writableBuildRoot}/3rdPartyJars/findbugs/findbugs-1.3.9/lib"
outputFile="${writableBuildRoot}/athena/fb-xpath20processor.xml" >
<class location="${writableBuildRoot}/athena/findbugsclasses"/>
<delete dir="${writableBuildRoot}/3rdPartyJars/findbugsclasses"/>

This target does the following:

  • Downloads the FindBugs zip file if it doesn’t already have it.
  • Unzips the file to a FindBugs directory in 3rdPartyJars
  • Gets the SDK ZIP file that was created during the build (sorry no P2 Repository ZIP support).
  • Extracts the necessary plugin JAR files to be analyzed.
  • Expands the JAR files into a directory called findbugsclasses
  • Sets up a TaskDef for the findbugs task
  • Runs find bugs with the class location set to the findbugsclasses directory.

It will output a file called fb-xpath2oprocessor.xml to the build/athena directory. To execute the target after you have called the Athena Builder to build the plugins, you can add a antcall task to execute the target.

<antcall target="findbugs" inheritall="true"/>

Testing using AntUnit:

For those interested, here is a sample unit test that can be used to test the task:

<!-- is called prior to the test -->
<target name="setUp">
<property name="writableBuildRoot" location="build"/>
<property name="sdkzipUrl" value="https://build.eclipse.org/hudson/job/cbi-wtp-wst.xsl.psychopath/128/artifact/build/athena/"/>
<property name="buildTimestamp" value="200912041353"/>

<!-- is called after the test, even if that caused an error -->
<target name="tearDown">


<!-- test the MacroDef for downloading Files -->
<target name="testFindBugs">
<ant antfile="build.xml" target="findbugs" inheritall="true"/>
<au:assertFileExists file="${writableBuildRoot}/athena/fb-xpath20processor.xml" />

<target name="run">
<fileset dir="${basedir}" includes="*.test.xml" excludes="*AllTaskTests.test.xml" />
<au:plainlistener />

Unit testing these functions is much quicker than trying to run an entire build just to see if we are successful and that the task works. This test setups the necessary properties and then executes the target. The test will pass if FindBugs was able to create the output file otherwise it’ll fail.

Hudson Integration:

To have Hudson show the reports on build.eclipse.org, you will need to enable the Publish FindBugs plugin for that job. Hudson will then generate a report from the XML files produced. You will also get an Icon in the sidebar that looks something like this:

Clicking the Icon will take you into more detail. You can see this in action with the PsychoPath job.

This entry was posted in build, eclipse, release engineering, testing, xml. Bookmark the permalink.

2 Responses to >Adding FindBugs to Athena Common Builder

  1. Miles Parker says:

    >Cool, thanks Dave, I'm anxious to try it. A couple of hopefully simple questions.1. Where are you actaully adding the antcall?2. I looked around in wtp releng but I'm on quite clear where everything is without downloading the actual build artifacts. Can you post quick links to your build scripts?

  2. David Carver says:

    >I've done some tweaks since the article was posted. You can see the build.xml and the findbugs.xml file I use here.You can also view the result from Hudson.I'm hoping to get this integrated with Athena so that everybody can use it as an optional step during their build.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s