A build system is OS independent, meant to ease the sharing of programs and setups. You can set it to download all required libraries and file systems automatically, which is very attractive since most people just like to click on something and be done with it. In particular, I practiced some more katas with the Ant System (the most popular build system for java) The programming was all done in XML which was really different for me and the way things were done required a shift in how I usually think. For example, rather than "variables" you have properties which just have a certain value. And then you can check if the property exists rather than if it equals something or other. Also, the other big thing was recycling code. I usually try to get all my includes up at one point but for the build system, I found myself including everything that may be relevant every single time. This is because someone using the build system may want only a certain part and if they take it all, then ANT will remember that it used something already and won't waste time repeating itself. It was really an interesting experience and looking at the API, it seems that there are a lot of possibilities for complex code.
The katas themselves weren't too much trouble, but small things messed me up. If I didn't structure my files the right way, it would produce errors. And as with any new programming language, at first I didn't know how to do anything. Even making a zip of the directory you're currently in gave me trouble! But as I continued writing the katas, things started to slowly come more easily to me proving once again how useful the things can be.
Ant is definitely something I'll be using in the future and learning more about. If anyone is interested, here are the katas I followed:
1. Ant Hello World
Create a script called helloworld.build.xml. Invoking this script via "ant -f helloworld.build.xml" should print out "Hello World". The script consists of a single (default) target called helloworld with a single line that invokes the <echo> task to print out Hello World.
2. Ant Immutable Properties
Create a script called immutable.build.xml. This script contains two <property> elements, one of which assigns the property "my.property" to the value "1" and the second of which assigns the (same) property "my.property" to the value "2". Now create a target called "printproperty" that uses the <echo> task to print out the value of the property "my.property".
If done correctly, this script demonstrates that build properties are immutable: once they are set, their value cannot be changed.
3. Ant Dependencies
Create a script called dependencies.build.xml. It should contain targets called "foo", "bar", "baz", "qux", and "elmo". Each target should consist of a single <echo> task that prints out the name of its target. The default target is foo.
The targets should have the following dependencies:
- foo should depend upon bar.
- bar should depend upon baz and elmo in that order.
- baz depends upon qux.
- qux depends upon elmo.
- elmo has no dependencies.
Now invoke the build script using "ant -f dependencies.build.xml". What is the order of targets. In particular, where is elmo called and why? A popular midterm question is to give a sample build script similar to this one and ask you to show the output, so you should be able to predict the way in which dependencies are resolved.
Try invoking "ant -verbose -f dependencies.build.xml". Note that Ant now tells you how it seriallzed the dependency structure.
Now make elmo depend upon bar and reinvoke the script. Make sure you understand what happens.
4. Hello Ant Compilation
Create a file called HelloAnt.java, which contains a Java class called "HelloAnt" and a main method that prints out "Hello Ant" to the console. This file should be in a src/ subdirectory.
Create a second file called compile.helloant.build.xml that contains a single target called "compile". This target contains a single <javac> task that compiles the HelloAnt program. You do not need Ivy. You should be able to compile the program with "ant -f compile.helloant.build.xml". These class files should be written to a build/classes subdirectory.
Create a second file called compile.helloant.build.xml that contains a single target called "compile". This target contains a single <javac> task that compiles the HelloAnt program. You do not need Ivy. You should be able to compile the program with "ant -f compile.helloant.build.xml". These class files should be written to a build/classes subdirectory.
You may want to create src.dir and build.dir properties.
5. Hello Ant Execution
Create a file called run.helloant.build.xml that compiles and runs the HelloAnt program. It should use the <import> task to import the contents of compile.helloant.build.xml so you have access to those targets.
Create a file called run.helloant.build.xml that compiles and runs the HelloAnt program. It should use the <import> task to import the contents of compile.helloant.build.xml so you have access to those targets.
Again, make this file as simple as possible. Provide a single target called "run", and make this "run" target depend upon the "compile" imported target so that the code is always compiled before being run. You should be able to compile and run the program with "ant -f run.helloant.build.xml".
6. Hello Ant Documentation
Create a file called javadoc.helloant.build.xml that generates the JavaDocs for the HelloAnt program. Once again, make this file as simple as possible; it can contain a single target called "javadoc" that invokes the <javadoc> task.
The javadoc target should ensure that the HelloAnt program compiles, so you will want to import compile.helloant.build.xml The javadoc html files should be placed in the build/javadoc subdirectory. You should be able to generate the JavaDocs with "ant -f javadoc.helloant.build.xml".
You can create a few properties to support the documentation process if you like. You must ensure that the javadoc command completes without any warnings or errors. This means you might have to improve your HelloAnt program!
7. Cleaning Hello Ant
Add a target called "clean" to your compile.helloant.build.xml file. It should delete the build/ directory.
8. Packaging Hello Ant
Create a file called dist.helloant.build.xml. It should contain a single target called "dist". The dist target should have dependencies that compile, execute, and create javadocs for the helloant system (thus checking to make sure the system works correctly). After all of these dependencies should be the clean dependency.
The contents of the dist target creates a zip file containing the (cleaned) version of the current directory and all its subdirectories. This zip file should be put into the (newly created) build/dist directory. Its name should be ant-code-katas-<username>.zip, where <username> is your hawaii.edu account name. Unzipping this file should create a new directory called "ant-code-katas-<username>" which contains your ant kata files.
To check your work, invoke "ant -f dist.helloant.build.xml". Now cd to the build/dist directory, invoke "jar -xf ant-code-katas-<username>.zip". This should create a new directory in build/dist called "ant-code-katas-<username>. Now cd into that directory, and make sure that all of your kata files (and the src/ directory) are there, but that the build/ directory is not there. Finally, invoke "ant -f dist.helloant.build.xml" in this directory. It should create a new build/dist directory containing yet another copy of ant-code-katas-<username>.