cruisecontrol + svn + maven2 配置总结

CruiseControl. 配置总结

cruisecontrol + svn + maven2 

 

 

CruiseControl :简称 CC ,持续集成工具,主要提供了基于版本管理工具 ( CVS) 感知变化或每天定时的持续集成,并提供持续集成报告、 Email Jabber 等等方式通知相关负责人,其要求是需要进行日构建的项目已编写好全自动的项目编译脚本 ( 可基于 Maven Ant)

 

在这里以一个项目来简要的说说 cc 的使用,通常项目对于日构建的类型的需求分为两种:

1 、每天的定时自动集成。

2 、感知版本管理工具中的变化而进行自动集成。

 

项目对于日构建的目标通常为:

1 、感知版本管理工具的变化,如发现有变化,则进行集成。

2 、调用项目编译脚本进行项目集成。

3 、合并项目编译脚本产生的单元测试、功能测试的日志。

4 、将集成报告发布至网站中。

5 、将集成的结果以邮件、 jabber 等等方式通知相应的负责人。

 

基于上面的要求,项目编译脚本采用 Maven ,版本管理工具采用 svn ,持续集成工具采用 CC ,假设已编写好了基于 Maven 的项目编译脚本, CruiseControl 的脚本如下编写:

 

     

<cruisecontrol>

<!-- 这里的 name 应该和你在 projects 目录下的项目名完全一致。 -->

<project name="gwt">


<!-- 用于监听项目状态的变化(指 building,passed 等)

这里的 ${project.name}</listeners> 是指“上面的 example”-->

<listeners>

<currentbuildstatuslistener file="logs/${project.name}/status.txt"/>

</listeners>

<!-- 用于 CruiseControl Repository 更新代码 -->

<bootstrappers>

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

</bootstrappers>

<!-- 用于监听在 quietperiod 秒内, Repository 是否变化 -->

<modificationset quietperiod="60">

<!--cvs cvsroot=":pserver:[email protected]:/forcvs/Project" module="ci"/-->

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

</modificationset>

<!-- 用于每隔 interval 秒, CruiseControl 去检查并计划一次构建 -->

<schedule interval="300">

<!-- 项目的编译脚本 -->

<maven2 mvnhome="/cf/apache-maven-2.2.1" pomfile="projects/${project.name}/pom.xml" goal="clean package site"/>

</schedule>

<!-- 用于得到并保存 log 文件。默认情况下,将放在 projects/${project.name} 的目录下 -->

<log logdir="logs/${project.name}">

<!-- 合并项目编译脚本中产生的单元、功能测试日志 -->

<merge dir="projects/${project.name}/target/surefire-reports"/>

</log>

<!-- 用于将构建的结果(如二进制文件)发布到指定的位置 -->

<publishers>

<!-- 决定在构建成功的情况下,发布哪些内容 -->

<!-- 备注: 在使用 maven2 进行项目管理时, package 后生成的 jar 包由于有版本后缀的因素,如 <ArtifactId-1.0-SNAPSHOT.war> 应此下图中如果用 file 则要加入相应的 SNAPSHOT 代码。 -->

<onsuccess>

<artifactspublisher dir="projects/${project.name}/target" dest="artifacts/${project.name}" />

</onsuccess>

<!-- 邮件通知相关的负责人 -->

<htmlemail charset="UTF-8"

buildresultsurl="http://127.0.0.1:8080/cruisecontrol/buildresults/${project.name}"

mailhost="smtp.qq.com" password=" ***** "

username=" ***** " defaultsuffix="@qq.com"

returnname="PetClinic Continuous Integration"

returnaddress="[email protected]"

skipusers="true"

xsldir="webapps/cruisecontrol/xsl"

css="webapps/cruisecontrol/css/cruisecontrol.css">

<always address="[email protected]" />

<success address="[email protected]" />

<map alias="admin" address="[email protected]" />

</htmlemail>

</publishers>

</project>


</cruisecontrol>

 

 

 

 

 

 

 

创建 cruisecontrol + svn + maven2

 

1. 创建 maven2 的简单项目



mvn archetype:create -DgroupId=org.sonatype.mavenbook /

-DartifactId=simple /

-DpackageName=org.sonatype.mavenbook


创建好项目后使用 mvn eclipse eclipse 将项目生成为 eclipse 项目

eclipse 中导入该项目





2. 构建 svn 服务器

Subversion 已经包含在 main 仓库中。所以,要安装 Subversion ,您只需要简单的运行:

$ sudo apt-get install subversion

$ sudo apt-get install libapache2-svn

许多位置都可以放置 Subversion 文件仓库,其中两个最常用的是: /usr/local/svn 以及 /home/svn 。为了在下面的描述中简单明了,我们假设您的 Subversion 文件仓库放在 /home/svn ,并且你的项目名称是简单的“ myproject”

