官方论坛文档写得很烂,让人以为安装了插件后就万事大吉,实际上并不是这样,它只是个静态分析结果的分析插件,而分析结果的生成,却是它完成不了的,你仍然需要在你的ant或maven任务中,写一个任务去执行,生成这个分析结果,通常是一个xml文件,例如:
- <!--===================================================================-->
- <!--CheckStylebuild-->
- <!--===================================================================-->
- <targetname="checkstyle"description="Reportstheviolationsofservicesourceagainstcodingstyleformat">
- <taskdefresource="checkstyletask.properties"classpathref="dist.lib"/>
- <checkstylefailOnViolation="false"config="${lib.path}/check/CheckStyle_hangame.xml">
- <classpathrefid="dist.lib"/>
- <filesetdir="${project.src.dir}">
- <includename="**/*.java"/>
- </fileset>
- <formattertype="xml"toFile="${commonbuild.dir}/checkstyle_errors.xml"/>
- </checkstyle>
- </target>
- <!--===================================================================-->
- <!--Findbugsbuild-->
- <!--===================================================================-->
- <taskdefname="findbugs"classname="edu.umd.cs.findbugs.anttask.FindBugsTask"classpathref="dist.lib"/>
- <propertyname="findbugs.home"value="/home/irteam/app/findbugs-1.3.9"/>
- <targetname="findbugs"depends="build-jar">
- <findbugshome="${findbugs.home}"output="xml"outputFile="${commonbuild.dir}/findbugs_errors.xml">
- <sourcePathpath="${project.src.dir}"/>
- <classlocation="${project.dist.dir}/${project.name}.jar"/>
- </findbugs>
- </target>
- <!--===================================================================-->
- <!--PMDbuild-->
- <!--===================================================================-->
- <targetname="pmd">
- <taskdefname="pmd"classname="net.sourceforge.pmd.ant.PMDTask"classpathref="dist.lib"/>
- <pmdrulesetfiles="${lib.path}/check/pmd_hangame.xml"encoding="iso-8859-1">
- <formattertype="xml"toFile="${commonbuild.dir}/pmd.xml"/>
- <filesetdir="${project.src.dir}">
- <includename="**/*.java"/>
- </fileset>
- </pmd>
- </target>
<!-- =================================================================== -->
<!-- CheckStyle build -->
<!-- =================================================================== -->
<target name="checkstyle" description="Reports the violations of service source against coding style format">
<taskdef resource="checkstyletask.properties" classpathref="dist.lib" />
<checkstyle failOnViolation="false" config="${lib.path}/check/CheckStyle_hangame.xml">
<classpath refid="dist.lib" />
<fileset dir="${project.src.dir}">
<include name="**/*.java" />
</fileset>
<formatter type="xml" toFile="${commonbuild.dir}/checkstyle_errors.xml" />
</checkstyle>
</target>
<!-- =================================================================== -->
<!-- Findbugs build -->
<!-- =================================================================== -->
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="dist.lib" />
<property name="findbugs.home" value="/home/irteam/app/findbugs-1.3.9" />
<target name="findbugs" depends="build-jar">
<findbugs home="${findbugs.home}" output="xml" outputFile="${commonbuild.dir}/findbugs_errors.xml">
<sourcePath path="${project.src.dir}" />
<class location="${project.dist.dir}/${project.name}.jar" />
</findbugs>
</target>
<!-- =================================================================== -->
<!-- PMD build -->
<!-- =================================================================== -->
<target name="pmd">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="dist.lib" />
<pmd rulesetfiles="${lib.path}/check/pmd_hangame.xml" encoding="iso-8859-1">
<formatter type="xml" toFile="${commonbuild.dir}/pmd.xml" />
<fileset dir="${project.src.dir}">
<include name="**/*.java" />
</fileset>
</pmd>
</target>
并在findbugs插件中指定你生成的文件名才可以,这里生成的叫findbugs_errors.xml,那么你在插件指定的名字也要叫findbugs_errors.xml,其他两个插件类似,不再赘述.
本文详细介绍了如何在Ant或Maven构建过程中配置CheckStyle、FindBugs和PMD等静态代码分析工具,包括生成XML格式的分析报告的具体步骤。



6316

被折叠的 条评论
为什么被折叠?



