Get Rev Number from SVN to Display in Web App

J

Jan Burse

Dear All,

Is there a simple Ant task to retrieve the revision
number of my code from a SVN repository, and then
store it in some location, so that later my web
application can show it?

Best Regards
 
R

Roedy Green

Is there a simple Ant task to retrieve the revision
number of my code from a SVN repository, and then
store it in some location, so that later my web
application can show it?

It is pretty easy to turn any exe into an ant task, so you can widen
your net.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Programmers love to create simplified replacements for HTML.
They forget that the simplest language is the one you
already know. They also forget that their simple little
markup language will bit by bit become even more convoluted
and complicated than HTML because of the unplanned way it grows.
..
 
D

Donkey Hottie

Dear All,

Is there a simple Ant task to retrieve the revision
number of my code from a SVN repository, and then
store it in some location, so that later my web
application can show it?

Best Regards

Just put the "$Revision: $" into your source code, and if it is a jsp
page, add echo "<!-- last build at `date` -->" >>the.jsp so it changes.
You may play with tail so that you just replace the last line in the
file with that time stamp. And have some Java utility to parse the
revision number from the string "$Revision: 2020$"

s.split(":")[1].replace('$',' ').trim();

So there. The page always will have the latest revision from version
control in it.
 
J

Jan Burse

Donkey said:
Just put the "$Revision: $" into your source code

Hi, thanks, but how do I get the revision from SVN?
Are there some SVN specific Ant tasks around, something
along get property? By revision I mean the transaction
number of SVN, not something I know and that I can put
manually in some file.

Bye
 
D

Donkey Hottie

Hi, thanks, but how do I get the revision from SVN?
Are there some SVN specific Ant tasks around, something
along get property? By revision I mean the transaction
number of SVN, not something I know and that I can put
manually in some file.

Bye

If you put that string to a file, svn will replace it with the revision
number when the file is committed to svn.

The file must be enabled to get this using command

svn propset svn:keywords "Revision" filename

http://johnbokma.com/mexit/2008/09/30/subversion-svn-keywords-property.html

The next "svn commit" will update the file with revision number.
 
J

Jan Burse

Donkey said:
If you put that string to a file, svn will replace it with the revision
number when the file is committed to svn.

The file must be enabled to get this using command

svn propset svn:keywords "Revision" filename

http://johnbokma.com/mexit/2008/09/30/subversion-svn-keywords-property.html

The next "svn commit" will update the file with revision number.

But still it doesn't solve my problem. Since it needs
that I commit a file. But if no changes happened at
all, the SVN command I am looking for, should just
return the global transaction count from the last time.
SVN maintains such a counter.
 
L

Lew

Jan said:
But still it doesn't solve my problem. Since it needs
that I commit a file. But if no changes happened at
all, the SVN command I am looking for, should just
return the global transaction count from the last time.
SVN maintains such a counter.

<http://lmgtfy.com/?q=get+subversion+revision+number+automatically+in+Ant>

which led me to find:
<http://ant.apache.org/antlibs/svn/>
<http://subclipse.tigris.org/svnant.html>

I didn't drill down deep enough there to find your specific answer, but since
the Ant tasks are wrappers for the "svn" command, if you know how to do it
with "svn" you should be able to do it with Ant. Some of the links from that
search give specific hacks that you might find useful.
 
N

Nigel Wade

Dear All,

Is there a simple Ant task to retrieve the revision
number of my code from a SVN repository, and then
store it in some location, so that later my web
application can show it?

Best Regards

I use NetBeans, and have added the following to its build.xml for an application in
which I want to include the SVN revision.

This sets a property for ant:

<target name="-post-init" description="Get the svn revision of the current build">
<exec dir=".." outputproperty="svna.version" executable="svnversion">
<arg value="-c" />
<redirector>
<outputfilterchain>
<tokenfilter>
<replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<echo>SVN version ${svna.version}</echo>
</target>


This embeds it into the jar manifest in the post-jar target:

<target name="-post-jar">
....
<jar destfile="${tmp.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>

<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Implementation-Version" value="${svna.version}"/>
<attribute name="SVN-Revision" value="${svna.version}" />
</manifest>
</jar>


This is the resulting contents of the jar manifest:
Manifest-Version: 1.0
Main-Class: package.Main
Implementation-Version: 384M
SVN-Revision: 384M


The main class extracts it, when given the -v flag, using:

System.out.println("SVN revision : " +Main.class.getPackage().getImplementationVersion() );


HTH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top