1 / 24

Apache Ant

Apache Ant. A gateway to test-driven Java development. What is Ant?. Ant is an Apache Jakarta project It’s a build system, intended to replace Make It’s written in Java, intended for Java Ant project files are XML Ant leverages XML document features such as ELEMENT references

caraf
Download Presentation

Apache Ant

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Apache Ant A gateway to test-driven Java development.

  2. What is Ant? Ant is an Apache Jakarta project It’s a build system, intended to replace Make It’s written in Java, intended for Java Ant project files are XML Ant leverages XML document features such as ELEMENT references Ant directives are Tags It’s extensible—you can create your own tags.

  3. Alternatives to Ant • IDE provided projects • typically closed format • Make • has a tricky file format ;-) • Make can only be extended using shell scripts or other executables • Shell scripting • cannot be extended • Both are slower to build Java

  4. Some Ant Tags • Checksum, chmod, concat, copy, delete, filter, FixCRLF, get, mkdir, move, patch • Bzip2, cab, Ear, gzip, jar, Rpm, Jlink, SignJar, tar, war, zip • Depend, javac, JspC, RmiC, WljspC • ServerDeploy, Javadoc, EJB • Exec, Java, Parallel, Sequential, Sleep, Waitfor • Echo, mail, sql, taskdef, tstamp, ftp, telnet • Cvs, ClearCase, VSS • Junit, Testlet

  5. Ant Project Files • One ant project per file • <project/> • Multiple build targets per project • <target/>

  6. Projects have Properties • Properties are immutable • Properties: <property name=“” value=“”/> • Environmental Variable Prefix: <property environment=“env”/> • Dereferncing env vars: <echo message=“Shell path: ${env.PATH}”/> • Load properties from Java property files: <property file=“build.properties”/>

  7. Projects use Paths • Classpaths, File paths and arbituary sets of files using filters can be described using path tags. <path id=“beagle”> <pathelement path="${classpath}"/> <pathelement location="lib/helper.jar"/> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> </path> <javac> <classpath refid=“beagle”/> </javac>

  8. Targets can be conditional • Targets execute conditionally using the “if” or “unless” attributes <target name="build-oracle" if=“env.BUILD_ORACLE"/> <target name=“build-psql" unless=“env.SKIP_PSQL"/>

  9. Advanced Conditionals <target name="cond" depends="cond-if,cond-else"/> <target name="check-cond"> <condition property="cond-is-true"> <and><not> <equals arg1="${prop1}" arg2="$${prop1}"/> </not> <not><equals arg1="${prop2}" arg2="$${prop2}"/> </not> <equals arg1="${prop3}" arg2="$${prop3}"/> </and> </condition> </target> <target name="cond-if" depends="check-cond" if="cond-is-true"> <echo message="yes"/> </target> <target name="cond-else" depends="check-cond" unless="cond-is-true"> <echo message="no"/> </target>

  10. Next: installing and using Ant

  11. Installing and Caring for Ant • Download from jakarta.apache.org/ant • Requires Java 2 (?) • Extract to /usr/local/ or… • Manage Ant as 3rd party library • managed in source control • prepare for new releases of Ant • Manage Ant Scripts in source control! • Prepare to branch your build scripts for new versions of Ant

  12. Runing Ant • By default, Antreads ./build.xml • define an $ANT_HOME in your .bashrc • Call indirectly from a shell alias: • Do alias Build=“$DEV/build.sh” where • build.sh sets env variables • Finally calls $ANT_HOME/bin/ant

  13. Ant Project Files • build.xml is the default “project” file where you define you build targets • Define a build target using <target name=“” depends=“”/> • Targets can call targets in the same file using dependency or explictly using <antcall target=“”/> • Break out different subprojects into different files • Call other files using <ant antfile=“” dir=“” target=“”/>

  14. An Example build.xml <project default="usage" basedir="."> <target name="usage"> <echo message="Please specify a target. Example: build (core|clean)"/> </target> <target name="init"> <property environment="env"/> <property name="TOOLS_DIR“ value="${env.IMPL_HOME}/admin/tools"/> <property file=“build.properties”/> </target> <target name=“core" depends=“init,clean"> <ant file="product.xml"/> </target> <target name="clean"> <delete dir=“${env.IMPL_HOME}/tmp/classes”/> </target> </project>

  15. Product.xml: invoking javac <project default="jar_product"> <target name="core"> <javac destdir="${CLASSDIR}" srcdir="${PRODUCTSOURCEDIR}" includes="**"> <classpath> <pathelement path="${CLASSDIR}"/> <fileset dir="${LIBDIR}"> <include name="**/*.jar"/> </fileset> </classpath> </javac> </target> <target name="jar_product" depends="core"> <property name="jarfile“ value="${LIBDIR}/${PRODUCT}_core.jar"/> <jar jarfile="${jarfile}" basedir="${CLASSDIR}"/> </target> </project>

  16. Next:Ant and Test-Driven Development

  17. Extending Ant • Tasks extend the class org.apache.tools.ant.Task • <Taskdef> • Makes new tag classes visible to Ant • Support for writing nested tags • Sophisticated tasks

  18. Extensibility provides 3p tag libraries • Existing libraries for: • testing • source control • Project deployment

  19. 3p lib: Junit <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes"> <classpath> <pathelement location="${integration.test.jar}"/> </classpath> <test name=“gov.irs.TestApplicantPainThreshold"/> </junit>

  20. 3p lib: Cactus • Useful for in-container web-application testing <runservertests testURL="http://localhost/${PRODUCT}/“ startTarget="start_container“ stopTarget="stop_container“ testTarget="test-classes"/> • StartTarget – starts container • StopTarget – container shutdown • TestTarget – like Junit test block • HTTPUnit compliments cactus by testing entirely outside the container

  21. Core lib: CVS tags <cvs cvsRoot=":pserver:user@192.168.0.1:/cvsroot" package="jakarta-ant" dest="${ws.dir}" /> <cvs command="update -A -d"/> • Invoke to get latest before a build • Invoke to tag working builds upon successful test execution

  22. Test-Driven Development • Kent Beck, Extreme Programming (XP) and continuous integration • Continuous integration involves validating implementation with automated tests • Run tests with every build • Write the tests before coding the feature • Write tests for multiple levels of the architecture • Automated deployment follows passed tests • Ant provides a framework for automating the build, testing, source control and deployment tasks

  23. Test-Driven Development Tools • Junit Ant tags • used for class-level tests • Cactus library • Servlet-container testing • CVS Ant tag • update source tree upon passing tests • Cruise Control – integrates these tasks • Scans your source-control repository periodically • Starts build upon detecting updates • test-failure reports posted to status web page

  24. Conclusion • Improves Java project build times • Supports large and modular projects • Conditional compilation of components • Tag libraries easily extend Ants utility • Automating build, testing and source-control tasks accelerate the build cycle

More Related