欢迎光临
我们一直在努力

持续集成 Java手册-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

持续集成 java手册

一、概念

martin fowler的文章:continuous integration 中文翻译:持续集成

二、工具

传统工具:visualstudio.net,visualsourcesafe,rational clearcase

自动编译工具:ant

回归测试工具:junit

代码检查工具:checkstyle

持续集成工具:cruisecontrol

三、步骤

cruisecontrol监控远程版本控制系统的变化

变化发生时cruisecontrol调用编译工具进行编译(ant等)

编译成功后调用junit进行回归测试

编译成功后调用checkstyle进行代码检查

完毕后将编译结果、测试结果、代码检查结果发送至开发人员、主管经理,并发布至网站,甚至报警器

所有这一切都是按照编制好的脚本自动进行的

四、实施示例

目前我们使用的是clearcase,主控软件为cruisecontrol,其脚本文件为cccc.xml

配置远程版本控制系统

<modificationset quietperiod="30">

<clearcase branch="main" viewpath="d:\cc_view\chelseafc\nucleus2.0\port" recursive="true" />

</modificationset>

配置编译工具

<schedule interval="30">

<ant antscript="c:\java\jbuilder2005\thirdparty\ant\bin\ant.bat" buildfile="d:\cc_view\chelseafc\nucleus2.0\port\clearcase-build.xml" target="cleanbuild" multiple="1" />

</schedule>

配置测试用例(在ant的配置文件中)

<target name="test" depends="init" description="run unit tests">

<delete dir="${junit.results}" />

<mkdir dir="${junit.results}" />

– <junit fork="yes" haltonfailure="yes">

– <classpath>

<pathelement location="${build.dir}" />

</classpath>

<formatter type="plain" usefile="false" />

<formatter type="xml" />

– <batchtest todir="${junit.results}">

<fileset dir="${build.dir}" includes="**/*test.class" />

</batchtest>

</junit>

</target>

配置报告形式

<publishers>

<currentbuildstatuspublisher file="currentbuild.txt" />

– <htmlemail mailhost="mail.chelseafc.com.cn" returnaddress="workflow_engine@chelseafc.com.cn" subjectprefix="continuousintegration:" buildresultsurl="http://chelsea:8044/cruisecontrol/buildresults" spamwhilebroken="true" xsldir="f:\software\agile.net\cruisecontrol-2.2\reporting\jsp\xsl" css="f:\software\agile.net\cruisecontrol-2.2\reporting\jsp\css\cruisecontrol.css" logdir="d:\tomcat 4.1\webapps\cruisecontrol\samplelogs">

<always address="chelsea@chelseafc.com.cn" />

<always address="ajax@chelseafc.com.cn" />

<map alias="chelsea" address="chelsea@chelseafc.com.cn" />

</htmlemail>

</publishers>

其中cruisecontrol暂时没有提供代码检查工具的支持,建议使用ant来调用checkstyle,示例如下(没有真正运行过):

<target name="web.checkstyle">

<mkdir dir="${target.temp}/checkstyle" />

<mkdir dir="${target.web}/checkstyle" />

– <taskdef resource="checkstyletask.properties">

– <classpath>

<fileset dir="${support.tools}/checkstyle31" includes="**/*.jar" />

</classpath>

</taskdef>

– <copy file="${support.tools}/checkstyle31/custom.xml" overwrite="true" tofile="${target.temp}/checkstyle/custom.xml">

– <filterset>

<filter token="source.java" value="${basedir}/${source.java}" />

<filter token="target.checkstyle" value="${basedir}/${target.temp}/checkstyle" />

</filterset>

</copy>

– <checkstyle config="${target.temp}/checkstyle/custom.xml" failonviolation="false">

<fileset dir="${source.java}/main" includes="**/*.java" />

<formatter type="plain" />

<formatter type="xml" tofile="${target.temp}/checkstyle/checkstyle_errors.xml" />

</checkstyle>

<style basedir="${target.temp}/checkstyle" destdir="${target.web}/checkstyle" includes="checkstyle_errors.xml" style="${support.tools}/checkstyle31/checkstyle-noframes.xsl" />

</target>

五、几点提示

cruisecontrol会自动根据本地clearcase的view监控远程vob

其实除了监控远程版本控制系统外其它的任务都可以由ant来完成,cc只负责监控变化并调用ant即可

可以为cruisecontrol.bat加入启动参数“-port 8055”,这样可以用jmx(http://localhost:8055)来控制cc

最好避免中文路径,否则就需要手工为几个xml格式的文件,如cc的report servlet的web.xml等加入编码方式“<?xml version="1.0" encoding="utf-8" ?> ”,或者将中文路径映射为虚拟硬盘:“subst y: "d:\cc_view\chelsea\platform\开发\nucleus2.0\source"”

中文log无法正常显示时,需要设置cruisecontrol配置文件中<log>元素的“encoding”属性,如:

<log dir="d:\tomcat 4.1\webapps\cruisecontrol\samplelogs" encoding="utf-8">

<merge dir="d:\cc_view\chelseafc\nucleus2.0\port\test-results" />

</log>

编译失败后,在下次checkin之前,一般不需要重新编译,这时可设置<project >的“buildafterfailed”属性为false来避免重新编译

<htmlemail>的几个属性好像没有缺省设置,虽然文档里说从2.1.7开始有缺省设置,包括xsldir,css,logdir

各种工具的安装、使用,在各自的文档里都非常详细,网上亦有无数资源

六、参考资料

dailybuild全攻略

draco.net

持续集成.net手册

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 持续集成 Java手册-JSP教程,Java技巧及代码
分享到: 更多 (0)

相关推荐

  • 暂无文章