hudson与checkstyle的集成

wang_l 技术分享评论阅读模式

1:下载checkstyle

下载checkstyle-8.5-bin.tar.gz (checkstyle主包配置文件)。下载地址:https://sourceforge.net/projects/checkstyle/files/checkstyle/8.5/checkstyle-8.5-src.tar.gz/download

下载checkstyle-8.5-src.tar.gz(build.xml文件)。下载地址:https://sourceforge.net/projects/checkstyle/files/checkstyle/8.5/checkstyle-8.5-src.tar.gz/download

   
 

2:写相应的ant脚本,如在build.xml中,可以加入下面的target,checkstyle在/opt/checkstyle/checkstyle-8.5下,java包在/root/.hudson/jobs/svn-test/workspace下:

vim build.xml

<project name="checkstyle" default="checkstyle.checkstyle" basedir=".">

   
 

<!--声明checkstyle相关的java包-->

<path id="project.sourcepath">

<fileset dir="src"

includes="**/*"

excludes="it/resources/**/*,test/resources/**/*,test/resources-noncompilable/**/*,main/resources-noncompilable/**/*"/>

</path>

   
 

<target name="checkstyle">

<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"

classpath="/opt/checkstyle/checkstyle-8.5/checkstyle-8.5-all.jar"/>

 
 

<!--声明参考checkstyle检查标准文件的路径、项目路径、相关jar和java代码-->

<checkstyle config="/opt/checkstyle/checkstyle-8.5/src/main/resources/sun_checks.xml" failureProperty="checkstyle.failure" failOnViolation="false">

<fileset dir="/root/.hudson/jobs/svn-test/workspace/" includes="**/*.jar"/>

<fileset dir="/root/.hudson/jobs/svn-test/workspace" includes="**/*.java"/>

<!--<formatter type="plain"/>--> <!--ant时输出告警信息-->

<!--生成checkstyle xml报表的文件和路径-->

<formatter type="xml" toFile="/root/.hudson/jobs/svn-test/workspace/checkstyle-result.xml"/>

</checkstyle>

<!-- <formatter type="xml" tofile="/root/.hudson/jobs/svn-test/workspace/checkstyle-result.xml"/>

<fileset dir="/root/.hudson/jobs/svn-test/workspace/" includes="**/*.jar"/>

<fileset dir="/root/.hudson/jobs/svn-test/workspace/" includes="**/*.java"/>

</checkstyle>

-->

</target>

   
 

</project>

   
 

   
 

3:配置hudson执行build.xml中的ant脚本

hudson与checkstyle的集成-图片1

    
 

4:配置Hudson,下载Hudson的checkstyle plugin,进入到工程配置界面,找到Post-build Actions项,里面多出一个Publish Checkstyle analysis results选项。做相应的配置,根据不同的项目要求设置不同的配置,可参照Help.

hudson与checkstyle的集成-图片2

   
 

5:运行工程。可得到如下结果:

图示1:

hudson与checkstyle的集成-图片3

   
 

图示2:

hudson与checkstyle的集成-图片4

图示3:

hudson与checkstyle的集成-图片5

   
 

hudson与checkstyle的集成-图片6

   
 

hudson与checkstyle的集成-图片7

文章末尾固定信息

 
wang_l
  • 本文由 wang_l 发表于 2018年1月18日 10:25:46
  • 转载请务必保留本文链接:https://www.qnjslm.com/ITHelp/797.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定