Presentation is loading. Please wait.

Presentation is loading. Please wait.

Apache Ant A gateway to test-driven Java development.

Similar presentations


Presentation on theme: "Apache Ant A gateway to test-driven Java development."— 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 Multiple build targets per project

6 Projects have Properties Properties are immutable Properties: Environmental Variable Prefix: Dereferncing env vars: Load properties from Java property files:

7 Projects use Paths Classpaths, File paths and arbituary sets of files using filters can be described using path tags.

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

9 Advanced Conditionals

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 3 rd 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, Ant reads./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 Targets can call targets in the same file using dependency or explictly using Break out different subprojects into different files Call other files using

14 An Example build.xml <echo message="Please specify a target. Example: build (core|clean)"/> <property name="TOOLS_DIR“ value="${env.IMPL_HOME}/admin/tools"/>

15 Product.xml: invoking javac <javac destdir="${CLASSDIR}" srcdir="${PRODUCTSOURCEDIR}" includes="**"> <property name="jarfile“ value="${LIBDIR}/${PRODUCT}_core.jar"/>

16 Next: Ant and Test-Driven Development

17 Extending Ant Tasks extend the class org.apache.tools.ant.Task –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"> <pathelement location="${integration.test.jar}"/>

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}" /> 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


Download ppt "Apache Ant A gateway to test-driven Java development."

Similar presentations


Ads by Google