Tapestry Training -- From The Source

Let me help you get your team up to speed in Tapestry ... fast. Visit howardlewisship.com for details on training, mentoring and support!

Thursday, May 20, 2004

Maven-like downloads for Ant

One of the key features of Maven that I like is that it will download dependencies for you automatically.

I'm just starting to convert HiveMind from Maven back to Ant and this was very hard to do. I want to download a file, just if it doesn't exist locally (or is out of date), compute the MD5 sum while it downloads, and compare that to an MD5 sum stored on the server.

There was an existing project, greedo that may have done some or all of that ... but it has stalled in that "nearly-done" open source state so many projects reach. No activity in the last nine months. Broken home page. No documentation. I got it to build, but I had to hack their broken Ant build files. Also, I think the <macrodef> features of Ant 1.6 trumps a lot of the functionality in greedo, and I wanted more flexibility with respect to where I get files and how they are stored.

Anyway, I took a peek at the existing Get task of Ant and created a Grabber task. That's a start and it will be necessary in order to build HiveMind in the future. For the moment, it is available as http://howardlewisship.com/downloads/AntGrab.zip. This includes source and a JAR, ant-grabber.jar, that must be placed in ANT_HOME/lib.

A request has come in to discuss how it is used. Now, Grabber is super-alpha, but here's a portion of my Ant-based build environment to demonstrate how it is used:

	<available classname="org.apache.ant.grabber.Grabber" property="grabber-task-available"/>
	<fail unless="grabber-task-available" message="Grab task (from ant-grabber.jar) not on Ant classpath."/>
	
	<taskdef classname="org.apache.ant.grabber.Grabber" name="grabber"/>

	<!-- macro for downloading a JAR from maven's repository on ibiblio. -->
	
	<macrodef name="download-from-ibiblio">
		<attribute name="jar" description="The name of the JAR to download."/>
		<attribute name="group-id" description="The Maven group-id containing the JAR."/>
		
		<sequential>
			<mkdir dir="${external.lib.dir}"/>

			<grabber
				dest="${external.lib.dir}/@{jar}"
				src="${maven.ibiblio.url}/@{group-id}/jars/@{jar}" 
				md5="${maven.ibiblio.url}/@{group-id}/jars/@{jar}.md5"
				/>


		</sequential>
	</macrodef>

Later I use the macro as follows:

		<download-from-ibiblio jar="commons-logging-1.0.3.jar" group-id="commons-logging"/>
		<download-from-ibiblio jar="javassist-2.6.jar" group-id="jboss"/>
		<download-from-ibiblio jar="xml-apis-1.0.b2.jar" group-id="xml-apis"/>
		<download-from-ibiblio jar="servletapi-2.3.jar" group-id="servletapi"/>
		<download-from-ibiblio jar="werkz-1.0-beta-10.jar" group-id="werkz"/>
		<download-from-ibiblio jar="oro-2.0.6.jar" group-id="oro"/>
		<download-from-ibiblio jar="easymock-1.1.jar" group-id="easymock"/>
		<download-from-ibiblio jar="log4j-1.2.7.jar" group-id="log4j"/>

3 comments:

Matt Raible said...

Hmmm, any documentation or sample XML on how you're using it?

Brett Porter said...

Howard, any reason you are switching back to Ant? We haven't heard from you on the Maven lists for a while.

Unknown said...

The Maven team now has official Ant tasks for accessing files within Maven repositories.