c-build.xml


<?xml version="1.0" encoding="UTF-8"?>
<project name="webclients2" default="" basedir=".">
<!--${ant.project.name}-->
<!-- 链接库目录 -->
<property name="lib.dir" value="${basedir}/lib" />
<!--工程目录-->
<property name="src" value="${basedir}/src" />
<property name="test" value="${basedir}/test" />
<property name="function" value="${basedir}/function" />
<!-- 工程编译目录 -->
<property name="build.dir" value="${basedir}/build" />
<property name="desc.dir" value="${build.dir}/desc" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="function.dir" value="${build.dir}/function" />
<!-- Tomcat 目录 -->
<property name="tomcat.dir" value="/opt/javaworkspace/tomcat" />
<property name="tomcatlib.dir" value="${tomcat.dir}/lib" />
<!-- Selenium 目录-->
<property name="selenium.dir" value="/opt/java/selenium/selenium-server-1.0-beta-1" />
<!-- 测试编译目录 -->
<property name="test.dir" value="${build.dir}/test" />
<property name="function.dir" value="${build.dir}/function" />
<property name="report.dir" value="${build.dir}/Report" />
<property name="junitreport.dir" value="${report.dir}/JunitReport" />
<property name="finalreport.dir" value="${report.dir}/FinalReport" />
<!-- 数据库 -->
<property file="${basedir}/config/datasource.properties" />
<property name="changelog" value="${basedir}/database/database.changelog.xml" />
<!-- 链接库(jar;class文件) -->
<path id="base.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- ant-contrib.jar -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${tomcatlib.dir}/ant-contrib-0.6.jar" />
</classpath>
</taskdef>
<!-- Clean 编译的文件-需要修改-->
<target name="clean" depends="tomcat.stop">
<delete dir="${build.dir}" />
<delete dir="${basedir}/classes">
</delete>
<delete>
<fileset dir="${tomcat.dir}/webapps">
<include name="${ant.project.name}.war" />
</fileset>
</delete>
<delete dir="${tomcat.dir}/webapps/${ant.project.name}" />
<delete dir="${tomcat.dir}/work/Catalina/localhost/${ant.project.name}" />
</target>
<!-- 生成编译文件目录 --需要改-->
<target name="init" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${report.dir}" />
<mkdir dir="${test.dir}" />
<mkdir dir="${function.dir}" />
<mkdir dir="${desc.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${report.dir}" />
<mkdir dir="${junitreport.dir}" />
<mkdir dir="${finalreport.dir}" />
<copy todir="${desc.dir}">
<fileset dir="${basedir}/WebRoot" />
</copy>
<copy todir="${classes.dir}">
<fileset dir="${basedir}/config">
<include name="*.xml" />
<include name="*.properties" />
</fileset>
</copy>
<copy todir="${test.dir}">
<fileset dir="${basedir}/config">
<include name="*.xml" />
<include name="*.properties" />
</fileset>
</copy>
</target>
<!-- 编译src -->
<target name="compile-src" depends="init">
<javac srcdir="${src}" destdir="${classes.dir}">
<classpath refid="base.classpath" />
</javac>
<copy todir="${classes.dir}/com/goodhope/pojo">
<fileset dir="${basedir}/src/com/goodhope/pojo">
<include name="*.xml" />
</fileset>
</copy>
<copy todir="${classes.dir}/com/goodhope/action">
<fileset dir="${basedir}/src/com/goodhope/action">
<include name="*.xml" />
</fileset>
</copy>
</target>
<!-- 编译test -->
<target name="compile-test" depends="compile-src">
<javac srcdir="${test}" destdir="${test.dir}">
<classpath path="${classes.dir}" />
<classpath refid="base.classpath" />
</javac>
</target>
<!-- 编译function -->
<target name="compile-function" depends="compile-src,compile-test">
<javac srcdir="${function}" destdir="${function.dir}">
<classpath path="${classes.dir}" />
<classpath refid="base.classpath" />
</javac>
</target>

<!--生成 War 包 -->
<target name="war" depends="compile-function">
<war warfile="${build.dir}/${ant.project.name}.war" webxml="${desc.dir}/WEB-INF/web.xml">
<lib dir="${basedir}/lib" />
<classes dir="${classes.dir}" />
<fileset dir="${desc.dir}">
</fileset>
</war>
</target>
<!-- 部署 War 到 Tomcat -->
<target name="deploy" depends="war">
<copy todir="${tomcat.dir}/webapps">
<fileset dir="${build.dir}">
<include name="${ant.project.name}.war" />
</fileset>
</copy>
<antcall target="tomcat.start" />
</target>

