Live and Learn – ant
Resources Ant User Manual Skip the book, most of the material is right here Apache Ant 101 – DeveloperWorks ibm.com/developerworks/edu/j-dw-java- apant-i.html ibm.com/developerworks/edu/j-dw-java- apant-i.html Totally righteous tutorial
Questions from Live and Learn 1.What is the basic structure of an Ant file? 2.What's required and what's optional? 3.What is the difference between build.xml and build.properties? 4.What is the advantages/disadvantages of defining properties in build.properties instead of build.xml? 5.How do I create and destroy directories? 6.How do I define projects to run using Ant? 7.Other hints and suggestions from an expert? 8.How to do junit tasks? 9.How to do task dependencies (don't compile unless fetch got stuff)
Basic structure Entities: Project Targets Tasks Types Project contains tasks, which contain targets and types Implicit target contains all “top-level” targets and types is executed each time ant is invoked, even for -projecthelp
Minimal file
Sample file (unreadable) A simple Java project
Sample file (part 1) A simple Java project
Sample file (part 2) <jar destfile="${distDir}/package-${DSTAMP}.jar" basedir="${buildDir}"> <jar destfile="${distDir}/package-src-${DSTAMP}.jar“ basedir="${srcDir}"/>
Properties Write-once! From command line: ant -D key=value Built-in: basedir, ant.file, ant.version, ant.project.name, ant.java.version Java System properties /System.html#getProperties() /System.html#getProperties() From the Property task
Property task explicitly stated: pulled from a file: Java-style properties file syntax. pulled from the environment: also URL or Resource
Example from ExpertVoices <fail unless="env.EV_CONFIG" message="Environment variable 'EV_CONFIG' is not set"/> <property name="config_property_file“ location="properties/${env.EV_CONFIG}.build.properties"/> <available file="${config_property_file}" type="file“ property="config_property_file_present"/> <fail unless="config_property_file_present“ message="Property file '${config_property_file}' missing"/> <property name="common_property_file“ location="properties/_common.build.properties"/>
File Set Inline: By reference:
Pattern Set Inline or by reference
Path-like structures -simple
Path-like structures - complex
Other types Selectors Selectors are a mechanism whereby the files that make up a fileset can be selected based on criteria other than filename. Filtersets <copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt">
Optional tasks Require libraries that are not supplied with Ant Put them in Ant’s lib directory, or add to the system classpath
Optional tasks - gotchas from Note: You must have junit.jar and the class files for the task in the same classpath. You can do one of: Put both junit.jar and the optional tasks jar file in ANT_HOME/lib. Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable. Do neither of the above, and instead, specify their locations using a element in the build file. See the FAQ for details.the FAQ
If – Then – Else THEN BODY EXECUTED ELSE BODY EXECUTED
“Subroutines” with parameters <param name="extensions_dir" value="${third_party_themes_dir}"/> <param name="destination_dir“ value="${build_wpmu_themes_dir}"/>
Loops <foreach target="unzip_extension" param="zip_file" inheritall="Yes">