一直想写一个持续集成的ant build.xml,可惜试了一阵子也没有成功,也懒得去查文档了.今天偶然看到一个网友写的build.xml,从中借用并修改后就搞定了.记录一下几个有用的task,免得忘记.
1.cvs
进行cvs操作的有关task: cvs,cvspass等.
<target name="cvs">
<delete dir="${app.name}" />
<cvspass cvsroot="${cvsroot}" password="anonymous"/>
<cvs cvsRoot="${cvsroot}"
package="${app.name}"
dest="${basedir}"
/>
</target>
2.antcall
调用同一个build.xml中的其它target.
<target name="build" >
<antcall target="callscript-build" />
</target>
3.ant
调用其它build.xml,一般就是用来构建子工程.这里面inheritAll属性应该要注意一下,缺省值是true,也就是使用当前build.xml(父)的所有属性.如果在被你调用的build.xml也设有属性,最好把它设置为false.
<ant antfile="build.xml" dir="${project.home.dir}" target="main" inheritAll="false" output="callscript.log" />
4.exec
调用本地命令,不同的操作系统语法不太一样.
<exec executable="cmd.exe" os="Windows 2000">
<arg line="/c dir"/>
</exec>
5.property
定义build.xml中的属性.这个task大家太熟悉了.我这里要提的是使用它引入属性定义文件.因为这样可以保证build.xml不是正常改变,而各人只修改自己的属性文件.
<property file="build.properties"/>
build.properties
---------------------------------------
app.name=CS
tomcat.home=C:/Tomcat //开发人员的tomcat路径很可能是不一样的
6.junit
junit就是为了集成单元测试.这是maven自动生成的build.xml中关于单元测试的target.
<target name="internal-test" depends="compile-tests">
<mkdir dir="${testreportdir}">
</mkdir>
<junit dir="./" failureproperty="test.failure" printSummary="yes" haltοnerrοr="true" fork="true">
<sysproperty key="basedir" value=".">
</sysproperty>
<formatter type="xml">
</formatter>
<formatter usefile="false" type="plain">
</formatter>
<classpath>
<fileset dir="${libdir}">
<include name="*.jar">
</include>
</fileset>
<pathelement path="${testclassesdir}">
</pathelement>
<pathelement path="${classesdir}">
</pathelement>
</classpath>
<batchtest todir="${testreportdir}">
<fileset dir="E:\workspace\projects\maven\src\test">
<include name="**/HTMLMarkupTest.java">
</include>
<exclude name="**/NaughtyTest.java">
</exclude>
</fileset>
</batchtest>
</junit>
</target>
7.path和classpath
path和classpath不能算是task,而更应该象target,或者说是一个tag.其实就是定义你需要引用的类库.这里面还有一个专业名词:path-like structure.下面是一些基本用法:
<path id="base.path">
<pathelement location="${tomcat.home}/common/lib/servlet.jar"/>
</path>
<path id="project.path">
<path refid="base.path"/>
<pathelement location="${lib}/log4j-1.2.8.jar"/>
<pathelement location="${build}"/>
</path>
<classpath>
<pathelement path="${classpath}"/>
</classpath>
<classpath>
<pathelement path="${classpath}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
<dirset dir="${build.dir}">
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<filelist refid="third-party_jars"/>
</classpath>
1.cvs
进行cvs操作的有关task: cvs,cvspass等.
<target name="cvs">
<delete dir="${app.name}" />
<cvspass cvsroot="${cvsroot}" password="anonymous"/>
<cvs cvsRoot="${cvsroot}"
package="${app.name}"
dest="${basedir}"
/>
</target>
2.antcall
调用同一个build.xml中的其它target.
<target name="build" >
<antcall target="callscript-build" />
</target>
3.ant
调用其它build.xml,一般就是用来构建子工程.这里面inheritAll属性应该要注意一下,缺省值是true,也就是使用当前build.xml(父)的所有属性.如果在被你调用的build.xml也设有属性,最好把它设置为false.
<ant antfile="build.xml" dir="${project.home.dir}" target="main" inheritAll="false" output="callscript.log" />
4.exec
调用本地命令,不同的操作系统语法不太一样.
<exec executable="cmd.exe" os="Windows 2000">
<arg line="/c dir"/>
</exec>
5.property
定义build.xml中的属性.这个task大家太熟悉了.我这里要提的是使用它引入属性定义文件.因为这样可以保证build.xml不是正常改变,而各人只修改自己的属性文件.
<property file="build.properties"/>
build.properties
---------------------------------------
app.name=CS
tomcat.home=C:/Tomcat //开发人员的tomcat路径很可能是不一样的
6.junit
junit就是为了集成单元测试.这是maven自动生成的build.xml中关于单元测试的target.
<target name="internal-test" depends="compile-tests">
<mkdir dir="${testreportdir}">
</mkdir>
<junit dir="./" failureproperty="test.failure" printSummary="yes" haltοnerrοr="true" fork="true">
<sysproperty key="basedir" value=".">
</sysproperty>
<formatter type="xml">
</formatter>
<formatter usefile="false" type="plain">
</formatter>
<classpath>
<fileset dir="${libdir}">
<include name="*.jar">
</include>
</fileset>
<pathelement path="${testclassesdir}">
</pathelement>
<pathelement path="${classesdir}">
</pathelement>
</classpath>
<batchtest todir="${testreportdir}">
<fileset dir="E:\workspace\projects\maven\src\test">
<include name="**/HTMLMarkupTest.java">
</include>
<exclude name="**/NaughtyTest.java">
</exclude>
</fileset>
</batchtest>
</junit>
</target>
7.path和classpath
path和classpath不能算是task,而更应该象target,或者说是一个tag.其实就是定义你需要引用的类库.这里面还有一个专业名词:path-like structure.下面是一些基本用法:
<path id="base.path">
<pathelement location="${tomcat.home}/common/lib/servlet.jar"/>
</path>
<path id="project.path">
<path refid="base.path"/>
<pathelement location="${lib}/log4j-1.2.8.jar"/>
<pathelement location="${build}"/>
</path>
<classpath>
<pathelement path="${classpath}"/>
</classpath>
<classpath>
<pathelement path="${classpath}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
<dirset dir="${build.dir}">
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<filelist refid="third-party_jars"/>
</classpath>