This is going to be another short series (2-3 posts) about a build automation tool. I got using this during my internship at WaveNET. I don’t this this is going to be a very useful post to many ( I here some one saying when I write useful posts 🙂 ), but it could be at least a reference for some one out there or to me some day.
Introduction
Luntbuild is a powerful build automation and management tool. Continuous Integration or nightly builds can be easily set using a clean web interface. Executed builds are well managed using functions such as search, categorization, promotion, patching, deletion, etc. It also acts as a central build artifacts repository and download area for your whole team.
Why Luntbuild?
You may ask why Luntbuild, while there are already many good build automation tools such as Cruise Control, Anthill, and others. Our answer is:
Luntbuild aims at not only being build automation, but also build management system. Executed builds can be categorized, promoted, searched, patched, deleted, etc. This is very important for a nightly builds or Continuous Integration builds, which generate many builds over time.
Luntbuild utilizes the project/schedule concept to easily provide build support for parallel development.
No configuration files, all jobs are done using web interface. You can set your Luntbuild system in less than thirty minutes.
Luntbuild makes advantage of quite a few open source libraries and frameworks listed here.
Basic unit of work in Luntbuild is a build. Build execution is triggered either by a schedule or it can be started manually. A build in Luntbuild performs following steps:
Checks out source code from the Version Control System(s) (VCS).
Labels the current source code based on the current build version.
Runs an Ant/Maven/Command/Rake build script in the source tree.
Runs an Ant/Maven/Command/Rake post build script in the source tree.
Publishes the build log and other build artifacts.
Build configuration, monitoring, and access to the build artifacts are all done using an intuitive web interface. Development and testing teams will have a central area to access the build information.
We shall see basic installation steps in the next post.
This is the final part of the so called Ant series I have been writing in this blog, about Apache Ant. This is an extremely brief tutorial on JUnit. The goal is to test Ant and JUnit framework integration .
First, we need a Java class to test. I had to make this example too simple according to my Java knowledge. This lacks any Java Docs or comments, but it's a pretty simple bit of code. 🙂
public class Math { static public int add(int a, int b) { return a + b; }
static public int multiply ( int a, int b) { return a * b; } }
Then to test this code, we need a second Java class that will
import junit.framework.*
extend TestCase
There are two important points to note in the sample. First, the routine is named testAdd. This convention tells that the routine is supposed to be a test and that it's targeting the add functionality. Here's the matching example.
import junit.framework.*;
public class TestMath extends TestCase {
protected void setUp() { // put common setup code in here }
protected void tearDown() { // put common cleanup code in here
}
public void testAdd() { int num1 = 3; int num2 = 2; int total = 5; int sum = 0; sum = Math.add(num1, num2); assertEquals(sum, total); }
public void testMulitply() {
int num1 = 3; int num2 = 7; int total = 21; int sum = 0; sum = Math.multiply(num1, num2); assertEquals("Problem with multiply", sum, total);
num1 = 5; num2 = 4;
total = 20; sum = Math.multiply(num1, num2); assertEquals("Problem with multiply", sum, total); } }
And both these files could be kept in a sub-folder named src
Ant Script
The last step is how to run your JUnit tests using Ant. Create a file called build.xml and place it in the main folder. The core of this scripts is the following, which does the JUnit tests.
The file I used is this one. (The inner details of this scripts are Ant Scripting and XML, which is not explained in this document, but really straightforward to understand)
Output
Run ant test in command line:
[root@nimal junit-sample]# ant test Buildfile: build.xml
init:
compile: [javac] Compiling 2 source files to /opt/junit-sample/bin
Ant will also do nice things like create nice HTML reports! I've linked to a simple Ant script that will compile all the code in your "src" folder, run all the tests named "test*" and then create an HTML report in your "reports\html" folder.
I've linked to a zip file (ant-junit-sample.zip) that contains the build.xml file, the source code and the test class. (If you try to run it and get errors about JUnit not being found, remember to add that junit.jar to your Ant lib folder.)
Attachments
ant-junit-sample.zip (109.6 kB) –Scripts for Test ,
This is the fifth part of the so called Ant series I have been writing in this blog, about Apache Ant. This post is mainly about building and running a Java Swing program using Ant.
public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new JFrame("HelloWorldSwing"); final JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }
Ant Script
Use a text editor to create a file called build.xml and place it in the main folder:
compile: [mkdir] Created dir: /opt/ant-swing/build/classes [javac] Warning: HelloWorldSwing.java modified in the future. [javac] Compiling 1 source file to /opt/ant-swing/build/classes
jar: [mkdir] Created dir: /opt/ant-swing/build/jar [jar] Building jar: /opt/ant-swing/build/jar/HelloWorldSwing.jar
run: ... ... [java] at java.awt.Window.<init>(Window.java:406) [java] at java.awt.Frame.<init>(Frame.java:402) [java] at javax.swing.JFrame.<init>(JFrame.java:207) [java] at HelloWorldSwing.main(Unknown Source) [java] Java Result: 1
BUILD SUCCESSFUL Total time: 3 seconds
This is one another basic level post and I strongly advice you to refer to any more advanced document, if you are going to do this for any production system. 🙂
Feedback and questions are welcome via comment or you can email me at talkout AT SPAMFREE gmail DOT com
This is the third part of the so called Ant series I have been writing in this blog, about Apache Ant. This post is mainly about building and running a Java program using Ant. In the example I’m using here, its a Hello World program in simple Java, but most of these basic Ant steps would be same for any other Java program you might run.
compile: [mkdir] Created dir: /opt/ant-hw/build/classes [javac] Warning: HelloWorld.java modified in the future. [javac] Compiling 1 source file to /opt/ant-hw/build/classes
jar: [mkdir] Created dir: /opt/ant-hw/build/jar [jar] Building jar: /opt/ant-hw/build/jar/HelloWorld.jar
run: [java] Hello World BUILD SUCCESSFUL Total time: 4 seconds
Enhance the build file
Now we have a working buildfile we could do some enhancements: many time you are referencing the same directories, main-class and jar-name are hard coded, and while invocation you have to remember the right order of build steps.
As I have worked on Ant before sometime for a project and I had few of my own documents for reference, related to installing and using Apache Ant. I thought of sharing those via this blog as it might be useful to someone out there, or at-least would be a backup of my doc in the Blogger servers. 😉
In this series of Ant, I put and introductory post which is followed by a Hello World post, and then I got a couple of IMs asking how could one come to Hello World before an installation post. (Seems thats the standard way of tutorial, so I said I’m not writing any tutorials, but thought of posting this now… 🙂 … ). System Requirements for Ant
Ant has been used successfully on many platforms, including Linux, MacOS X, Windows XP and Unix. To build and use Ant, you must have a JAXP-compliant XML parser installed and available on your classpath, such as Xerces.
For the current version of Ant, you will also need a JDK installed on your system, version 1.2 or later required, 1.5 or later strongly recommended. The later the version of Java, the more Ant tasks you get.
Note: If a JDK is not present, only the JRE runtime, then many tasks will not work.
Building Ant
Obtaining Ant
To build Ant from source, you can either install the Ant source distribution or checkout the Ant module from SVN. I obtained the Ant source version and placed it at /opt/
Once you have obtained the source, change into the installation directory and run,
[root@nimal opt]# tar -xzvf apache-ant-1.7.0-src.tar.gz
This will creat Set the JAVA_HOME environment variable to the directory where the JDK is installed. See Installing Ant for examples on how to do this for your operating system.
Note: The bootstrap process of Ant requires a greedy compiler like Sun’s javac or jikes. It does not work with gcj or kjc.
Make sure you have downloaded any auxiliary jars required to build tasks you are interested in. These should be added to the lib/optional directory of the source tree. See Library Dependencies for a list of JAR requirements for various features. Note that this will make the auxiliary JAR available for the building of Ant only. For running Ant you will still need to make the JARs available as described under Installing Ant.
build -Ddist.dir=<directory_to_contain_Ant_distribution> dist (Windows) sh build.sh -Ddist.dir=<directory_to_contain_Ant_distribution> dist (Unix)
[root@nimal opt]# cd /opt/apache-ant-1.7.0/ [root@nimal apache-ant-1.7.0]# sh build.sh -Ddist.dir=/usr/local/ant/ dist Buildfile: build.xml
dist:
prepare:
check_for_optional_packages:
build: [copy] Copying 2 files to /opt/apache-ant-1.7.0/build/classes
jars: [jar] Building jar: /opt/apache-ant-1.7.0/build/lib/ant.jar
. . .
compile-tests:
test-jar:
dist-lite: [mkdir] Created dir: /usr/local/ant [mkdir] Created dir: /usr/local/ant/bin [mkdir] Created dir: /usr/local/ant/lib [copy] Copying 8 files to /usr/local/ant/lib [copy] Copying 2 files to /usr/local/ant/lib [copy] Copying 13 files to /usr/local/ant/bin
javadoc_check:
javadocs: [mkdir] Created dir: /opt/apache-ant-1.7.0/build/javadocs [javadoc] Generating Javadoc
. . .
[javadoc] 114 warnings
dist_javadocs: [mkdir] Created dir: /usr/local/ant/docs/manual/api [copy] Copying 1180 files to /usr/local/ant/docs/manual/api
internal_dist: [mkdir] Created dir: /usr/local/ant/etc [copy] Copying 1 file to /usr/local/ant/lib [copy] Copying 1 file to /usr/local/ant/lib [copy] Copying 25 files to /usr/local/ant/lib [copy] Copying 1 file to /usr/local/ant/lib [copy] Copying 259 files to /usr/local/ant/docs [copy] Copying 33 files to /usr/local/ant/docs [copy] Copying 11 files to /usr/local/ant [copy] Copying 15 files to /usr/local/ant/etc
BUILD SUCCESSFUL Total time: 59 seconds
This will create a binary distribution of Ant in the directory you specified.
The above action does the following:
If necessary it will bootstrap the Ant code. Bootstrapping involves the manual compilation of enough Ant code to be able to run Ant. The bootstrapped Ant is used for the remainder of the build steps.
Invokes the bootstrapped Ant with the parameters passed to the build script. In this case, these parameters define an Ant property value and specify the “dist” target in Ant’s own build.xml file.
Create the ant.jar and ant-launcher.jar JAR files
Create optional JARs for which the build had the relevant libraries. If a particular library is missing from ANT_HOME/lib/optional, then the matching ant- JAR file will not be created. For example, ant-junit.jar is only built if there is a junit.jar in the optional directory.
Other ways to build and install
On most occasions you will not need to explicitly bootstrap Ant since the build scripts do that for you. If however, the build file you are using makes use of features not yet compiled into the bootstrapped Ant, you will need to manually bootstrap. Run bootstrap.bat (Windows) or bootstrap.sh (UNIX) to build a new bootstrap version of Ant. If you wish to install the build into the current ANT_HOME directory, you can use:
build install (Windows) sh build.sh install (Unix)
You can avoid the lengthy Javadoc step, if desired, with:
build install-lite (Windows) sh build.sh install-lite (Unix)
This will only install the bin and lib directories.
Both the install and install-lite targets will overwrite the current Ant version in ANT_HOME.
Checking the Installation
Now we have built and installed Ant, and we can check if everything works properly, as shown below.
[root@nimal ~]# which ant /usr/local/ant/bin/ant [root@nimal ~]# ant -version Apache Ant version 1.7.0 compiled on November 13 2007
This is just a brief document related to Ant installation which I did on a RHEL4 server. I think this should work on other environments as well, but I’m not sure about that. If someone of you try this using my doc and if you are successful just let me know via a comment. Also if you have any doubts you can ask me, but I can assure answers, if-and-only-if its under my intellectual capacity :).