2010-10-15 16 views
3

我有一個運行的FindBugs兩次相同的源代碼,以產生XML和HTML報告Findbug - ANT XSLT樣式表的源代碼引用

<delete dir="${findbugs.dir}"/> 
<mkdir dir="${findbugs.dir}"/>   
<findbugs 
    home="${findbugs.home}" 
    output="xml" 
    outputFile="${findbugs.dir}/findbugs.xml" 
    jvmargs="${findbugs.jvmargs}" 
    timeout="${findbugs.timeout}" 
    effort="${findbugs.effort}"> 
    <sourcePath path="${src.dir}"/> 
    <class location="${build.classes.dir}"/> 
</findbugs> 

<findbugs 
    home="${findbugs.home}" 
    output="html" 
    outputFile="${findbugs.dir}/findbugs.html" 
    jvmargs="${findbugs.jvmargs}" 
    timeout="${findbugs.timeout}" 
    effort="${findbugs.effort}"> 
    <sourcePath path="${src.dir}"/> 
    <class location="${build.classes.dir}"/> 
</findbugs> 

這是啞因爲HTML報告可以從生成的ANT目標xml報告使用

<xslt in="${findbugs.dir}/findbugs.xml" out="${findbugs.dir}/findbugs.html" style="${findbugs.home}/default.xsl"/> 

但生成的html報告沒有正確的源代碼引用。任何想法,我如何得到這個工作,並避免重複的findbugs調用?

答案

with output="xml" 

<BugInstance type="REC_CATCH_EXCEPTION" priority="2" abbrev="REC" category="STYLE"> 
    <Class classname="com.x.y.aggregate.AggregationProperties"> 
     <SourceLine classname="com.x.y.aggregate.AggregationProperties" start="20" end="788" sourcefile="AggregationProperties.java" sourcepath="com/x/y/aggregate/AggregationProperties.java"/> 
    </Class> 
    <Method classname="com.x.y.aggregate.AggregationProperties" name="setAggregateProperties" signature="()V" isStatic="true"> 
     <SourceLine classname="com.x.y.aggregate.AggregationProperties" start="86" end="148" startBytecode="0" endBytecode="489" sourcefile="AggregationProperties.java" sourcepath="com/x/y/aggregate/AggregationProperties.java"/> 
    </Method> 
    <SourceLine classname="com.x.y.aggregate.AggregationProperties" start="140" end="140" startBytecode="308" endBytecode="308" sourcefile="AggregationProperties.java" sourcepath="com/x/y/aggregate/AggregationProperties.java"/> 
</BugInstance> 

with 'xml:withMessages' 

<BugInstance type="REC_CATCH_EXCEPTION" priority="2" abbrev="REC" category="STYLE" instanceHash="b7a7c8f292d2a8432680a1c971fb93b3" instanceOccurrenceNum="0" instanceOccurrenceMax="0"> 
    <ShortMessage>Exception is caught when Exception is not thrown</ShortMessage> 
    <LongMessage>Exception is caught when Exception is not thrown in com.x.y.aggregate.AggregationProperties.setAggregateProperties()</LongMessage> 
    <Class classname="com.x.y.aggregate.AggregationProperties" primary="true"> 
     <SourceLine classname="com.x.y.aggregate.AggregationProperties" start="20" end="788" sourcefile="AggregationProperties.java" sourcepath="com/x/y/aggregate/AggregationProperties.java" relSourcepath="com/x/y/aggregate/AggregationProperties.java"> 
     <Message>At AggregationProperties.java:[lines 20-788]</Message> 
     </SourceLine> 
     <Message>In class com.x.y.aggregate.AggregationProperties</Message> 
    </Class> 
    <Method classname="com.x.y.aggregate.AggregationProperties" name="setAggregateProperties" signature="()V" isStatic="true" primary="true"> 
     <SourceLine classname="com.x.y.aggregate.AggregationProperties" start="86" end="148" startBytecode="0" endBytecode="489" sourcefile="AggregationProperties.java" sourcepath="com/x/y/aggregate/AggregationProperties.java" relSourcepath="com/x/y/aggregate/AggregationProperties.java"/> 
     <Message>In method com.x.y.aggregate.AggregationProperties.setAggregateProperties()</Message> 
    </Method> 
    <SourceLine classname="com.x.y.aggregate.AggregationProperties" primary="true" start="140" end="140" startBytecode="308" endBytecode="308" sourcefile="AggregationProperties.java" sourcepath="com/x/y/aggregate/AggregationProperties.java" relSourcepath="com/x/y/aggregate/AggregationProperties.java"> 
     <Message>At AggregationProperties.java:[line 140]</Message> 
    </SourceLine> 
</BugInstance> 

回答

2

output="xml:withMessages"

documentation後更新,

如果設置爲 「XML」(默認),輸出是XML格式。如果設置爲「xml:withMessages」,則輸出爲XML格式,增加了人類可讀的消息。 (如果您計劃使用XSL樣式表生成報告,則應使用此格式。)