I was trying to improve our version numbering system, which was manually updated as a number in a file. Looking to make it part of the automated build process, I started looking into SvnAnt. Unfortunately, SvnAnt isn’t platform independent, and builds can occur on Linux or Windows, but JavaSVN is platform independent, and has instructions for integrating with Ant in place of SvnAnt.
Unfortunately, JavaSVN’s support for SVN commands isn’t quite as good as the regular Subversion client. I ended up having to run the equivalent of an “svn status -v” and run it through Ant (v1.6+) filterchains. Fortunately, the built-in filterchains support the equivalent of the GNU head, tail, and tr. All that was missing was a sort. It was pretty straightforward to write a simple Java program to sort stdin and do a little bit of awkwardness in the buildfile to put it all together.
So now every build scans for the latest revision in the repository it can, and extracts that number to use as the version number. Much more convenient for us when talking about which build we were using. Arguably a performance issue, but the repository isn’t that big, and Subversion’s smart enough to keep information like that locally anyway.
Updated 2006-11-16
Thanks to Scott Carlson for pointing out that the command svnversion produces a concise version number (or range) that is much easier to parse.