<!--启动 Tomcat -->
<target name="tomcat.start">
<ant antfile="${tomcat.dir}/tomcat-build.xml" target="tomcat.start" inheritall="false" />
</target>
<!--停止 Tomcat -->
<target name="tomcat.stop">
<ant antfile="${tomcat.dir}/tomcat-build.xml" target="tomcat.stop" inheritall="false" />
</target>

<!-- 单元测试-生成单元测试报告 -->
<target name="junit-test" depends="deploy">
<junit printsummary="on" fork="true" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath>
<pathelement location="${test.dir}" />
<pathelement location="${classes.dir}" />
<path refid="base.classpath" />
</classpath>
<formatter type="xml" />
<batchtest todir="${junitreport.dir}" fork="true">
<fileset dir="${test.dir}">
<include name="**/*Test.*" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${junitreport.dir}">
<fileset dir="${junitreport.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${junitreport.dir}" />
</junitreport>
<fail if="tests.failed">
</fail>
</target>

<!--启动 Selenium 服务器 -->
<target name="selenium.start">
<if>
<not>
<socket server="localhost" port="4444" />
</not>
<then>
<java jar="${selenium.dir}/selenium-server.jar" fork="true" spawn="true" />
<waitfor maxwait="5" maxwaitunit="minute" checkevery="3" checkeveryunit="second">
<and>
<socket server="localhost" port="4444" />
</and>
</waitfor>
</then>
</if>
</target>
<!-- 停止 Selenium 服务器 -->
<target name="selenium.stop">
<if>
<socket server="localhost" port="4444" />
<then>
<get taskname="selenium-shutdown" dest="${functionTest.report.dir}/selenium-result.txt" src="http://localhost:4444/selenium-server/driver/?cmd=shutDown" ignoreerrors="true" />
</then>
</if>
</target>
<!-- test-all -->
<target name="function-test" depends="junit-test">
<!-- 并行容器节点,一边同时打开tomcat 和selenium server,一边等待两者打开后执行JUnit测试。
如果不使用并行节点,而是用spawn=yes属性后台启动tomcat,则屏幕里看不到tomcat信息,如果测试意外终止的话,也不能关闭tomcat -->
<parallel>
<antcall target="tomcat.start" />
<antcall target="selenium.start" />
<sequential>
<waitfor maxwait="5" maxwaitunit="minute" checkevery="3" checkeveryunit="second">
<and>
<socket server="localhost" port="8099" />
</and>
</waitfor >
<waitfor maxwait="5" maxwaitunit="minute" checkevery="3" checkeveryunit="second">
<and>
<socket server="localhost" port="4444" />
</and>
</waitfor >
<!-- Junit Test All -->
<junit printsummary="on" fork="true" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath>
<pathelement path="${function.dir}" />
<path refid="base.classpath" />
</classpath>
<formatter type="xml" />
<batchtest todir="${finalreport.dir}">
<fileset dir="${function.dir}">
<include name="**/*Test.*" />
</fileset>
</batchtest>
</junit>
<!-- 生成总测试报告 -->
<junitreport todir="${finalreport.dir}">
<fileset dir="${finalreport.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${finalreport.dir}" />
</junitreport>
<fail if="tests.failed">
</fail>
<antcall target="tomcat.stop" />
</sequential >
</parallel>
<antcall target="selenium.stop" />
</target>

<target name="all">
<antcall target="function-test"></antcall>
</target>

<!-- 刷数据库 -->
<!-- 更新数据-->
<target name="update-database">
<taskdef name="updateDatabase" classname="liquibase.ant.DatabaseUpdateTask" classpathref="base.classpath" />
<updateDatabase changeLogFile="${changelog}" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/atm" username="goodhope" password="goodhope" dropFirst="true" classpathref="base.classpath" />
</target>
<!-- 配置文件 -->
<taskdef resource="migratortasks.properties" classpathref="base.classpath" />
<!-- 指定执行文件位置 -->
<macrodef name="excuteScript">
<attribute name="dir" />
<attribute name="dropFirst" default="false" />
<sequential>
<migrateDatabase defaultschemaname="public" changeLogFile="@{dir}/script_suite.xml" driver="${dirver}" url="${url}" username="${username}" password="${password}" dropFirst="@{dropFirst}" classpathref="base.classpath" />
</sequential>
</macrodef>
<!-- 删除数据库表,并重新建立数据表 -->
<target name="fresh.atm.data" description="drop all table and rebuild schema">
<excuteScript dir="${basedir}/database/script/before" dropFirst="true" />
<excuteScript dir="${basedir}/database/script/create_table" />
<excuteScript dir="${basedir}/database/data" />
</target>
</project>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值