Tuesday, September 29, 2009

Using Software Tools. Less Grunt Work.

This week I had my first experience with Ant a software tool developed by Apache to help with the software build process. It has sub-processes that checks for syntax errors, errors in run time, and also makes sure your source code is up to Java coding standards. The initial learning curve is not that steep. I think with a little determination, most programmers can be comfortable with this tool in a short time. This tool was used for my robocode robot and it helped to check my source code. There are quite a few things that Ant does with just a simple command typed into the command line. I will detail the requirements for installation and also how to use Ant.

Ant is a open source software available at (http://ant.apache.org/). I found it somewhat difficult to set up on my computer particularly because there are not a lot guides that give you a step by step explanation of the process. Most of the sites I visited showed guides that were inadequate. Here is my take on how to set it up on a windows vista HP Laptop.

1. Download Ant and unzip. Move it to the C:/ directory. Or try to move the Ant file to a directory that has no spaces in the name. It can be problematic later on.

2. Now click start, right-click computer, and click properties. If you are running on a Vista OS, then you should see a window opened. Click on "advanced system settings" under Task on the left side.

3. Click on Environmental Settings. This is where you will enter two variables.

4. The first variable will be called JAVA_HOME. Under the variable value, enter the system path that leads to your latest sdk version of Java. For example, this my path. C:\Program Files\Java\jdk1.6.0_16.

5. The second variable will be called ANT_HOME. The variable value of this variable will contain the path to the same directory as the above variable. So just enter the same thing.

6. Now open dos. Go to the directory which contains your build.xml and type ant.

Those are the basic steps to setting up Ant and checking if it works. There are many utilities within Ant that are quite helpful.
  • ant
  • ant -f checkstyle.build.xml
  • ant -f junit.build.xml
  • ant -f findbugs.build.xml
  • ant -f pmd.build.xml
  • ant -f jar.build.xml
  • ant -f verify.build.xml
  • ant -f dist.build.xml
Each one has their use. Checkstyle and findbug for example check for irregularities in your code and byte code. While jar and dist on the other hand are used to package your source code. And verify is the special command that does it all. It pretty much does everything on the list.

On this occasion Ant was used to improve my source code for Bato, a robocode robot created about two weeks ago. I made some improvements on the movement of Bato and after compiling it, I used the commands checkstyle, pmd and findbugs. I was surprised that there were many errors. I mean it compiled didn't it? What could be wrong?

It turns out that there were some small coding standard violations, like leaving no white space between a while declaration and the "{" bracket. Another problem was declaring a variable and not using it. Findbugs made sure I changed it before letting me get a "Build successful."

Finally after going through that, I used the verify command to make sure I was able to get a successful build as well. Verify is the command in which you can use to check if everything has been done.

In terms of quality assurance, I found the program to be quite helpful. I didn't even know about some of the errors that checkstyle and findbugs found. It drastically shortened my work time. The one complaint I have about some these programs were how they alerted you to an error. The messages were kind of ambiguous and not very helpful. It took me awhile to figure out what was wrong with my code.

JUnit is plugin that tests your program in order to make sure that your program works in all cases. This was the most difficult of the programs to learn. I found that JUnit can be helpful and downright essential if you want to know what works and what doesn't.

This is a good tool to have for programmers. It makes things so much easier during the entire coding process and generally makes a better experience for users.

Check out my robot source code here along with the build files.

Update
I've revised my package

(robocode-wcm-Bato-1.1.1003)

No comments:

Post a Comment