同样的,也有许多常用的方式设置文件仓库的访问权限。然而,这也是安装过程中最经常出现错误的地方。典 型的情况下,应该创建一个名为“ Subversion” 的组来拥有文件仓库所在的目录。下面是一个快速的操作说明,有关内容请参考相关文档的详细说明:

  • Ubuntu 菜单上选择“系统 -> 系统管理 -> 用户和组”;

  • 切换到“组”标签;

  • 点击“添加组”按钮;

  • 组名为“ subversion”

  • 将您自己和“ www-data”(Apache 用户 ) 加入组成员中;

  • 点击“ OK” 以确认修改,关闭该程序。

或者使用命令完成上述功能(增加组,并且把用户加到组里):

sudo addgroup subversion

sudo usermod -G subversion -a www-data

再或者直接使用命令编辑组文件 "sudo vi /etc/group" ,增加组和成员(不推荐):

$ sudo vi /etc/group

结果看上去,像这样。

$ cat /etc/group|grep subversion

subversion:x:1001:www-data,exp

您需要注销然后再登录以便您能够成为 subversion 组的一员,然后就可以执行签入文件( Check in ,也称提交文件)的操作了。

现在执行下面的命令

$ sudo mkdir /home/svn

$ cd /home/svn

$ sudo mkdir myproject

$ sudo chown -R root:subversion myproject

下面的命令用于创建 SVN 文件仓库:

$ sudo svnadmin create /home/svn/myproject

赋予组成员对所有新加入文件仓库的文件拥有相应的权限:

$ sudo chmod -R g+rws myproject

如果上面这个命令在创建 SVN 文件仓库之前运行,你可能在后续 Check in 的时候遇到如下错误:

Can't open '/home/svn/myproject/db/txn-current-lock': Permission denied

查看 txn-current-lock 文件的权限和用户以及组信息,应该类似于:

$ ls -l /home/svn/myproject/db/txn-current-lock

-rw-rwSr-- 1 root subversion 0 2009-06-18 15:33 txn-current-lock

除了权限以外,用户及其组如果不对,则仍然会遇到上述问题,可以再次运行命令:

$ sudo chown -R root:subversion myproject




将上面创建的 example 项目上传到 svn 服务器上去。




2.cruisecontrol 配置


example 项目上传到 svn 服务器上去后,进入 cruisecontrol 目录下的 projects 目录通过下面语句将 example 项目 checkout projects 下。

svn checkout file:///home/svn


根据上面的config.xml 文件配置好config.xml 文件内容

进入cruisecontrol 目录

在控制台运行 ./ cruisecontrol 来启动 cruisecontrol


打开浏览器输入 http://localhost:8080 即可对 cruisecontrol 进行查看

 

 

 


