首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

复建CruiseControl配置和Ant脚本

2012-10-28 
重构CruiseControl配置和Ant脚本代码的重复是件麻烦事,配置文件的重复也让人不爽。当配置文件出现bad smell

重构CruiseControl配置和Ant脚本
代码的重复是件麻烦事,配置文件的重复也让人不爽。当配置文件出现bad smell时,也要着手进行重构了。

当在CruiseControl(以下简称cc)监控多个项目时,config.xml很容易出现大堆的重复配置。比如我的:


当存在多个project时,由于每个project的处理过程是一模一样的,因此配置写了重复的n次。使用plugin定义模板来改变:

有更多的project都只需添加一句话而已。plugin的使用可参考官方http://cruisecontrol.sourceforge.net/main/plugins.html。其中name属性如果是cc默认定义的,可以不加classname属性,比如这里的name="project"。

由于cc经常和ant配合使用,ant也容易出现大堆的重复配置。比如我的:
cc.xml

dd.xml

cc.xml和dd.xml几乎一模一样,只是project name不同而已。使用import task来改变:
先定义公共的xml,这里为import.xml:

在cc.xml和dd.xml中import进来即可:
cc.xml

dd.xml

需要注意的是,import.xml中的project name是没用的,${ant.project.name}不是指该值,而是指最上层引用的xml的project name。比如cc.xml引用了import.xml,那么${ant.project.name}是指cc.xml的project name。import task有点复制代码的味道。

参考:
http://www.blogjava.net/chelsea/archive/2008/03/06/184374.html
http://cruisecontrol.sourceforge.net/main/plugins.html
http://ant.apache.org/manual/index.html

热点排行