0

Making Your Build Files User Friendly

Posted April 10th, 2009. Filed under Code

I’m working on a build file for the Model-Glue project and want to make it as user friendly as possible.  Turns out this is very easy in Ant!

First always include a description in your build file – you can be a bit more verbose, I kept this short for the example:


<description>
Ant script to create new Model-Glue 3.0 application.
</description>

Of course if anyone edits your build file they will see the description, but we can also display this when the build file is first run. First I make my default target ‘help’:


<project name="Model-Glue" default="help" basedir=".">

Then create a ‘help’ target:


<target name="HELP" description="Displays a list of help to the user.">
<java fork="no" classname="org.apache.tools.ant.Main">
<classpath>
<fileset dir="${ant.home}\lib">
<include name="**/*.jar" />
</fileset>
</classpath>
<arg line="-projecthelp" />
</java>
</target>

This is simply running the exec task and running Ant with the ‘-p’ switch (which is short for ‘-projecthelp’ which simply prints a list of the build files targets as well as the description.  In all our other targets we’ll make sure to include a ‘description’:


<target name="build"  description="Copy Model-Glue files to new
project directory.">
<echo message="Copy Model-Glue!"/>
</target>

Now if we run our build file we’ll see something like the following output (either at the command line or in the Eclipse console:

D:\>ant
Buildfile: build.xml

help:
 [exec] Buildfile: build.xml
 [exec]
 [exec] Ant script to create new Model-Glue 3.0 application
 [exec]
 [exec] Main targets:
 [exec]
 [exec]  build  Copy Model-Glue files to new project directory.
 [exec]  help   Displays a list of help to the user.
 [exec] Default target: help

Now the user can easily determine the purpose of the build file and see a list of possible targets to run.

Possibly Related:

If you have enjoyed this entry. Please feel free to bookmark it using your favorite social bookmarking site

Leave a Comment