上个项目中写的Ant build文件

类别:Java 点击:0 评论:0 推荐:

一、上一个项目中写的,可以编译、自动化测试、打包的build.xml

<?xml version="1.0"?>
<project name="SimulatorEL" basedir="." default="all">
<!-- edit by YangHuaWei -->
 
 <property name="build.dir" value="classes"/>
 <property name="lib.dir" value="lib"/>
    <property name="dist.dir" value="dist"/>
    <property name="source.dir" value="./SimulatorEL/src"/>
 <property name="testSrc.dir" value="./SimulatorEL/test"/>
 
 <property name="report.dir"   value="report" />
 <property name="report_html.dir"   value="${report.dir}/html" />
   
 <property name="cvs.repository" value=":pserver:yanghw:cvs@localhost:/usr/local/cvsroot"/>
    <property name="cvs.package" value="SimulatorEL"/>
 
 <property name="common.src" value="Common"/>
 <property name="common.class" value="CommonClass"/>

 <property name="release_AP.dir" value="SimAP/SimulatorEL/AP"/>
 
 <path id="project.classpath">
  <fileset dir="${lib.dir}">
   <include name="**/*.jar"/>
  </fileset>
  <pathelement path="${build.dir}"/>
 </path>
 
 <target name="init" description="Prepare for build">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${dist.dir}"/>
        <!--mkdir dir="${logdir}"/-->
  <!--mkdir dir="${report.dir}"/-->
  <mkdir dir="${report_html.dir}"/>
 </target>

 <target name="clean" description="Clean all build products">
        <delete dir="${build.dir}" quiet="true"/>
        <delete dir="${dist.dir}" quiet="true"/>
        <delete dir="SimulatorEL" quiet="true"/>
        <delete dir="${report.dir}" quiet="true"/>
  
  <delete dir="${common.class}" quiet="true"/>
    </target>

    <target name="compile" depends="init,checkout,common_build" description="Compile application">
        <javac srcdir="${source.dir}" destdir="${build.dir}" encoding="EUC-JP"
         includes="**/*.java" debug="on" deprecation="on">
   <classpath refid="project.classpath"/>
  </javac>
    </target>

 <target name="compile_test" depends="compile" description="compile the classes of test">
  <javac srcdir="${testSrc.dir}" destdir="${build.dir}" encoding="EUC-JP"
         includes="**/*.java" debug="on" deprecation="on">
   <classpath refid="project.classpath"/>
  </javac>
 </target>

    <target name="test" depends="compile_test" description="Run unit tests">
        <!--delete dir="${junit.results}"/>
        <mkdir dir="${junit.results}"/-->
  <tstamp/>
        <junit fork="yes" haltonfailure="no">
            <jvmarg value="-Duser.dir=/home/docomo/simBuild/SimulatorEL"/>
            <classpath refid="project.classpath"/>
            <formatter type="xml" usefile="true"/>
            <!--formatter type="xml"/-->
            <batchtest todir="${report.dir}">
                <fileset dir="${build.dir}" includes="**/*Test.class"/>
            </batchtest>
        </junit>
  
  <junitreport todir="${report.dir}">
   <fileset dir="${report.dir}">
     <include name="TEST-*.xml" />
   </fileset>
   <report format="frames" todir="${report_html.dir}" />
  </junitreport>
  <jar jarfile="${report.dir}/SimulatorELTestReport-${DSTAMP}-${TSTAMP}.zip" basedir="${report_html.dir}"/>
    </target>
 

 <target name="mail" depends="test">
  <mail mailhost="192.168.98.1" subject="Test report">
     <from address="[email protected]"/>
     <to address="[email protected]"/>
     <message>The nightly build/test has completed</message>
     <fileset dir="${report.dir}">
     <include name="*.zip"/>
     </fileset>
  </mail>
    </target>
 
 <target name="common_build" description="Build common module">
  <!-- checkout common module from cvs -->
  <delete dir="${common.src}" quiet="true"/>
  <cvs cvsroot="${cvs.repository}" package="Common" dest="."/>
  
  <!-- compile and jar the common module -->
  <mkdir dir="${common.class}"/>
  <javac srcdir="${cttcommsrc}" destdir="${common.class}" excludes="**/*Test.java" encoding="EUC-JP">
   <classpath refid="project.classpath"/>
  </javac>
  <delete file="${lib.dir}/common.jar" quiet="true"/>
  <jar jarfile="${lib.dir}/common.jar" basedir="${common.class}"/>
 </target>

 <target name="tar" depends="compile,jar" description="Creates a tar archive">
  <delete dir="SimAP" quiet="true"/>
  <mkdir dir="${release_AP.dir}/src"/>
  <mkdir dir="${release_AP.dir}/conf"/>
  <mkdir dir="${release_AP.dir}/lib"/>
  <!--mkdir dir="SimAP/SimulatorEL/AP/conf"/-->
  
  <copydir src="${source.dir}" dest="${release_AP.dir}/src" includes="**/*.java"/>
   
  <copydir src="SimulatorEL/config/SimulatorEL/AP/conf" dest="${release_AP.dir}/conf"/>

  <!--copydir src="SimulatorEL/images" dest="SimAP/SimulatorEL/AP/conf/images"/-->  

  <copy file="${dist.dir}/SimulatorEL.jar" todir="${release_AP.dir}/lib"/>

  <copy todir="${release_AP.dir}/lib">
   <fileset dir="${lib.dir}">
    <include name="emsutil.jar"/>
    <include name="common.jar"/>
   </fileset>
  </copy>
  
  <tar tarfile="${dist.dir}/SimulatorEL.tar" basedir="SimAP"/>
  <gzip zipfile="${dist.dir}/SimulatorEL.tar.gz" src="${dist.dir}/SimulatorEL.tar"/>
 </target>
 
 <target name="jar">
        <jar jarfile="${dist.dir}/SimulatorEL.jar">
            <fileset dir="${build.dir}">
    <exclude name="**/*Test*"/>
   </fileset>
        </jar>
    </target>

    <target name="checkout" description="Update package from CVS">
        <cvs cvsroot="${cvs.repository}" package="${cvs.package}" dest="."/>
    </target>

 <target name="all" depends="clean,mail,tar" description="Build application"/>
 
</project>

二、在Linux下写一个shell文件autoTest.sh

       cd ~/build

       source ~/.docomo.profile

       ant mail

三、加入到crontab中,每天自动运行

       # crontab -e

         4 9 * * * /home/docomo/build/autoTest.sh

crontab的使用参见收藏的文章

 

本文地址:http://com.8s8s.com/it/it15682.htm