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 http://hg.netbeans.org/main/

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

:pserver:user_name:password@cvs.hostname/home/cvs/project

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 />
    <buildnumber/>
    <property name="project.build.number" value="release_${DSTAMP}_${build.number}" />
  </target>

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

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

Comments

Popular posts from this blog

My HSQLDB schema inspection story

This is a simple story of my need to inspect the schema of an HSQLDB database for a participar FOREIGN KEY, and the interesting things I had to do to actually inspect it. I am using an HSQLDB 1.8 database in one of my web applications. The application has been developed using the Play framework , which by default uses JPA and Hibernate . A few days back, I wanted to inspect the schema which Hibernate had created for one of my model objects. I started the HSQLDB database on my local machine, and then started the database manager with the following command java -cp ./hsqldb-1.8.0.7.jar org.hsqldb.util.DatabaseManagerSwing When I tried the view the schema of my table, it showed me the columns and column types on that table, but it did not show me columns were FOREIGN KEYs. Image 1: Table schema as shown by HSQLDB's database manager I decided to search on StackOverflow and find out how I could view the full schema of the table in question. I got a few hints, and they all pointed to

Fuctional Programming Principles in Scala - Getting Started

Sometime back I registered for the Functional Programming Principles in Scala , on Coursera. I have been meaning to learn Scala from a while, but have been putting it on the back burner because of other commitments. But  when I saw this course being offered by Martin Odersky, on Coursera , I just had to enroll in it. This course is a 7 week course. I will blog my learning experience and notes here for the next seven weeks (well actually six, since the course started on Sept 18th). The first step was to install the required tools: JDK - Since this is my work machine, I already have a couple of JDK's installed SBT - SBT is the Scala Build Tool. Even though I have not looked into it in detail, it seems like a replacement for Maven. I am sure we will use it for several things, however upto now I only know about two uses for it - to submit assignments (which must be a feature added by the course team), and to start the Scala console. Installed sbt from here , and added the path

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. -- prismnet.com 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