JesperE
JesperE

Reputation: 64414

Finding source paths using FindBugs ant task

I'm trying to get the FindBugs ant task to include source info in the generated report.

<findbugs home="${findbugs.home}" output="xml" outputFile="${basedir}/findbugs/findbugs-${package.basename}.xml" excludeFilter="${basedir}/findbugsExclude.xml" jvmargs="-Xmx1048m">
    <sourcePath path="${package.srcdir}" />
<class location="${package}" />
<auxClasspath>
    <path refid="findbugs.auxinput" />
    </auxClasspath>
</findbugs>

The value of the ${package.srcdir} attribute is correct as far as I can see; it points to the root of the source tree such that ${package.srcdir}/com/mydomain/MyClass.java is the path of the source file.

The generated reports contains a <SrcDir> element which matches the source path given to the ant task, so apparently the <sourcePath> element is handled by the findbugs task. Despite this, the package stats in the XML reports only contains sourceFile="&lt;Unknown&gt;".

Am I missing something obvious?

Upvotes: 3

Views: 4376

Answers (2)

willowherb
willowherb

Reputation: 897

Try an echo like this(inl ine number two):

<echo message="Finding Bugs From ${package.srcdir}"/>  

I suspect that package.srcdir has not been set to a value yet. Try using

<sourcePath path="${basedir}/src/com" />

Or whichever directory that contains your source files.


Do not forget to mark an answer as the accepted answer if it solves your question.

Upvotes: -1

christian
christian

Reputation: 51

I had the same problem.

Probably your code is compiled with "-g:none". If you use ant's <javac> task have to set <javac debug=true>.

Setting the source path correctly (as mentioned in findbugs manual) to the enclosing folder of the top level package (in eclipse projects the src folder) you should be successful.

Nethertheless, afaik there are some cases findbugs can't determine a proper source line number.

cheers, Christian

Upvotes: 5

Related Questions