Thursday, 11 December 2014

Configure Jenkins for Android - FindBugs

FindBugs is a static code analysis tool which could find potential bugs. It could be installed on Jenkins to run each time there is a change in the code.

1. Download and install the findBugs
1.1 Go to the follow web page to download the last version of FindBugs


1.2 Unzip it and put it on your /usr/lib folder. Call it as findbugs
1.3 Copy the findbugs-ant.jar from the /usr/lib/findbugs/lib to the lib directory of ant. In Mac OS X it ant could be located at /opt/local/share/java/apache-ant

2. Configure Jenkins
2. 1 Install the plugin called ¨FindBugs plugins¨ in Jenkins
2.2 Go to the configuration page of the project
2.3 On the Build section, add the target checkstyle for ant. It could be just after debug and before install target
2.4 On the Post-build Actions section, add a new action called "Publish FindBugs analysis results". The file could be find in the Test/findbugs.xml, where Test is the name of the test project.

3. Modify the Test project
3.1 On the ant.properties file of the test project, add the follow line:

findbugs.home=/usr/lib/findbugs

3.2 If you want to exclude the R folder, create a file called findbugs-exclude.xml in the root directory of the test project and paste the follow code:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Class name="~.*\.R\$.*"/>
        <Bug code="Nm"/>
    </Match>
</FindBugsFilter>

3.3 Add the follow line in the build.xml of the test project, at the end of the file and just before the last line, which is </project>

    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
    <target name="findbugs">
        <mkdir dir="reports" />
        <findbugs home="${findbugs.home}" output="xml" outputFile="findbugs.xml" excludeFilter="findbugs-exclude.xml">
            <auxClasspath path="${project.target.android.jar}"/>
            <class location="${tested.project.dir}/${out.dir}" />
        </findbugs>
    </target>

Add the value for tested.project.dir in the ant.properties file if you have not done it before. It is value is the directory where the source project is.

Source
Jenkins - Building an Android app and test project

No comments:

Post a Comment