http://down.51cto.com/zt/2163/37
http://www.ibm.com/developerworks/cn/java/j-lo-junit4/index.html
《老友记》,《绝望主妇》,《越狱》,《欢乐合唱团》
===============================
<?xml version="1.0"?>
<project name="Govt Filing System" default="build.project" basedir=".">
<import file ="clover.xml" />
<!-- Default build timestamp -->
<tstamp>
<format property="buildtime" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<!-- Load project build preference -->
<xmlproperty file="${basedir}/${build.prop}" keeproot="off"
semanticAttributes="true" includeSemanticAttribute="true" />
<!-- Load project specfic preference -->
<xmlproperty file="${project.preference}" semanticAttributes="true"
includeSemanticAttribute="true" />
<!-- Default values -->
<property name="build.target" value="" />
<property name="build.depends" value="true" />
<property name="frameBase" value="${frameworks.dir}" />
<target name="copy.dds.commanjars" >
<echo message="Copying DDS Common Jars......${dist.dir}/" />
<echo message="DDS Common Jars Location ......${dds.common}/" />
<!-- <mkdir dir="${dist.dir}" />-->
<copy file="${dds.common}/DDSCommon.jar" todir="${dist.dir}" />
<copy file="${dds.common}/DDSCommonService.jar" todir="${dist.dir}" />
<copy file="${dds.common}/DDSOffline.jar" todir="${dist.dir}" />
<copy file="${dds.common}/DDSOfflineClient.jar" todir="${dist.dir}" />
<copy file="${dds.common}/CommonServer.jar" todir="${dist.dir}" />
<copy file="${dds.common}/BatchClient.jar" todir="${dist.dir}" />
<copy file="${dds.common}/BatchContainer.jar" todir="${dist.dir}" />
<copy file="${dds.common}/atp-redis-cache-1.0.jar" todir="${dist.dir}" />
<echo message="@@@@@@@@@@@@@@@@@@ Path ...... ${dist.dir}/" />
</target>
<!-- Project compile classpath -->
<path id="compile.classpath">
<path refid="java.classpath" />
<path refid="websphere.classpath" />
<path refid="base.classpath" />
<path refid="project.classpath" />
</path>
<taskdef name="junit"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
classpathref="base.classpath"
/>
<!--
<taskdef name="junitee"
classname="org.junitee.anttask.JUnitEETask"
classpathref="base.classpath"
/>-->
<typedef name="buildproject"
classname="net.atpco.ant.build.ProjectBuilder"
classpathref="base.classpath" />
<typedef name="copypath"
classname="net.atpco.ant.build.CopyDirectory"
classpathref="base.classpath"/>
<typedef name="compress"
classname="net.atpco.ant.build.FileCompressorTask"
classpathref="base.classpath"/>
<target name="check.build" unless="build.pref">
<echo>*************** See how to build usage >build usage***************</echo>
<fail message="WARN: Project preference file not specified" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: init (runs for every project)
- - - - - - - - - - - - - - - - - -->
<target name="init" depends="with.clover,check.build">
<echo>*************** init started ***************</echo>
<tstamp>
<format property="buildtime" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<mkdir dir="${dist.dir}" />
<mkdir dir="${basedir}/tmp" />
<echo>*************** init finished ***************</echo>
</target>
<!-- =================================
target: build.project
Resolve and invoke the project and its dependency
================================= -->
<target name="build.project" >
<buildproject file="${build.pref}" target="${build.target}" builddepends="${build.depends}" />
</target>
<!-- =================================
target: clean ear jar
================================= -->
<target name="clean-ear-jars" description="Delete all jar files in EAR folder">
<echo message="Clean ${project.home.dir}/${appLib.dir}" />
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${project.home.dir}/${appLib.dir}" includes="**/*.jar" />
<fileset dir="${project.home.dir}/${applicationEar.dir}" includes="**/*.jar" />
</delete>
</target>
<!-- =================================
target: clean warlib
================================= -->
<target name="clean-war-libjars" description="Delete all jar files in WAR lib folder">
<echo message="Clean ${project.home.dir}/${webLib.dir}" />
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${project.home.dir}/${webLib.dir}" includes="**/*.jar" />
</delete>
</target>
<!-- =================================
target: clean
================================= -->
<target name="clean" if="project.java.classes" description="Delete all complied Java source">
<echo message="Clean ${project.name} project classes dir [ ${project.java.classes} ]..." />
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${project.java.classes}" includes="**/*" />
</delete>
</target>
<!-- =================================
target: clean-dist
================================= -->
<target name="clean-dist" description="Clean the distribution folder">
<echo message="Clean distribution directory [ ${dist.dir} ]..." />
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dist.dir}" includes="**/*" />
</delete>
</target>
<!-- =================================
target: clean-all
================================= -->
<target name="clean-all" depends="clean-dist" description="Clean all">
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${basedir}/log" includes="**/*" />
<fileset dir="${basedir}/junit" includes="**/*" />
<fileset dir="${basedir}/doc" includes="**/*" />
</delete>
</target>
<!-- =================================
target: compile
================================= -->
<target name="compile" depends="init" description="Compile java source">
<echo message="Compile ${project.name} source in [${project.java.src}] ..." />
<echo message="Common DDS Jars ${DDS_COMMON}" />
<mkdir dir="${project.java.classes}" />
<javac srcdir="${project.java.src}" destdir="${project.java.classes}"
deprecation="${java.deprecation}"
debug="true" includes="**/*"
includejavaruntime="false" includeantruntime="false"
fork="true" debuglevel="lines, vars, source"
memoryinitialsize="128m" memorymaximumsize="2048m">
<classpath refid="java.classpath" />
<classpath refid="base.classpath" />
<classpath refid="websphere.classpath" />
<classpath refid="project.classpath" />
</javac>
<copypath todir="${project.java.classes}" srcdir="${project.config.dir}"
includes="${project.config.includes}" excludes="${project.config.excludes}"/>
</target>
<!-- =================================
target: jar
================================= -->
<target name="jar" depends="init, clean,copy.dds.commanjars, compile" description="Make binary distribution jar">
<echo message="Build jar [ ${project.jar.name} ] file for ${project.name} project ..." />
<echo message="Excludes file for ${project.jar.excludes} project ..." />
<echo message="Copying Spring Config files to classes dir......" />
<copy todir="${project.java.classes}/spring" failonerror="false">
<fileset dir="${project.dir}/config/spring" >
<include name="**/*.xml"/>
<include name="**/*.xsd"/>
<include name="**/*.properties"/>
</fileset>
</copy>
<echo message="Copying properties and resources from the JavaSource dir to classes dir......" />
<copy todir="${project.java.classes}" failonerror="false">
<fileset dir="${project.java.src.dir}" >
<include name="**/*.xml"/>
<include name="**/*.properties"/>
<include name="**/*.csv"/>
<include name="**/*.xsd"/>
</fileset>
</copy>
<echo message="Copying properties and resources from config dir to classes dir......" />
<copy todir="${project.java.classes}" failonerror="false">
<fileset dir="${project.dir}/config" >
<include name="**/*.xml"/>
<include name="**/*.properties"/>
</fileset>
</copy>
<jar destfile="${dist.dir}/${project.jar.name}">
<fileset dir="${project.java.classes}" includes="**/*" excludes="${project.jar.excludes}" />
<manifest>
<attribute name="Implementation-Title" value="${project.name}" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Implementation-Vendor" value="ATPCO" />
<attribute name="Class-Path" value="${project.jar.mainfest.classpath}"/>
</manifest>
</jar>
</target>
<!-- =================================
target: jar-src
================================= -->
<target name="jar-src" depends="init, jar, javadoc" description="Make project source distribution jar">
<echo message="Make source distribution jar [ ${project.jar-src.name} ] file for ${project.name} project ..." />
<zip destfile="${dist.dir}/${project.jar-src.name}">
<zipfileset dir="${doc.dir}/${project.name}" prefix="docs/api" />
<zipfileset dir="${project.dir}" includes="**/*" excludes="${project.jar-src.excludes}" />
<zipfileset dir="${dist.dir}" includes="${project.jar-src.includes}" />
</zip>
</target>
<!-- =================================
target: javadoc
================================= -->
<target name="javadoc" depends="init, compile" if="project.java.src" description="Generates JAVA API documentation">
<echo message="Generate Java doc API for project [ ${project.name} ] ..." />
<mkdir dir="${doc.dir}/${project.name}" />
<javadoc packagenames="net.atpco.*" sourcepath="${project.java.src}"
destdir="${doc.dir}/${project.name}" classpathref="compile.classpath"
version="true" use="true" author="true" doctitle="ATPCO ${project.name} API"
windowtitle="${project.name} API">
<bottom>
<i>Copyright &#169; 2012 ATPCO. All Rights Reserved.</i>
</bottom>
<tag name="TODO" scope="all" description="To do:" />
<link href="http://java.sun.com/j2se/1.4.2/docs/api/" />
</javadoc>
</target>
<!-- include all clover definitions -->
<property name="clover.jar" location="${clover.home.dir}/lib/clover.jar"/>
<taskdef resource="cloverlib.xml" classpath="${clover.jar}"/>
<target name="with.clover" if="${clover.run}">
<echo message="Priming Clover" />
<clover-setup >
<!-- <statementContext name="LOGGER" regexp="^.*LOG\..*"/> -->
<!-- <statementContext name="logger" regexp="^.*if \(LOG\.is.*"/> -->
<methodContext name="main" regexp="public static void main\(String args\[\]\).*"/>
<files>
<patternset>
<!-- <exclude name="**/*Event*.java" />
<exclude name="**/*Job*.java" />
<exclude name="**/*Service*.java" />
<exclude name="**/*DAO*.java" />
-->
<exclude name="**/*Test.java" />
<exclude name="**/*JUnit*.java" />
<exclude name="**/*Mock*.java" />
</patternset>
</files>
</clover-setup>
</target>
<!-- =================================
target: junit
================================= -->
<target name="junit" depends="with.clover" description="Run JUnit for GFS" >
<echo message="===========================================" />
<echo message="Run Junit test cases for the ${project.name} project " />
<echo message="===========================================" />
<property name="unittest.report.dir" value="${basedir}/junit/${project.name}" />
<delete dir="${unittest.report.dir}" includeEmptyDirs="true" failonerror="false"/>
<mkdir dir="${unittest.report.dir}" />
<!-- Run the JUnit test -->
<junit printsummary="yes"
showoutput="yes" fork="no" haltonfailure="no" errorproperty="test.error" failureproperty="test.error" >
<classpath refid="project.classpath" />
<classpath>
<pathelement path="${clover.jar}"/>
</classpath>
<formatter type="xml" usefile="true" />
<batchtest fork="yes" haltonfailure="no" haltonerror="no" todir="${unittest.report.dir}">
<fileset dir="${project.home.dir}/GFSTestProject/TestSource">
<include name="**/*Test*.java" />
<!--<exclude name="**/*DAO*.java"/>
<exclude name="**/*ServiceImpl.java"/>
<exclude name="**/*Listen*.java"/>
<exclude name="**/*Job*.java"/>
<exclude name="**/*Event*.java"/>
-->
<exclude name="**/*Performance*.java"/>
<exclude name="**/*Integration*.java"/>
<exclude name="**/*Transaction*.java"/>
<exclude name="**/*Concurrency*.java"/>
<exclude name="**/*POC*.java"/>
</fileset>
</batchtest>
</junit>
<!-- Run JUnit report -->
<junitreport todir="${unittest.report.dir}">
<fileset dir="${unittest.report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${unittest.report.dir}" />
</junitreport>
<fail message="Tests failed!, Check unit test reports. " if="test.error" />
</target>
<!-- =================================
target: junit
================================= -->
<target name="performancetest" description="Run JUnit performance test for GFS" >
<echo message="===========================================" />
<echo message="Run Performance test cases for the ${project.name} project " />
<echo message="===========================================" />
<property name="unittest.report.dir" value="${basedir}/junit/${project.name}" />
<delete dir="${unittest.report.dir}" includeEmptyDirs="true" failonerror="false"/>
<mkdir dir="${unittest.report.dir}" />
<!-- Run the JUnit test -->
<junit printsummary="yes"
showoutput="yes" fork="no" haltonfailure="no" errorproperty="test.error" failureproperty="test.error" >
<classpath refid="project.classpath" />
<classpath>
<pathelement path="${clover.jar}"/>
</classpath>
<formatter type="xml" usefile="true" />
<batchtest fork="yes" haltonfailure="no" haltonerror="no" todir="${unittest.report.dir}">
<fileset dir="${project.home.dir}/GFSTestProject/TestSource">
<include name="**/LucenePerformanceTest.java"/>
<exclude name="**/*Integration*.java"/>
<exclude name="**/*Transaction*.java"/>
<exclude name="**/*Concurrency*.java"/>
<exclude name="**/*POC*.java"/>
</fileset>
</batchtest>
</junit>
<fail message="Tests failed!, Check unit test reports. " if="test.error" />
</target>
<!-- =================================
target: archive
================================= -->
<target name="archive" depends="init" description="Archives all the files in the destribution folder " >
<echo message="JD Archiving"/>
<mkdir dir="${archive.dir}" />
<move todir="${archive.dir}" includeemptydirs="false">
<fileset dir="${dist.dir}" />
<mapper type="glob" from="*" to="${DSTAMP}.${TSTAMP}_*"/>
</move>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: help
- - - - - - - - - - - - - - - - - -->
<target name="usage">
<echo>
<![CDATA[
ant -Dbuild.prop=? -Dbuild.pref=? -Dbuild.target=? -Dbuild.depends={true/false}
build.prop : Build preference
build.pref : Relative path of Project preference file
build.target : Overrides configured the default target
build.depends: Build project dependencies [true/false]
targets:
clean - Delete All Complied Java Source
clean-dist- Clean the Distribution Folder
clean-all - Clean Distribution, Doc, JUnit and Log folders
compile - Compile Java Source
ear - Make Enterprise Application File
ejbdeploy - Make Deployable EJB Module
jar - Make Bin Distribution Archive File
jar-src - Make Source Distribution Archive File
javadoc - Generates JAVA API Documentation
junit - Run JUnit
war - Make Web Module
Default target: build.project
]]>
</echo>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: help
- - - - - - - - - - - - - - - - - -->
<target name="display.preference">
<property name="project.compile.path" refid="compile.classpath" />
<echo>
<![CDATA[
project.name ${project.name}
websphere.home.dir ${websphere.home.dir}
websphere.ejbdeploy ${websphere.ejbdeploy}
java.deprecation ${java.deprecation}
java.debug ${java.debug}
compile.classpath ${project.compile.path}
dist.dir ${dist.dir}
project.java.src ${project.java.src}
project.java.classes ${project.java.classes}
project.jar.name ${project.jar.name}
project.config ${project.config}
project.jar.includes ${project.jar.includes}
project.jar.excludes ${project.jar.excludes}
WAR related targets
project.war.name ${project.war.name}
project.war.webxml ${project.war.webxml}
project.webcontent ${project.webcontent}
project.war.lib.includes ${project.war.lib.includes}
project.war.lib.excludes ${project.war.lib.excludes}
project.war.mainfest.classpath ${project.war.mainfest.classpath}
EJB related preference
project.jar.descriptordir ${project.jar.descriptordir}
project.ejb.publicid ${project.ejb.publicid}
project.ejb.dtd.location ${project.ejb.dtd.location}
EAR related preference
project.ear.name ${project.ear.name}
project.ear.applicationxml ${project.ear.applicationxml}
project.ear.modules ${project.ear.modules}
project.ear.lib.include ${project.ear.lib.include}
project.dir ${project.dir}
project.ear.lib.thirdparty ${project.ear.lib.thirdparty}
]]>
</echo>
</target>
</project>
================================