Ant的例子—编译/打包/报表/email /DOC/测试

<!--author:黄庆飞 ; date:2006.7 http://hqflysky.spaces.msn.com/-->


<?xml version="1.0"?>
<project name="sunpkcs11" default="help" basedir=".">
 <!-- properies -->
 <property name="src.dir" value="src" />
 <property name="report.dir" value="report" />
 <property name="classes.dir" value="bin" />
 <property name="lib.dir" value="lib" />
 <property name="dist.dir" value="packoutput" />
 <property name="doc.dir" value="doc" />
 <property name="test.dir" value="testcases" />
 <property name="jre.dir" value="D:/winxp program/JBuilderX/jdk1.5/jre/lib" />
 <property name="eclipse_plugins.dir" value="D:/winxp program/eclipse/plugins" />
 <property environment="env"/>
 <property name="java.home" value="${env.JAVA_HOME}"/>
 <property name="ant.home"  value="${env.ANT_HOME}"/>
 <property name="java.home" value="${system.dir}"/>
 <!-- 定义classpath -->
 <path id="master-classpath">
  <fileset file="${lib.dir}" id="mylib">
   <include name="lib/mail.jar" />
   <include name="lib/activation.jar" />
   <include name="lib/bcprov-jdk15-131.jar" />
   <include name="lib/jdom.jar" />
   <include name="lib/mssqlserver.jar" />
   <include name="lib/msutil.jar" />
   <include name="lib/msbase.jar" />
   <include name="lib/junit.jar" />
   <include name="lib/jaxp/*.jar" />
  </fileset>
 </path>
 <path id="plusin-classpath">
  <fileset file="${eclipse_plugins.dir}" id="pluslib">
   <include name="${eclipse_plugins.dir}/org.junit_3.8.1/*.*" />
  </fileset>
 </path>
 <!-- 初始化任务 -->
 <target name="init" description="initialize global parameter...">
  <echo> 初始化开始 </echo>
  <available property="junit.present" classname="junit.framework.TestCase" />
  <echo> 初始化结束  </echo>
 </target>
 <target name="welcome" description="WelCome, Show System Information...">
  <echo message="系统基本配置信息"/>
  <echo message="Number of Processors = ${env.NUMBER_OF_PROCESSORS}"/>
  <echo message="ANT_HOME is set to = ${ant.home}"/>
  <echo message="JAVA__HOME is set to = ${java.home}"/>
 </target>
 <!-- 编译 -->
 <target name="compile" depends="init" description="compile the source files">
  <echo> 编译开始 </echo>
  <mkdir dir="${classes.dir}" />
  <javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.5">
   <classpath refid="master-classpath" />
   <exclude name="test/*.java"/>
  </javac>
  <echo> 编译结束 </echo>
 </target>
 <!-- 打包成jar -->
 <target name="pack" depends="compile" description="make .jar file">
  <echo> 开始打包jar </echo>
  <mkdir dir="${dist.dir}" />
  <jar destfile="${dist.dir}/hqfAPI.jar" basedir="${classes.dir}">
   <exclude name="**/*build*.*" />
  </jar>

  <!-- 复制用到的库 -->
  <mkdir dir="${dist.dir}/lib" />
  <copy todir="${dist.dir}">
   <fileset refid="mylib" />
  </copy>
  <!-- 复制本地化文件 -->
  <!--copy todir="${dist.dir}" file="${swt.dll}"/-->
  <echo> 结束打包jar </echo>
 </target>
 
 <!--  测试初始化 -->
 <target name="test-init" depends="pack" description="initialiaze local directory before junit test...">
  <echo message="测试初始化---开始"/>
  <delete dir="${test.dir}" />
  <mkdir dir="${test.dir}"/>
  <delete dir="${report.dir}" />
     <mkdir dir="${report.dir}"/> 
  <echo message="测试初始化---结束"/>
 </target>

 <!--编译测试组-->
 <target name="compiletests" depends="test-init" description="compile junit test class...">
  <echo message="编译测试组开始"/>
  <javac srcdir="${src.dir}/test" destdir="${test.dir}" target="1.5">
   <classpath refid="master-classpath" />
   <classpath id="winxp_lib">
    <pathelement path="${dist.dir}/hqfAPI.jar"/>
   </classpath>
   <include name="**.*"/>
  </javac>
  <jar destfile="${dist.dir}/testall.jar" basedir="${test.dir}">
  </jar>
  <echo message="编译测试组结束"/>
 </target>
 <!--  运行junit  -->
 <target name="runtests" depends="compiletests" description="run junit test suit and build a report about it...">
  <echo message="run test开始" />
  <junit printsummary="true" haltonfailure="true" fork="yes">
   <classpath refid="master-classpath" />
   <classpath>
    <pathelement location="${dist.dir}/*.jar" />
    <pathelement location="${test.dir}/test/*.*" />
    <pathelement path="" />
   </classpath>
   <classpath>
    <pathelement path="${dist.dir}/hqfAPI.jar"/>
   </classpath>
   <formatter type="plain"/>
   <test name="test.testall" haltonfailure="no" outfile="${report.dir}/result">
       <formatter type="xml"/>
   </test>
  </junit> 
  <echo message="run test结束" />
 
  <echo message="自动生成测试报表开始"/>
  <junitreport todir="${report.dir}">
   <fileset dir="${report.dir}">
    <include name="*.xml" />
   </fileset>
   <report format="frames" todir="${report.dir}/html" />   
  </junitreport>
  <echo message="自动生成测试报表结束"/>
 </target>
 
 <!--压缩report成zip文件-->
 <target name ="zip" description ="zip the report files...">
  <zip destfile="${report.dir}/reports.zip">
     <zipfileset dir="${report.dir}/html" prefix=""/>     
   </zip>
    </target>
 
 
 <!--将zip文件发送email-->
 <target name ="mail" description ="mail the zip report file to the manager...">
 <mail mailhost="smtp.tom.com" mailport="25" subject="Test build" user="XXX" password="XXX"  charset="utf-8" messagemimetype="multipart/mixed">
   <from name="XXX" address="
