Jump to: navigation, search

Difference between revisions of "FindBugs"

(New page: {{Warning|Work in progress}} FindBugs is installed on the build server: * /shared/common/findbugs-1.3.9/ ==Using FindBugs from Maven== ==Using FindBugs from Ant==)
 
(Using FindBugs from Ant)
Line 7: Line 7:
 
==Using FindBugs from Maven==
 
==Using FindBugs from Maven==
  
==Using FindBugs from Ant==
+
Example of running FindBugs from Sapphire build.
 +
 
 +
<pre>&lt;target name="findbugs" depends="init"&gt;
 +
  &lt;findbugs/&gt;
 +
&lt;/target&gt;
 +
 
 +
&lt;macrodef name="findbugs"&gt;
 +
  &lt;sequential&gt;
 +
     
 +
    &lt;if&gt;
 +
      &lt;not&gt;&lt;isset property="findbugs.output"/&gt;&lt;/not&gt;
 +
      &lt;then&gt;
 +
        &lt;if&gt;
 +
          &lt;available file="${build.dir}/findbugs"/&gt;
 +
          &lt;then&gt;
 +
            &lt;echo message="Found existing findbugs output..."/&gt;
 +
            &lt;var name="findbugs.output" value="${build.dir}/findbugs"/&gt;
 +
          &lt;/then&gt;
 +
        &lt;/if&gt;
 +
      &lt;/then&gt;
 +
    &lt;/if&gt;
 +
 
 +
    &lt;if&gt;
 +
      &lt;not&gt;&lt;isset property="findbugs.output"/&gt;&lt;/not&gt;
 +
      &lt;then&gt;
 +
 
 +
        &lt;build-repository/&gt;
 +
 
 +
        &lt;property name="findbugs.output" value="${build.dir}/findbugs"/&gt;
 +
 
 +
        &lt;delete dir="${findbugs.output}" quiet="true"/&gt;
 +
        &lt;mkdir dir="${findbugs.output}"/&gt;
 +
 
 +
        &lt;taskdef name="findbugs-task" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"&gt;
 +
          &lt;classpath&gt;
 +
            &lt;fileset dir="${findbugs.location}/lib"&gt;
 +
              &lt;include name="*.jar"/&gt;
 +
            &lt;/fileset&gt;
 +
          &lt;/classpath&gt;
 +
        &lt;/taskdef&gt;
 +
 
 +
        &lt;with-target-platform configuration="${configuration.recommended}"&gt;
 +
          &lt;pathconvert property=".aux.xml" pathsep="&amp;lt;/AuxClasspathEntry&amp;gt;&amp;#xA;&amp;lt;AuxClasspathEntry&amp;gt;"&gt;
 +
            &lt;path&gt;
 +
              &lt;fileset dir="${.target.platform}/plugins"&gt;
 +
                &lt;include name="**/*.jar"/&gt;
 +
              &lt;/fileset&gt;
 +
            &lt;/path&gt;
 +
          &lt;/pathconvert&gt;
 +
        &lt;/with-target-platform&gt;
 +
 
 +
        &lt;pathconvert property=".source.xml" pathsep="&amp;lt;/SrcDir&amp;gt;&amp;#xA;&amp;lt;SrcDir&amp;gt;"&gt;
 +
          &lt;path&gt;
 +
            &lt;dirset dir="${root.dir}/plugins" includes="*/src"/&gt;
 +
          &lt;/path&gt;
 +
        &lt;/pathconvert&gt;
 +
 
 +
        &lt;pathconvert property=".jars.xml" pathsep="&amp;lt;/Jar&amp;gt;&amp;#xA;&amp;lt;Jar&amp;gt;"&gt;
 +
          &lt;path&gt;
 +
            &lt;fileset dir="${build.dir}/repository/plugins"&gt;
 +
              &lt;include name="org.eclipse.sapphire*.jar"/&gt;
 +
              &lt;exclude name="*.source_*.jar"/&gt;
 +
              &lt;exclude name="*.nl_re_*.jar"/&gt;
 +
            &lt;/fileset&gt;
 +
          &lt;/path&gt;
 +
        &lt;/pathconvert&gt;
 +
 
 +
        &lt;echo file="${findbugs.output}/project.xml"&gt;
 +
          &amp;lt;BugCollection&gt;
 +
            &amp;lt;Project filename="findbugs.project" projectName="Sapphire"&gt;
 +
              &amp;lt;Jar&amp;gt;${.jars.xml}&amp;lt;/Jar&amp;gt;
 +
              &amp;lt;AuxClasspathEntry&amp;gt;${.aux.xml}&amp;lt;/AuxClasspathEntry&amp;gt;
 +
              &amp;lt;SrcDir&amp;gt;${.source.xml}&amp;lt;/SrcDir&amp;gt;
 +
              &amp;lt;SuppressionFilter&amp;gt;
 +
                &amp;lt;LastVersion value="-1" relOp="NEQ"/&amp;gt;
 +
              &amp;lt;/SuppressionFilter&amp;gt;
 +
            &amp;lt;/Project&amp;gt;
 +
          &amp;lt;/BugCollection&amp;gt;
 +
        &lt;/echo&gt;
 +
 
 +
        &lt;var name=".aux.xml" unset="true"/&gt;
 +
        &lt;var name=".source.xml" unset="true"/&gt;
 +
        &lt;var name=".jars.xml" unset="true"/&gt;
 +
 
 +
        &lt;findbugs-task
 +
          home="${findbugs.location}"
 +
          projectFile="${findbugs.output}/project.xml"
 +
          excludeFilter="${root.dir}/findbugs-excludes.xml"
 +
          output="xml"
 +
          outputFile="${findbugs.output}/result.xml"
 +
          timeout="2400000"
 +
          jvmargs="-Xmx1024m -XX:MaxPermSize=256m"/&gt;
 +
 
 +
      &lt;/then&gt;
 +
    &lt;/if&gt;
 +
 
 +
  &lt;/sequential&gt;
 +
