Skip to main content

Automated release tagging with ANT

Sometime back I was researching how to automatically tag a CVS snapshop from an ANT script. Yes, I know this should be a basic thing :-) But for some reason, IT has always taken care of tagging and creating builds. Whenever I needed to release some code, I would tag the CVS snapshot from Eclipse, I would manually creat a MANIFEST.MF file, and then create the distributable.

However, this time I tried to automate the task with an ANT script.

What I needed was an ANT script which would automatically create a MANIFEST.MF file with a release number, and tag the CVS project with that release number.

The first thing I came across was the Ant cvs task. This task allows us to run any CVS command on a repository. However, there is a catch. You need CVS installed on your local machine for this to work. Under the hoods the CVS task invokes cvs.exe (on Windows), or cvs on *nix machines. This was a clear show stopper. I did not want to make all developers install CVSNT on their development machines.

So, I started looking for CVS libraries implemented in Java. There are a couple of them. I decided to settle with javacvs which is created by the Netbeans folks. javacvs is a CVS client implementation written purely in Java. If you are interested, here is a javacvs quick start tutorial. It outlines some non trivial steps for setting up and using javacvs.

I downloaded javacvs and wrote some code to tag my repository. However, when I ran it, the library threw a NullPointerException. The javacvs folks have not created Javadocs for their projects, so the only option I had to figure out what was wrong, was to look at their source code. I followed a link from their page to download the sources. However, the page suggested that the sources were moved to a Mercurial repository. They were also merged with the Netbeans source, so I would now have to download all of Netbeans to get the javacvs sources.

Ok, so I installed Mercurial and ran this to get the Netbeans sources.

hg clone

It seemed to be doing something, but it was also taking forever. After downloading some 350 MB of stuff, it still seemed to be getting more. The command line did not give me any status message, so I had no clue how much was downloaded and how long it would take. To make matters worse, we had some network problems on that day and the Internet was really dragging. After a couple of hours, I gave up and aborted the checkout. After coming home I tried to resume the download by running the above command, but it failed. Looks like partially cloned Mercurial repositories cannot be resumed. I would have to delete all the downloaded files and restart the clone operation.

Meanwhile, I came across a class called CvsCommand in javacvs, which was like a command line for javacvs. It could take any cvs command with arguments and run it on the CVS repository. I ran the following from my project directory. This class was also set to be the main-class of the jar file. So executing the jar as shown below results in the main method of CvsCommand being invoked.

java -jar org-netbeans-lib-cvsclient.jar tag b20090211_01

It almost worked. It read CVSROOT details from the ./CVS/Root file, but it complained that it could not find the password for my CVS account. Some research suggested that I needed a .cvspass file in my home directory. But how was I to create a .cvspass file? It had to be created automatically. I copied .cvspass from my Linux machine into the home directory of my Windows machine. But javacvs continued complaining about the password. So, I manually modified the ./CVS/Root file in the project directory and added a password to the cvsroot string. The format is


Finally everything worked. Running the program automatically tagged the CVS repository with a releaseNumber.

I could run the above command using ANT's java task. However, I still had to manually specify the build number in the Ant script. Ant also has a buildNumber task, which can create incremental numbers. This task relies on a file to store a number. Every time it is run it takes the number from the file and saves it in memory in an Ant property called build.number. At the same time it also rewrites the file with an incremented number. By default it uses a file called build.number in the same directory as the Ant script. However, we can specify another file if we want. Ok, so this gave me incremental numbers, but I still wanted to use a timestamp in the build number. Ant has a task called tstamp for just that. When run, it's default behavior is to store the current time (yyyymmdd) in an Ant property called TODAY. I could concatenate the output from tstamp and buildNumber to create a release tag.

I still wanted to automatically create a MANIFEST.MF file with the release number. Ant also has a manifest task, which creates a MANIFEST.MF file from supplied parameters.

Here's a simple build file that uses Ant's buildNumber, tstamp, manifest, and java tasks to automatically tag CVS with a release number and create a manifest file. To make a release, run this file first followed by your regular ANT script which creates the distributable file.

<project name="MyProject" basedir="." default="tag">
  <target name="build_number">
    <tstamp />
    <property name="" value="release_${DSTAMP}_${build.number}" />

  <target name="generate_manifest" depends="build_number">
    <manifest file="WebContent/META-INF/MANIFEST.MF">
      <attribute name="Built-By" value="${}"/>
      <attribute name="Product-Name" value="MyProject" />
      <attribute name="Date" value="${TODAY}" />
      <attribute name="Tag" value="${}" />
      <attribute name="Class-Path" value="" />

  <target name="tag" depends="generate_manifest">
    <echo message="tagging with build number ${}" />
    <java jar="lib/org-netbeans-lib-cvsclient.jar" fork="true">
      <arg value="tag" />
      <arg value="${}" />


Popular posts from this blog

Running your own one person company

Recently there was a post on PuneTech on mom's re-entering the IT work force after a break. Two of the biggest concerns mentioned were : Coping with vast advances (changes) in the IT landscape Balancing work and family responsibilities Since I have been running a one person company for a good amount of time, I suggested that as an option. In this post I will discuss various aspects of running a one person company. Advantages: You have full control of your time. You can choose to spend as much or as little time as you would like. There is also a good chance that you will be able to decide when you want to spend that time. You get to work on something that you enjoy doing. Tremendous work satisfaction. You have the option of working from home. Disadvantages: It can take a little while for the work to get set, so you may not be able to see revenues for some time. It takes a huge amount of discipline to work without a boss, and without deadlines. You will not get the benefits (insuranc

Testing Groovy domain classes

If you are trying to test Grails domain class constraints by putting your unit test cases in the 'test/unit' directory, then your tests will fail because the domain objects will not have the 'valdate' method. This can be resolved in two ways: Place the test cases inside test/integration (which will slow things down) Use the method 'mockForConstraintsTests(Trail)' to create mock method in your domain class and continue writing your test cases in 'test/unit' What follows is some example code around this finding. I am working on a Groovy on Grails project for a website to help programmers keep up and refresh their skills. I started with some domain classes and then moved on to write some unit tests. When we create a Grails project using grails create-app , it creates several directories, one of which is a directory called 'test' for holding unit tests. This directory contains two directories, 'unit', and 'integration' for unit and

Planning a User Guide - Part 3/5 - Co-ordinate the Team

Photo by  Helloquence  on  Unsplash This is the third post in a series of five posts on how to plan a user guide. In the first post , I wrote about how to conduct an audience analysis and the second post discussed how to define the overall scope of the manual. Once the overall scope of the user guide is defined, the next step is to coordinate the team that will work on creating the manual. A typical team will consist of the following roles. Many of these roles will be fulfilled by freelancers since they are one-off or intermittent work engagements. At the end of the article, I have provided a list of websites where you can find good freelancers. Creative Artist You'll need to work with a creative artist to design the cover page and any other images for the user guide. Most small to mid-sized companies don't have a dedicated creative artist on their rolls. But that's not a problem. There are several freelancing websites where you can work with great creative ar