XXX@tom.com"/>
   <to name="XXX" address="
XXX@sina.com"/>
   <cc name="XXX" address="
XXX@sina.com"/>
   <bcc name="XXX" address="
XXX@21cn.com"/
   <message>The nightly build has completed</message>
   <fileset dir="${report.dir}">
     <include name="reports.zip"/>
   </fileset>
 </mail>
 </target> 
 
 <!-- 输出api文档  -->

 <target name="doc"  description="create api doc">
     <echo message="正在更新api文档"/>
  
  <delete dir="${doc.dir}" />
  <mkdir dir="${doc.dir}" />
  <javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="HQF API">
   <packageset dir="${src.dir}" defaultexcludes="yes">
    <include name="com/hqf/security/**" />
    <include name="com/hqf/email/**" />
    <include name="com/hqf/http/**" />
    <include name="com/hqf/test/**" />
   </packageset>
   <doctitle>
    <![CDATA[<h1>XXX GEDIP API</h1>]]></doctitle>
  <bottom>
   <![CDATA[<i>XXXAll Rights Reserved.</i>]]></bottom>
        <tag name="todo" scope="all" description="To do:" />
  </javadoc>
  <echo message="更新api文档结束"/>
 </target>
 
 <target name="help" description="show help">
  <echo message="Build the usage_example project"/>
  <echo message="Usage: ant [ant options] [target1]\
  [target2 | target3 | ... ]"/>
  <echo message=""/>
  <echo message=" build-lib - build just the project's library"/>
  <echo message=" build-app - build the library and \
 the application"/>
  <echo message=" deploy-app - ready the \
 application for deployment"/>
  <echo message=" makedoc - generate all the \
 documentation for the project"/>
  <echo message=" -projecthelp - (An Ant option) Display all \
 target descriptions"/>
 </target>
</project>

 

<!--author:黄庆飞 ; date:2006.7-->

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值