&lt;/macrodef&gt;
 +
 
 +
 
 +
&lt;target name="clean-findbugs" depends="init"&gt;
 +
 
 +
  &lt;delete dir="${build.dir}/findbugs" quiet="true"/&gt;
 +
  &lt;var name="findbugs.output" unset="true"/&gt;
 +
 
 +
&lt;/target&gt;
 +
 
 +
</pre>

Revision as of 12:47, 7 May 2013

Warning2.png
Work in progress


FindBugs is installed on the build server:

  • /shared/common/findbugs-1.3.9/

Using FindBugs from Maven

Example of running FindBugs from Sapphire build.

<target name="findbugs" depends="init">
  <findbugs/>
</target>

<macrodef name="findbugs">
  <sequential>
      
    <if>
      <not><isset property="findbugs.output"/></not>
      <then>
        <if>
          <available file="${build.dir}/findbugs"/>
          <then>
            <echo message="Found existing findbugs output..."/>
            <var name="findbugs.output" value="${build.dir}/findbugs"/>
          </then>
        </if>
      </then>
    </if>

    <if>
      <not><isset property="findbugs.output"/></not>
      <then>

        <build-repository/>

        <property name="findbugs.output" value="${build.dir}/findbugs"/>

        <delete dir="${findbugs.output}" quiet="true"/>
        <mkdir dir="${findbugs.output}"/>

        <taskdef name="findbugs-task" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
          <classpath>
            <fileset dir="${findbugs.location}/lib">
              <include name="*.jar"/>
            </fileset>
          </classpath>
        </taskdef>

        <with-target-platform configuration="${configuration.recommended}">
          <pathconvert property=".aux.xml" pathsep="&lt;/AuxClasspathEntry&gt;&#xA;&lt;AuxClasspathEntry&gt;">
            <path>
              <fileset dir="${.target.platform}/plugins">
                <include name="**/*.jar"/>
              </fileset>
            </path>
          </pathconvert>
        </with-target-platform>

        <pathconvert property=".source.xml" pathsep="&lt;/SrcDir&gt;&#xA;&lt;SrcDir&gt;">
          <path>
            <dirset dir="${root.dir}/plugins" includes="*/src"/>
          </path>
        </pathconvert>

        <pathconvert property=".jars.xml" pathsep="&lt;/Jar&gt;&#xA;&lt;Jar&gt;">
          <path>
            <fileset dir="${build.dir}/repository/plugins">
              <include name="org.eclipse.sapphire*.jar"/>
              <exclude name="*.source_*.jar"/>
              <exclude name="*.nl_re_*.jar"/>
            </fileset>
          </path>
        </pathconvert>

        <echo file="${findbugs.output}/project.xml">
          &lt;BugCollection>
            &lt;Project filename="findbugs.project" projectName="Sapphire">
              &lt;Jar&gt;${.jars.xml}&lt;/Jar&gt;
              &lt;AuxClasspathEntry&gt;${.aux.xml}&lt;/AuxClasspathEntry&gt;
              &lt;SrcDir&gt;${.source.xml}&lt;/SrcDir&gt;
              &lt;SuppressionFilter&gt;
                &lt;LastVersion value="-1" relOp="NEQ"/&gt;
              &lt;/SuppressionFilter&gt;
            &lt;/Project&gt;
          &lt;/BugCollection&gt;
        </echo>

        <var name=".aux.xml" unset="true"/>
        <var name=".source.xml" unset="true"/>
        <var name=".jars.xml" unset="true"/>

        <findbugs-task
          home="${findbugs.location}"
          projectFile="${findbugs.output}/project.xml"
          excludeFilter="${root.dir}/findbugs-excludes.xml"
          output="xml"
          outputFile="${findbugs.output}/result.xml"
          timeout="2400000"
          jvmargs="-Xmx1024m -XX:MaxPermSize=256m"/>

      </then>
    </if>

  </sequential>
</macrodef>


<target name="clean-findbugs" depends="init">

  <delete dir="${build.dir}/findbugs" quiet="true"/>
  <var name="findbugs.output" unset="true"/>

</target>