Use Ant to Maintain Custom Framework Builds

2008 May 18
by Paul Marcotte
I'm pretty new to Ant, so I'm thankful that a lot of other developers have examples and sample build files that I can use as a guide to learning Ant. After writing a few small build files, I wanted to tackle something a little more ambitious. I like to keep all the frameworks that I use up to date from their respective repositories, and, when deploying a new site or project, I will typically include the framework dependencies as a minimal include at the project root. This requires a bit of work, exporting and stripping out documentation, examples and tests from my local checkout of the framework files. As a learning objective, I decided to write an ant build file to maintain my own "nightly build" of each framework customized to carry only the core files.I'm going to assume that anyone interested in this post will already have all the necessary dependencies. Which are: Ant
A CVS command line client
SVNAnt On OS X, the simplest way to get a CVS client is to install the Apple Developer Tools. There are plenty of guides available to install and setup ant and svnant, so I won't re-hash them here. For the first cut of this build file, I chose to setup tasks to export ModelGlue, MachII, Coldspring, Transfer and Coldbox. The process is to export the core files to a temp directory, then copy the files to a location where I will point the Coldfusion Administrator to create mappings to each framework. Here are the properties and build files respectively.
# ant lib path and svn ant jars
lib.dir=/usr/local/ant/lib
svnant.jar=${lib.dir}/svnant.jar
svnClientAdapter.jar=${lib.dir}/svnClientAdapter.jar
svnjavahl.jar=${lib.dir}/svnjavahl.jar


#local props

tempdir=/Users/paul/tmp/export

targetdir=/Users/paul/src/frameworks


# MachII
mach-ii.svn=http://greatbiztoolsllc-svn.cvsdude.com/mach-ii/framework/1-6-0/trunk

#model-glue
model-glue.svn=http://svn.model-glue.com/trunk/ModelGlue

#coldbox
coldbox.svn=http://ortus.svnrepository.com/svn/coldbox/coldbox/trunk/src/system
coldbox.username=nightlybuild
coldbox.password=nightlybuild

#transfer
transfer.svn=http://svn.riaforge.org/transfer/trunk/transfer


#coldspring
coldspring.cvs=:pserver:anoncvs@cvs.coldspringframework.org:
coldspring.repo=/coldspring
coldspring.module=coldspring
coldspring.username=anoncvs
coldspring.password=anoncvs
<?xml version="1.0"?>
<project name="svn-test" basedir="." default="exportFrameworks">

<!-- all properties are in frameworks.properties -->
<property file="frameworks.properties" />


<!-- path to the svnant libraries. Usually they will be located in ANT_HOME/lib -->
<path id="project.classpath">
<pathelement location="${svnjavahl.jar}" />
<pathelement location="${svnant.jar}" />
<pathelement location="${svnClientAdapter.jar}" />
</path>

<!-- load the svn task -->
<taskdef resource="svntask.properties" classpathref="project.classpath"/>


<!-- model glue export -->
<target name="exportModelGlue">
<svn >
<export srcUrl="${model-glue.svn}" revision="HEAD" destPath="${tempdir}/ModelGlue" />
</svn>
</target>

<!-- mach-ii export -->
<target name="exportMachII">
<svn >
<export srcUrl="${mach-ii.svn}" revision="HEAD" destPath="${tempdir}/MachII" />
</svn>
</target>

<!-- transfer export -->
<target name="exportTransfer">
<svn >
<export srcUrl="${transfer.svn}" revision="HEAD" destPath="${tempdir}/transfer" />
</svn>
</target>

<!-- coldbox export -->
<target name="exportColdbox">
<svn username="${coldbox.username}" password="${coldbox.password}">
<export srcUrl="${coldbox.svn}" revision="HEAD" destPath="${tempdir}/coldbox/system" />
</svn>
</target>

<!-- coldspring export -->
<target name="exportColdSpring">
<cvspass cvsroot="${coldspring.cvs}${coldspring.repo}"
password="${coldspring.password}"
/>
<cvs
command="export -DNOW ${coldspring.module}"
cvsRoot="${coldspring.cvs}${coldspring.repo}"
package="${coldspring.module}"
dest="${tempdir}"
/>

</target>

<!-- list of export tasks -->
<target name="export" depends="exportModelGlue,exportMachII,exportColdbox,exportTransfer,exportColdSpring" />

<!-- copy task - -->
<target name="copy">
<mkdir dir="${targetdir}" />
<copy todir="${targetdir}">
<fileset dir="${tempdir}">
<exclude name="**/coldspring/docs/**" />
<exclude name="**/coldspring//examples/**" />
<exclude name="**/coldspring//tests/**" />
<exclude name="**/coldspring//unitTests/**" />
</fileset>
</copy>
</target>

<!-- clean task - remove temp dir -->
<target name="clean">
<delete dir="${tempdir}"/>
</target>

<!-- default task -->
<target name="exportFrameworks" depends="clean,export,copy">
<echo message="frameworks updated" />
</target>

</project>
If you are like me and prefer to keep the frameworks that you use up to date and lean, I hope you find this useful.