SE450: Ant: A concrete example [23/41] ![]() ![]() ![]() |
An example build file (that built the solution to Homework 1!)
<?xml version="1.0"?> <project name="se450" basedir="." default="compile"> <!-- the classpath used for various tasks in the build process --> <path id="project.classpath"> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> <pathelement location="." /> <pathelement location="build" /> </path> <!-- ================================================== --> <!-- Target: init --> <!-- Sets properties, creates needed directories --> <!-- ================================================== --> <target name="init"> <!-- put name=value pairs in this file to override --> <!-- the properties below --> <property file="ant.properties" /> <property name="apidoc" value="docs" /> <property name="src" value="src" /> <property name="build" value="build" /> <property name="submission" value="submission" /> <property name="test" value="test" /> <property name="testresults" value="testresults" /> <property name="instrument" value="instr" /> <property name="repository" value="rep" /> <property name="instrbuild" value="instrbld" /> <!-- used in making submission file --> <property name="homework" value="hw1" /> <mkdir dir="${build}" /> <mkdir dir="${submission}" /> <mkdir dir="${testresults}" /> </target> <!-- ================================================== --> <!-- Target: compile --> <!-- Compiles all the source code --> <!-- ================================================== --> <target name="compile" depends="init"> <!-- Both srcdir and destdir should be package roots. --> <javac srcdir="${src}" destdir="${build}" debug="true" deprecation="true"> <classpath> <path refid="project.classpath" /> </classpath> <!-- To exclude some files: --> <!-- <exclude name="com/foo/SomeFile.java"/> <exclude name="com/foo/somepackage/"/> --> </javac> </target> <!-- ================================================== --> <!-- Target: zip --> <!-- Makes a submission zip file for the grader --> <!-- ================================================== --> <target name="zip" depends="init,compile"> <copy todir="${submission}" > <fileset dir="${src}"> <include name="**/${homework}/*.java" /> </fileset> <fileset dir="${test}"> <include name="**/${homework}/*.java" /> </fileset> <fileset dir="."> <include name="grader.txt" /> </fileset> </copy> <zip zipfile="${submission}/submission.zip" compress="true" basedir="${submission}"> <include name="**/*.java" /> <include name="grader.txt" /> <exclude name="**/*.class"/> <exclude name="**/*.jar" /> </zip> </target> <!-- ================================================== --> <!-- Target: compiletests --> <!-- Compiles all the test source --> <!-- ================================================== --> <target name="compiletests" depends="init"> <!-- Both srcdir and destdir should be package roots. --> <javac srcdir="${test}" destdir="${build}" debug="true" deprecation="true"> <classpath> <path refid="project.classpath" /> </classpath> <include name="se450/**/*Test.java"/> </javac> </target> <!-- ================================================== --> <!-- Target: test --> <!-- Runs a unit test. Add or remove test lines --> <!-- to run more tests. --> <!-- ================================================== --> <target name="test" depends="compiletests,compile" description="Run Unit Test" > <junit printsummary="withOutAndErr" fork="yes"> <classpath> <path refid="project.classpath" /> </classpath> <formatter type="plain" /> <test name="se450.student.hw4.CourseTest" todir="${testresults}" /> </junit> </target> <!-- ================================================== --> <!-- Target: alltests --> <!-- Runs all the unit tests. --> <!-- ================================================== --> <target name="alltests" depends="compiletests,compile" description="Run All Unit Tests" > <junit printsummary="withOutAndErr" fork="yes" haltonfailure="yes"> <classpath> <path refid="project.classpath" /> </classpath> <formatter type="plain" /> <batchtest fork="yes" todir="${testresults}"> <fileset dir="${test}"> <include name="**/*Test*.java" /> <exclude name="**/AllTests.java" /> </fileset> </batchtest> </junit> </target> <!-- ================================================== --> <!-- Target: all --> <!-- Compiles and builds the submission file --> <!-- ================================================== --> <target name="all" depends="init,zip" description="Build everything."> <echo message="Homework built. Submission zip is in ${submission}" /> </target> <!-- ================================================== --> <!-- Target: javadoc --> <!-- Makes javadoc of the source code --> <!-- ================================================== --> <target name="javadoc" depends="init" description="Javadoc for my API."> <mkdir dir="${apidoc}"/> <javadoc packagenames="se450.*" destdir="${apidoc}" > <sourcepath> <pathelement location="${src}"/> </sourcepath> </javadoc> </target> <!-- ================================================== --> <!-- Target: clean --> <!-- Cleans up the build artifacts --> <!-- ================================================== --> <target name="clean" depends="init" description="Clean up class, test result files"> <delete dir="${build}" /> <delete dir="${testresult}" /> <delete dir="${submission}" /> </target> </project>