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

Five Reasons Why Your Product Needs an Awesome User Guide

Photo Credit: Peter Merholz ( Creative Commons 2.0 SA License ) A user guide is essentially a book-length document containing instructions for installing, using or troubleshooting a hardware or software product. A user guide can be very brief - for example, only 10 or 20 pages or it can be a full-length book of 200 pages or more. -- As engineers, we give a lot of importance to product design, architecture, code quality, and UX. However, when it comes to the user manual, we often only manage to pay lip service. This is not good. A usable manual is as important as usable software because it is the first line of help for the user and the first line of customer service for the organization. Any organization that prides itself on great customer service must have an awesome user manual for the product. In the spirit of listicles - here are at least five reasons why you should have an awesome user manual! Enhance User Satisfaction In my fourteen years as a

Inheritance vs. composition depending on how much is same and how much differs

I am reading the excellent Django book right now. In the 4th chapter on Django templates , there is an example of includes and inheritance in Django templates. Without going into details about Django templates, the include is very similar to composition where we can include the text of another template for evaluation. Inheritance in Django templates works in a way similar to object inheritance. Django templates can specify certain blocks which can be redefined in subtemplates. The subtemplates use the rest of the parent template as is. Now we have all learned that inheritance is used when we have a is-a relationship between classes, and composition is used when we have a contains-a relationship. This is absolutely right, but while reading about Django templates, I just realized another pattern in these relationships. This is really simple and perhaps many of you may have already have had this insight... We use inheritance when we want to allow reuse of the bulk of one object in other

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