Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Get Rev Number from SVN to Display in Web App

Reply
Thread Tools

Get Rev Number from SVN to Display in Web App

 
 
Jan Burse
Guest
Posts: n/a
 
      05-08-2012
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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-08-2012
On Tue, 08 May 2012 12:15:35 +0200, Jan Burse <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>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.
..
 
Reply With Quote
 
 
 
 
Donkey Hottie
Guest
Posts: n/a
 
      05-08-2012
On 8.5.2012 13:15, Jan Burse wrote:
> 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.

--

You shall be rewarded for a dastardly deed.
 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      05-08-2012
Donkey Hottie schrieb:
> 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
 
Reply With Quote
 
Donkey Hottie
Guest
Posts: n/a
 
      05-08-2012
On 8.5.2012 14:20, Jan Burse wrote:
> Donkey Hottie schrieb:
>> 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


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/3...-property.html

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


 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      05-08-2012
Donkey Hottie schrieb:
> On 8.5.2012 14:20, Jan Burse wrote:
>> Donkey Hottie schrieb:
>>> 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

>
> 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/3...-property.html
>
> The next "svn commit" will update the file with revision number.
>
>


Cool! I will give it a try!
 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      05-08-2012
Donkey Hottie schrieb:
> On 8.5.2012 14:20, Jan Burse wrote:
>> Donkey Hottie schrieb:
>>> 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

>
> 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/3...-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.





 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      05-08-2012
Jan Burse wrote:
> Donkey Hottie schrieb:
>> Jan Burse wrote:
>>> Donkey Hottie schrieb:
>>>> 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

>>
>> 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/3...-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.


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

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedi.../c/cf/Friz.jpg
 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      05-08-2012
On 08/05/12 11:15, Jan Burse wrote:
> 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.

--
Nigel Wade
 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      05-08-2012
Nigel Wade schrieb:

> HTH.


Looks perfect!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get "last action" from SVN::Client? david.karr Perl Misc 4 06-10-2010 11:35 PM
can i examine the svn rev used to build a python 3 executable? Robert P. J. Day Python 0 01-19-2010 03:29 PM
svn backup via rake.. easier way to obtain lastest rev? Simon Strandgaard Ruby 3 07-22-2005 09:06 AM
get svn version Alessandro Rossi Java 7 06-07-2005 08:39 AM
Re: Dialogic D/240SC-T1 Rev.2 and Rev.3 for sale GREGORY BURNS VOIP 0 07-08-2003 04:05 AM



Advertisments