`
Virgo_S
  • 浏览: 1140751 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Ant自动化构建

阅读更多
<?xml version="1.0"?>   
<project name="testAnt" basedir="." default="mail">
	
	<!-- ========== 属性定义  ========= -->
	<property name="pro.name" value="testAnt" />
	<property name="pro.author" value="VS" />
	<property name="src.dir" value="src/main/app" />
	<property name="pro.web.root" value="WebContent" />
	<property name="pro.web.source" value="${pro.web.root}/WEB-INF" />
	<property name="pro.lib" value="${pro.web.source}/lib" />
	<property name="pro.build.path" value="${pro.web.source}/classes" />
	<property name="user.dir" value="${pro.build.path}" />
	  
	<!-- ========== 邮件发送  ========= -->
	<target name="mail" depends="mkzip">   
		<mail mailhost="smtp.126.com" mailport="25" subject="The Build Test" user="shibanan" password="*********" messagemimetype="text/html">   
			<from address="shibanan@126.com" name="VS" />   
			<fileset dir="report/html">   
				<include name="**/test-result${ant.project.name}.zip" />   
			</fileset>   
			<to address="shibanan@hotmail.com" name="VS" />   
			<message>The ${pro.name}--${pro.author} has been tested ! </message>   
		</mail>   
	</target>
	
	<!-- ========== 测试报告打包  ========= -->
	<target name="mkzip" depends="report">   
		<jar destfile="report/html/test-result${ant.project.name}.zip">   
			<fileset dir="report/html">   
				<include name="**/*.html" />   
				<include name="**/*.css" />   
				<include name="**/*.txt" />   
			</fileset>   
		</jar>   
	</target>
	 
	<!-- ========== 生成测试报告  ========= -->
	<target name="report" depends="junit">   
		<junitreport id="myJUnitReport" taskname="reported" todir="report" description="Junit Report">   
			<fileset dir="report">   
				<include name="TEST-*.xml" />   
			</fileset>   
			<report todir="report/html" />   
		</junitreport>   
	</target>
	
	<!-- ========== 测试  ========= -->
	<target name="junit" depends="build">   
		<mkdir dir="report/html" />   
		<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">   
			<formatter type="plain" usefile="false" />   
			<formatter type="xml" />   
			<test name="test.TestHelloWorld" todir="report" />   
			<classpath refid="classpath" />   
         </junit>   
	</target>
	
	<!-- ========== 编译  ========= -->
	<target name="build" depends="prepare">   
		<javac destdir="${pro.build.path}" target="1.5">   
			<src path="${src.dir}" />   
			<classpath refid="classpath" />   
		</javac>   
		<javac destdir="${pro.build.path}" target="1.5">   
			<src path="src/main/test" />   
			<classpath refid="classpath" />   
		</javac>   
	</target>
	
	<!-- ========== 初始化  ========= -->
	<target name="prepare" depends="clean">   
		<copy todir="${pro.build.path}">   
			<fileset dir="${src.dir}">   
				<include name="**/*.properties" />   
				<include name="**/*.xml" />   
			</fileset>   
		</copy>   
	</target>
	
	<!-- ========== 清理  ========= -->
	<target name="clean">   
		<delete>   
			<fileset dir="${pro.build.path}">   
				<include name="**/*.*" />   
			</fileset>   
			<fileset dir="report">   
				<include name="**/*.*" />   
			</fileset>   
		</delete>   
	</target>
	
	
	<path id="classpath">   
		<fileset dir="${pro.lib}">   
			<include name="*.jar" />   
		</fileset>   
		<pathelement path="${pro.build.path}" />   
	</path>
	
	
</project>  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics