Thursday, September 29, 2011

Ant Code Katas

Building upon my last blog entry on the application of Katas on improving my programming, I applied this concept to the Apache Ant build system for Java. Although not my first time messing around with a build system, this is by far the most complex I've encountered. Similar to the Make utility found on most Unix-based operating systems, the Apache Ant build system automatically builds executable programs from source code and libraries.

For this particular build system, I worked on the following katas:

1. Ant Hello World
2. Ant Immutable Properties
3. Ant Dependencies
4. Hello Ant Compilation
5. Hello Ant Execution
6. Hello Ant Documentation
7. Cleaning Hello Ant
8. Packaging Hello Ant

Sparing the details for each kata (you can read about them here), each kata gets more difficult along the way. Funny enough, learning how to print words to the screen in Ant took a bit longer than expected. Unlike a programming language, it seems like the first thing the authors of a build system would like you to do is to actually use their program to build a system. I knew I had to enclose the "echo" task around what I wanted to print to the screen but to actually set up the script to do this took longer than expected. A quick Google searched revealed resources on how to do exactly this.

Next, completing the immutability and dependency scripts were pretty painless since the Wikibooks website also provided a good tutorial on those two concepts, however, I would soon hit a brick wall with the next three scripts. Out of the three, compilation wasn't too bad since the Ant manual provides a good basis on how to do this. On the execution script I would later find out the pain in trying to run a Java program using Ant. During this time I've probably went back-and-forth a few times deciding whether to follow the Apache model and JAR my HelloWorld program and execute the the JAR, or to simply find a way to execute the program without having to do this step. Finally, I found the documentation script to be a little simpler since I only had to be concerned with the location of the source files and the directory where I want to store the Javadoc reference files. Luckily, I had no problems with the clean and distribution scripts since I found the sample scripts from another build system distribution straightforward.

With these code katas I was able to dive a little deeper with just how complex build systems can get pass the compilation and execution stages. With the headaches I've encountered when trying to run other peoples Java implementations on my computer, it is clear how useful and in my case necessary to have a robust build system to accompany any software system.

No comments:

Post a Comment