使用ANT,SVN,CruiseControl构建每日集成

 准备工作:
       1,下载cruisecontrol-bin-2.7.1.zip: http://cruisecontrol.sourceforge.net/download.html该工具集成apache-ant-1.7.0,解压到任意工作目录下,即完成安装。
       2,下载SvnAnt1.1.0RC2 http://subclipse.tigris.org/svnant.html,下载之后将里面的Jar包拷贝到%ANT_HOME%/lib下。用于在ANT中使用<SVN>标签。
       3,将%ANT_HOME%/lib加入环境变量。
       4,使用SVN将要测试的项目CheckOut到CruiseControl_HOME/projects目录下.
编写配置文件:
1,项目构建文件build.xml,放入项目根目录下。

<? xml version="1.0" encoding="UTF-8" ?>
< project  name ="OALP"  default ="all" >
    
< description >
        This is our OALP project which we're putting on CruiseControl
    
</ description >
    
< taskdef  name ="svn"  classname ="org.tigris.subversion.svnant.SvnTask"   />
    
<!--  加入该语句,否则提示找不到svn tag  -->
    
< target  name ="setup"  depends ="setup.properties,setup.paths" />
    
< target  name ="setup.properties" >
        
< property  name ="src.main"  value ="src" />
        
< property  name ="src.test"  value ="src/org/oa/test" />
        
< property  name ="classes"  value ="target/classes" />
        
< property  name ="classes.main"  value ="${classes}/main" />
        
< property  name ="classes.test"  value ="${classes}/test" />
        
< property  name ="libs"  value ="WebRoot/WEB-INF/lib" />
        
< property  name ="dist"  value ="target/dist" />
        
< property  name ="reports"  value ="reports" />
        
< property  name ="reports.junit.data"  value ="${reports}/junit/data" />
        
< property  name ="remoteurl"  value ="svn://localhost/OALP/src" />
        
< property  name ="localurl"  value ="src" />
    
</ target >
    
< target  name ="setup.paths" >
        
< path  id ="classpath.main" >
            
< pathelement  location ="${classes.main}" />
        
</ path >
        
< path  id ="classpath.lib" >
            
< fileset  dir ="${libs}" >
                
< include  name ="**/*.jar" />
            
</ fileset >
        
</ path >
    
</ target >
    
< target  name ="clean"  depends ="setup" >
        
< delete  dir ="${classes}"  failonerror ="false" />
        
< delete  dir ="${reprots}"  failonerror ="false" />
        
< delete  dir ="${dist}"  failonerror ="false" />
    
</ target >
    
< target  name ="compile.main" >
        
< mkdir  dir ="${classes.main}" />
        
< javac  srcdir ="${src.main}"  destdir ="${classes.main}" >
            
< classpath  refid ="classpath.lib" />
        
</ javac >
    
</ target >
    
< target  name ="compile.tests"  depends ="setup,compile.main" >
        
< mkdir  dir ="${classes.test}" />
        
< javac  srcdir ="${src.test}"  destdir ="${classes.test}" >
            
< classpath  refid ="classpath.lib" />
            
< classpath  refid ="classpath.main" />
        
</ javac >
    
</ target >
    
< target  name ="compile"  depends ="setup,compile.tests,compile.main"  description ="compile" />

    
< target  name ="test"  depends ="compile" >
        
< delete  dir ="${reports.junit.data}"  failonerror ="false" />
        
< mkdir  dir ="${reports.junit.data}" />
        
< junit  printsummary ="yes"  haltonfailure ="no"  failureproperty ="tests.failed" >
            
< classpath  refid ="classpath.lib"   />
            
< classpath  refid ="classpath.main" />
            
< formatter  type ="xml"   />
            
< batchtest  fork ="yes"  todir ="${reports.junit.data}"  failureproperty ="tests.failed" >
                
< fileset  dir ="${classes.test}" >
                    
< include  name ="**/HelloTest.class" />
            
< include  name ="**/TestFunction.class" />
            
< include  name ="**/TestValidator.class" />
                
</ fileset >
            
</ batchtest >
        
</ junit >
        
< fail  if ="tests.failed"  message ="Some unit tests failed"   />
    
</ target >
    
< target  name ="jar"  depends ="update,compile,test,report" >
        
< mkdir  dir ="${dist}" />
        
< jar  destfile ="${dist}/oalp.jar"  basedir ="${classes.main}" />
    
</ target >
    
< target  name ="all"  depends ="jar" />
    
    
< target  name ="report"  depends ="test" >
        
< junitreport  todir ="${reports.junit.data}" >
            
< fileset  dir ="${reports.junit.data}" >
                
< include  name ="TEST-*.xml" />
            
</ fileset >
            
< report  format ="frames"  todir ="${reports}/html" />
        
</ junitreport >
    
</ target >
    
    
< target  name ="update"  depends ="setup" >
        
< svn  javahl ="false" >
            
< checkout  url ="${remoteurl}"  revision ="HEAD"  destPath ="${localurl}"   />    
        
</ svn >
    
</ target >

</ project >

2,CruiseControl配置文件config.xml

< cruisecontrol >
    
< project  name ="OALP" >
    
< dateformat  format ="yyyy/MM/dd HH:mm:ss" />
        
< listeners >
            
< currentbuildstatuslistener  file ="logs/${project.name}/status.txt" />
        
</ listeners >

        
< bootstrappers >
            
< svnbootstrapper  localWorkingCopy ="projects/${project.name}"   />
        
</ bootstrappers >

        
< modificationset  quietperiod ="30"  requiremodification ="false" >
            
< svn  localWorkingCopy ="projects/${project.name}/src" />
        
</ modificationset >

        
< schedule  interval ="3600" >
            
< ant  anthome ="apache-ant-1.7.0"  buildfile ="projects/${project.name}/build.xml" />
        
</ schedule >

        
< log >
            
< merge  dir ="projects/${project.name}/reports/junit/data" />
        
</ log >

        
< publishers >
            
< onsuccess >
                
< artifactspublisher  dest ="artifacts/${project.name}"  file ="projects/${project.name}/target/dist/${project.name}.jar" />
            
</ onsuccess >
        
</ publishers >
    
</ project >
</ cruisecontrol >

查看Build结果

启动cruisecontrol.bat,打开浏览器输入:http://localhost:8080/cruisecontrol即可查看Build结果.(无需启动Tomcat服务器)
注:该端口与Tomcat服务器端口冲突,如果build.xml中包含selenium功能测试,最好将更改Tomcat服务器端口改成8081,或其他未使用的端口。

你可能感兴趣的:(SVN,ant,JUnit,delete,include,项目构建)