A common ant template (build. XML)
Last Update:2018-07-25
Source: Internet
Author: User
Now the project is managed using ant, organizing a common ant template file, including compiling, running junit test cases, Checkstlye, from VSS, Javadoc, and so on. Hope to be useful.
<?xml version= "1.0" encoding= "gb2312"?>
<!--
This template file provides the following features:
1. Compile Java code;
2. Generate Java code corresponding to Javadoc;
3. Check the coding specification of Java code;
4. Compile and run the corresponding JUnit test code for Java code
5. Getting programs from VSS
-->
<project name= "Fog project" default= "All" basedir= "." >
<!--environment variable-->
<property environment= "env"/>
<!--set the XSL file directory for junit reporting-->
<property name= "Junit.styledir" value= "${env". Ant_home}/etc "/>
<!--source code directory-->
<property name= "Src.code" value= "src"/>
<!--source code for the JUnit directory-->
<property name= "Src.junit" value= "JUnit"/>
<!--reference Package directory-->
<property name= "Lib.dir" value= "Lib"/>
<!--target jar name-->
<property name= "Lib.jar" value= "Fog.jar"/>
<!--checkstyle configuration-->
<property name= "Checkstyle.config" value= "${lib.dir}/checkstyle33.xml"/>
<!--to set Checkstyle xsl files-->
<property name= "checkstyle.xsl" value= "${lib.dir}/checkstyle-frames.xsl"/>
<taskdef resource= "Checkstyletask.properties"
Classpath= "${lib.dir}/checkstyle-all-3.3.jar"/>
<!--VSS configuration-->
<property name= "Vss.ssdir" value= "D:/program files/vss/win32/"/>
<property name= "Vss.svrdir" value= "Z:"/>
<property name= "Vss.path" value= "/fog/implement"/>
<!--output document-->
<property name= "Doc.dir" value= "Doc"/>
<property name= "Doc.api" value= "${doc.dir}/api"/>
<!--JUnit-->
<property name= "Doc.junitreport" value= "${doc.dir}/junitreport"/>
<!--Checkstyle-->
<property name= "Doc.checkstylereport" value= "${doc.dir}/checkstylereport"/>
<!--the same as the development package structure-->
<property name= "Javadoc.package" value= "fog.*"/>
<!--output binary file-->
<property name= "Dist.root" value= "Projdist"/>
<property name= "dist.proj" value= "${dist.root}/proj"/>
<property name= "dist.classes" value= "${dist.proj}/classes"/>
<property name= "Dist.lib" value= "${dist.proj}/lib"/>
<property name= "Dist.junit" value= "${dist.root}/junit"/>
<!--classpath-->
<path id= "Classpath" >
<fileset dir= "${lib.dir}" >
<include name= "**/*.jar"/>
</fileset>
<fileset dir= "Web/web-inf/lib" >
<include name= "**/*.jar"/>
</fileset>
<fileset dir= "${dist.lib}" >
<include name= "**/*.jar"/>
</fileset>
<fileset dir= "Junit_lib" >
<include name= "**/*.jar"/>
</fileset>
</path>
<target name= "Init" >
<mkdir dir= "${doc.dir}"/>
<mkdir dir= "${dist.root}"/>
<mkdir dir= "${dist.proj}"/>
<mkdir dir= "${dist.lib}"/>
<tstamp/>
<echo message= "${tstamp}" ></echo>
</target>
<target name= "All" depends= "compilesrc, Javadoc, Checkstyle"/>
<!--compiling source files-->
<target name= "compilesrc" depends= "init" >
<mkdir dir= "${dist.classes}"/>
<javac destdir= "${dist.classes}" deprecation= "on" >
<src path= "${src.code}"/>
<classpath refid= "Classpath"/>
</javac>
<jar jarfile= "${dist.lib}/${lib.jar}" basedir= "${dist.classes}" >
<include name= "**/*.class"/>
</jar>
</target>
<!--produce Javadoc-->
<target name= "Javadoc" depends= "init" >
<mkdir dir= "${doc.api}"/>
<javadoc packagenames= "${javadoc.package}" sourcepath= "${src.code}"
Private= "yes" defaultexcludes= "yes" destdir= "${doc.dir}/api" >
<classpath refid= "Classpath"/>
</javadoc>
</target>
<!--compiling junit files-->
<target name= "Compilejunit" depends= "COMPILESRC" >
<mkdir dir= "${dist.junit}"/>
<javac destdir= "${dist.junit}" deprecation= "on" >
<src path= "${src.junit}"/>
<classpath refid= "Classpath"/>
</javac>
</target>
<!--run Checkstyle Check code specification-->
<target name= "Checkstyle" depends= "init" >
<mkdir dir= "${doc.checkstylereport}"/>
<checkstyle config= "${checkstyle.config}" >
<fileset dir= "${src.code}" includes= "**/*.java"/>
<formatter type= "plain"/>
<formatter type= "xml" tofile= "${doc.checkstylereport}/checkstyle_report.xml"/>
</checkstyle>
<style in= "${doc.checkstylereport}/checkstyle_report.xml" out= "${doc.checkstylereport}/checkstyle_report.html "Style=" ${checkstyle.xsl} "/>
</target>
<!--run JUnit-->
<target name= "JUnit" depends= "Compilejunit" >
<mkdir dir= "${doc.junitreport}"/>
<copy todir= "${dist.junit}" >
<fileset dir= "Junit_lib" >
<exclude name= "**/*.jar"/>
</fileset>
<fileset dir= "${src.code}" >
<include name= "Fog.hbm.xml"/>
</fileset>
</copy>
<junit printsummary= "yes" haltonfailure= "no" >
<classpath>
<path refid= "Classpath"/>
<pathelement location= "${dist.junit}"/>
</classpath>
<formatter type= "brief" usefile= "false"/>
<formatter type= "xml"/>
<batchtest todir= "${doc.junitreport}" >
<fileset dir= "${dist.junit}" includes= "**/*test.class"/>
</batchtest>
</junit>
<junitreport todir= "${doc.junitreport}" >
<fileset dir= "${doc.junitreport}" >
<include name= "Test*-*.xml"/>
</fileset>
<report format= "Frames" styledir= "${junit.styledir}" todir= "${doc.junitreport}"/>
</junitreport>
</target>
<!--get the latest version from VSS-->
<target name= "getversion" depends= "" >
<vssget
Vsspath= "${vss.path}" localpath= "." Login= "Codeline,codeline"
Ssdir= "${vss.ssdir}" serverpath= "${vss.svrdir}" autoresponse= "N" recursive= "true"
Quiet= "true"/>
</target>
<!--cleanup-generated classes, JUnit-related classes, document-->
<target name= "clean" >
<delete dir= "${dist.classes}"/>
<delete dir= "${dist.junit}"/>
<delete dir= "${doc.api}"/>
<delete dir= "${doc.junitreport}"/>
<delete dir= "${doc.checkstylereport}"/>
</target>
<!--clear all output results-->
<target name= "Cleanall" depends= "clean" >
<delete dir= "${doc.dir}"/>
<delete dir= "${dist.root}"/>
</target>
</project>