<target name="svnrevision" description="Retrieve svn info">
<java classname="org.tmatesoft.svn.cli.svnversion.SVNVersion"
outputproperty="svn.revision">
<classpath>
<fileset dir="${build.lib.dir}" />
</classpath>
<arg path="${basedir}" />
</java>
</target>
That ant target will nab the revision number and stuff it in a property named svn.revision for use later in the ant script. In the event that you are working on an exported code base that is not a local svn repo, your svn.revision property will have a value of "exported", thus keeping the build from breaking if you are building from an export or don't even have an svn client installed. All you need is the svnkit libraries for svnkit.jar and svnkit-cli.jar on your classpath (as I have done by placing them in the directory referenced by the ${build.lib.dir} property).
Once you have the revision number in a property, creating a version string for a properties file , for example, can be done with the propertyfile ant task:
<target name="versionproperties" depends="svnrevision">
<propertyfile file="build/classes/version.properties" >
<entry key="name" value="${project.name}" />
<entry key="version" value="${project.version}" />
<entry key="revision" value="${svn.revision}" />
</propertyfile>
</target>
Which will create a property file at the root of your classpath (assuming that is what is in build/classes) that looks similar to the following:
#Sat Jan 10 06:44:37 EST 2009
version=1.5.1
revision=3827
name=your_project_name
This properties file can easily be slurped up by your app using Java's Properties class and referenced very easily by some servlet or some Swing component to easily provide version reporting.
2 comments:
Seems blogger.com doesn't have a nice way of handling stuff in <pre> tags to keep it from rolling off of the right margin. I suppose I need one of those javascript syntax highlighters that will embed my paste in a frame. My apologies for the inconvenience.
And I settled on prettify
Post a Comment