WEB开发网
开发学院软件开发Java 基于 Ant 搭建敏捷开发过程中的持续集成环境 阅读

基于 Ant 搭建敏捷开发过程中的持续集成环境

 2010-01-04 00:00:00 来源:WEB开发网   
核心提示: Mapper 则常出现于 Copy,Move 或 Unzip 任务中,基于 Ant 搭建敏捷开发过程中的持续集成环境(5),它的作用在于为这些任务增加指定输出文件的能力,使得我们不仅可以通过 <fileset> 来指定源文件集,在构建服务器上调用一个综合性的 Ant 构建脚本(清单

Mapper 则常出现于 Copy,Move 或 Unzip 任务中,它的作用在于为这些任务增加指定输出文件的能力,使得我们不仅可以通过 <fileset> 来指定源文件集,更可以通过各种不同功能的 mapper,来实现重新命名输出文件文件名或更改输出文件目录结构的能力,这在构建持续集成环境中起到了极为灵活的作用,很好的理解这两个概念有助于写出简单而功能全面的 ant 脚本。

Taskdef

另外,在一个复杂的持续集成环境中,我们不可避免地会涉及一些商业产品或者开源项目来搭建整个环境,比如使用 CVS,SVN 或 IBM ClearCase 作为项目源代码库,使用 Apache Tomcat,IBM WebSphere Application 作为测试或产品环境的部署服务器,使用 LiquiBase,DBdeploy 作为产品数据库的持续重构工具等。而 Ant 借助其易扩展的特性,对所有这些工具提供了很好的支持,外部工具的提供者只要实现特定的 Ant 任务接口,就可以提供自定义的 Ant 任务,我们只需要通过 <taskdef> 任务引入这些特定的 Ant 任务,便可以实现与这些工具的连接,实现通过 Ant 脚本来管理整个集成环境的目的。

实现一个基本的持续集成环境

在一个典型的线上 Web 2.0 应用的迭代开发周期中,持续集成通常涉及构建、部署、测试和上线等一系列动作,而这些动作能够自动运行的前提是获取各自需要的产品包(比如基于 Java EE 的产品都须提供的 WAR 或 EAR 文件)。因此,在构建服务器上调用一个综合性的 Ant 构建脚本(清单 1),产生其它动作所需要的产品包,则成为整个持续集成过程中最为核心的一步。


清单 1. 产生其它动作所需要的产品包
 <?xml version="1.0" encoding="UTF-8"?> 
<project name="SampleOverall" basedir="." default="fetch_Code"> 
 <property file="SampleOverall.properties" /> 
 
 <taskdef name ="teamFetch" classname="com.ibm.team.build.ant.task.TeamFetchTask" /> 
 <taskdef name ="teamAccept" classname="com.ibm.team.build.ant.task.TeamAcceptTask" /> 
  
 <tstamp><format property="build.time" pattern="yyyy-MM-dd$hh-mm-ss" /></tstamp> 
  
 <target name="perform_DailyBuild"> 
  <antcall target="generate_SmokeTest_Package"/> 
  <antcall target="mail"/> 
 </target> 
  
 <target name="perform_FVTBuild"> 
  <antcall target="generate_FVTTest_Package" /> 
  <antcall target="upload_to_FTP" /> 
 </target> 
 
 <target name="perform_ProductBuild"> 
  <antFetch dir="${basedir}" antfile="checkLicense.xml" target="checkLicense" 
  return="reportFile" /> 
  <available property="reportFile_exist" file="${reportFile}"/> 
  <fail message="Unlicensed file found, please check ${reportFile}" 
  if="${reportFile_exist}"/> 
  <antcall target="generate_Product_Package" /> 
  <antcall target="upload_to_FTP" /> 
 </target> 
 
 <target name="fetch_Code"> 
  <teamAccept repositoryAddress="${repositoryAddress}" userId="${userId}" 
  password="${password}" workspaceName="${workspaceName}" verbose="true" /> 
  <teamFetch repositoryAddress="${repositoryAddress}" userId="${userId}" 
  password="${password}" workspaceName="${workspaceName}" 
  destination="${destination}" 
   verbose="true" /> 
 </target> 
 
 <target name="generate_SmokeTest_Package" depends="fetch_Code"> 
  <!-- may also include other project,like SampleApp2, SampleApp3 --> 
  <ant dir="${SampleApp1.dir}" antfile="build.xml" target="war" 
  inheritAll="false" /> 
 </target> 
 
 <target name="generate_FVTTest_Package" depends="fetch_Code"> 
  <ant dir="${SampleApp1.dir}" antfile="build.xml" target="ear_FVT" 
  inheritAll="false" /> 
 </target> 
 
 <target name="generate_Product_Package" depends="fetch_Code"> 
  <ant dir="${SampleApp1.dir}" antfile="build.xml" target="product" 
  inheritAll="false" /> 
 </target> 
 
 <target name="upload_to_FTP"> 
  <zip destfile = "${BuildPackage}/SampleApp1.zip" basedir="${BuildPackage}" /> 
 
  <ftp action="mkdir" server="${FTPAddress}" userid="${FTPUserName}" 
  password="${FTPPassword}" remotedir="${FTPSharedFolder}/${build.time}"/> 
  <ftp server="${FTPAddress}" userid="${FTPUserName}" password="${FTPPassword}" 
  remotedir="${FTPSharedFolder}/${build.time}"> 
   <fileset file="${BuildPackage}/SampleApp1.zip" /> 
  </ftp> 
 </target> 
 
 <target name="mail"> 
  <mail mailhost="${MailServer}" mailport="${MailServerPort}" 
  subject="Build Report Mail" tolist="${MailList}" messagemimetype="text/html" 
  messagefile="mailcontent.html"> 
   <from address="${fromMailAddr}" />  
  </mail> 
 </target> 
</project> 

上一页  1 2 3 4 5 6 7  下一页

Tags:基于 Ant 搭建

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接