附:gwt1.5的maven2的pom.xml代码 其中集成了 cobertura ,checkstyle.pmd,findbugs,jdepend.javancss

 

 

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <!-- GWT-Maven archetype generated POM --> <modelVersion>4.0.0</modelVersion> <groupId>rssServer</groupId> <artifactId>myArtifactId</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>gwt-maven-archetype-project</name> <!-- include pluginRepository and repository for GWT-Maven --> <pluginRepositories> <pluginRepository> <id>gwt-maven-plugins</id> <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/</url> </pluginRepository> </pluginRepositories> <repositories> <repository> <id>gwt-maven</id> <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/</url> </repository> </repositories> <!-- convenience to define GWT version in one place --> <properties> <gwtVersion>1.5.3</gwtVersion> </properties> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <!-- GWT deps (from central repo) --> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-servlet</artifactId> <version>${gwtVersion}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>rome</groupId> <artifactId>rome</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-user</artifactId> <version>${gwtVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-dev</artifactId> <version>${gwtVersion}</version> <classifier>${platform}-libs</classifier> <type>zip</type> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-dev</artifactId> <version>${gwtVersion}</version> <classifier>${platform}</classifier> <scope>provided</scope> </dependency> <!-- test --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.1</version> <scope>test</scope> </dependency> <dependency> <groupId>jdom</groupId> <artifactId>jdom</artifactId> <version>1.1</version> </dependency> </dependencies> <build> <plugins> <!-- configure the GWT-Maven plugin --> <!-- continuous Database integration (CDBI) begin --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> <version>1.2</version> <dependencies> <!-- specify the dependent jdbc driver here --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> </dependencies> <!-- common configuration shared by all executions --> <configuration> <driver>com.mysql.jdbc.Driver</driver> <url>jdbc:mysql://localhost:3306/mysql</url> <username>root</username> <password>asdfaa</password> <!-- You can comment out username/password configurations and have maven to look them up in your settings.xml using ${settingsKey} --> <settingsKey>sensibleKey</settingsKey> <!--all executions are ignored if -Dmaven.test.skip=true--> <skip>${maven.test.skip}</skip> </configuration> <executions> <execution> <id>drop-db-before-test-if-any</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <!-- need another database to drop the targeted one --> <url>jdbc:mysql://localhost:3306/mysql</url> <autocommit>true</autocommit> <sqlCommand>drop database yourdb</sqlCommand> <!-- ignore error when database is not avaiable --> <onError>continue</onError> </configuration> </execution> <execution> <id>create-db</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <url>jdbc:mysql://localhost:3306/mysql</url> <!-- no transaction --> <autocommit>true</autocommit> <sqlCommand>create database yourdb</sqlCommand> </configuration> </execution> <execution> <id>create-schema</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <url>jdbc:mysql://localhost:3306/yourdb</url> <autocommit>true</autocommit> <srcFiles> <srcFile>src/main/resources/create_channel.sql</srcFile> </srcFiles> </configuration> </execution> <execution> <id>create-data</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <orderFile>ascending</orderFile> <fileset> <basedir>${basedir}</basedir> <includes> <include>src/main/resources/insert.sql</include> </includes> </fileset> </configuration> </execution> </executions> </plugin> <!-- end --> <plugin> <groupId>com.totsp.gwt</groupId> <artifactId>maven-googlewebtoolkit2-plugin</artifactId> <version>2.0-RC1</version> <configuration> <compileTargets> <value>myGroupId.Application</value> </compileTargets> <runTarget>myGroupId.Application/Application.html</runTarget> <logLevel>INFO</logLevel> <mce:style><!-- DETAILED --></mce:style><style mce_bogus="1">DETAILED</style> <noServer>false</noServer> <extraJvmArgs>-Xmx512m</extraJvmArgs> <gwtVersion>${gwtVersion}</gwtVersion> </configuration> <executions> <execution> <goals> <!-- <goal>mergewebxml</goal>--> <!-- <goal>i18n</goal>--> <goal>compile</goal> <goal>test</goal> </goals> </execution> </executions> </plugin> <!-- Use the dependency plugin to unpack gwt-dev-PLATFORM-libs.zip --> <!-- (this is a replacement for the old "automatic" mode - useful if you don't have GWT installed already, or you just want a maven way to handle gwt deps) --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack</id> <phase>compile</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>com.google.gwt</groupId> <artifactId>gwt-dev</artifactId> <version>${gwtVersion}</version> <classifier>${platform}-libs</classifier> <type>zip</type> <overWrite>false</overWrite> <outputDirectory>${settings.localRepository}/com/google/gwt/gwt-dev/${gwtVersion}</outputDirectory> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <!-- If you want to use the target/web.xml file mergewebxml produces, tell the war plugin to use it. Also, exclude what you want from the final artifact here. --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <!-- <webXml>target/web.xml</webXml>--> <warSourceExcludes>.gwt-tmp/**</warSourceExcludes> </configuration> </plugin> <!-- tell the compiler we can use 1.5 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <configuration> <check> <branchRate>85</branchRate> <lineRate>85</lineRate> <haltOnFailure>true</haltOnFailure> <totalBranchRate>85</totalBranchRate> <totalLineRate>85</totalLineRate> <packageLineRate>85</packageLineRate> <packageBranchRate>85</packageBranchRate> <regexes> <regex> <pattern>src.main.java.myGroupId.client.*</pattern> <branchRate>40</branchRate> <lineRate>30</lineRate> </regex> <regex> <pattern>src.main.java.myGroupId.server.*</pattern> <branchRate>40</branchRate> <lineRate>30</lineRate> </regex> </regexes> </check> </configuration> <executions> <execution> <goals> <goal>clean</goal> <goal>check</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.3</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <enableRulesSummary>false</enableRulesSummary> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jdepend-maven-plugin</artifactId> <version>2.0-beta-2</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>javancss-maven-plugin</artifactId> <version>2.0</version> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>javancss-maven-plugin</artifactId> <version>2.0</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.0.1</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.3</version> <configuration> <linkXref>true</linkXref> <sourceEncoding>utf-8</sourceEncoding> <minimumTokens>100</minimumTokens> <targetJdk>1.5</targetJdk> <excludes> <exclude>**/*Bean.java</exclude> <exclude>**/generated/*.java</exclude> </excludes> <excludeRoots> <excludeRoot>target/generated-sources/stubs</excludeRoot> </excludeRoots> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>2.0</version> <configuration> <effort>Max</effort> <threshold>Low</threshold> <findbugsXmlOutput>true</findbugsXmlOutput> <!-- Optional directory to put findbugs xml report --> <findbugsXmlOutputDirectory>target</findbugsXmlOutputDirectory> <!-- <includeFilterFile>lib-filter.xml</includeFilterFile> --> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jdepend-maven-plugin</artifactId> <version>2.0-beta-2</version> </plugin> </plugins> </reporting> <!-- profiles (with activation per platform) --> <profiles> <profile> <id>gwt-dev-windows</id> <properties> <platform>windows</platform> </properties> <activation> <activeByDefault>true</activeByDefault> <os> <family>Windows</family> </os> </activation> </profile> <profile> <id>gwt-dev-mac</id> <properties> <platform>mac</platform> </properties> <activation> <os> <family>mac</family> </os> </activation> </profile> <profile> <id>gwt-dev-linux</id> <properties> <platform>linux</platform> </properties> <activation> <os> <name>Linux</name> </os> </activation> </profile> </profiles> </project>

你可能感兴趣的:(maven,SVN,脚本,database,gwt,subversion)