[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Subversion Version Number in Java

From: Andrew Kappen <akappen_at_yahoo.com>
Date: 2004-12-22 17:24:51 CET

It probably won't be a perfect fit for you, but this is how I currently expose the svn repository
version using the jar manifest file. From ant you can pull the repository version by execing
'svnversion', then pop the version into the library manifest jar thus:

<!-- target: version -->
<target name="version">
        <exec executable="svnversion" outputproperty="svn.version">
                <arg value="." />
        </exec>
</target>

<!-- target: jar -->
<target name="jar" description="Build jar for development" depends="compile,version">
        <jar jarfile="${output.filename}.jar" basedir="${dir.build}">
                <manifest>
                        <attribute name="Implementation-Version" value="${svn.version}" />
                </manifest>
        </jar>
</target>

Now you can pull the version from the library manifest using something like this:
(Note that AppVersion must be located within the jar in question, otherwise change
'this.getClass()' with '<someClassInTheVersionedJar>.getClass()')

public class AppVersion {
        public String getCoreVersion() {
                String implementationVersion = this.getClass().getPackage().getImplementationVersion();
                if (implementationVersion == null) {
                        log.info("Implementation version not found, either the jar manifest is incomplete or the
AppVersion class is not contained in a jar file.");
                        return "Unknown, no implementation version found.";
                } else {
                        return implementationVersion;
                }
        }
}

Hope this gives you some ideas!

Cheers,
Andy K.

--- Jubijub <jubijub@free.fr> wrote:

> Chas Douglass wrote:
>
> > Does anyone have a favorite method for getting the current Subversion
> > version number into some Java code for display (e.g. in an about box
> > or whatever).
> >
> > I want do display something like
> > "Product version 1.00; source version 1712"
> > where "1712" is the Subversion repository version number.
> >
> > Chas Douglass
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@subclipse.tigris.org
> > For additional commands, e-mail: users-help@subclipse.tigris.org
> >
> >
> >
> You can do this with an ant task I think,
>
> Julien
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subclipse.tigris.org
> For additional commands, e-mail: users-help@subclipse.tigris.org
>
>

                
__________________________________
Do you Yahoo!?
Dress up your holiday email, Hollywood style. Learn more.
http://celebrity.mail.yahoo.com
Received on Thu Dec 23 03:24:51 2004

This is an archived mail posted to the Subclipse Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.