Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #14394 > unrolled thread

Get Rev Number from SVN to Display in Web App

Started byJan Burse <janburse@fastmail.fm>
First post2012-05-08 12:15 +0200
Last post2012-05-08 16:21 +0200
Articles 11 — 6 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Get Rev Number from SVN to Display in Web App Jan Burse <janburse@fastmail.fm> - 2012-05-08 12:15 +0200
    Re: Get Rev Number from SVN to Display in Web App Roedy Green <see_website@mindprod.com.invalid> - 2012-05-08 03:23 -0700
      Re: Get Rev Number from SVN to Display in Web App Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-05-08 05:34 -0500
    Re: Get Rev Number from SVN to Display in Web App Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-05-08 14:13 +0300
      Re: Get Rev Number from SVN to Display in Web App Jan Burse <janburse@fastmail.fm> - 2012-05-08 13:20 +0200
        Re: Get Rev Number from SVN to Display in Web App Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-05-08 15:09 +0300
          Re: Get Rev Number from SVN to Display in Web App Jan Burse <janburse@fastmail.fm> - 2012-05-08 14:17 +0200
          Re: Get Rev Number from SVN to Display in Web App Jan Burse <janburse@fastmail.fm> - 2012-05-08 14:23 +0200
            Re: Get Rev Number from SVN to Display in Web App Lew <noone@lewscanon.com> - 2012-05-08 05:44 -0700
    Re: Get Rev Number from SVN to Display in Web App Nigel Wade <nmw@ion.le.ac.uk> - 2012-05-08 14:56 +0100
      Re: Get Rev Number from SVN to Display in Web App Jan Burse <janburse@fastmail.fm> - 2012-05-08 16:21 +0200

#14394 — Get Rev Number from SVN to Display in Web App

FromJan Burse <janburse@fastmail.fm>
Date2012-05-08 12:15 +0200
SubjectGet Rev Number from SVN to Display in Web App
Message-ID<joaro7$8hs$1@news.albasani.net>
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

[toc] | [next] | [standalone]


#14395

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-05-08 03:23 -0700
Message-ID<40thq7lpf213fdvvoe16voemf8kd9gs2dr@4ax.com>
In reply to#14394
On Tue, 08 May 2012 12:15:35 +0200, Jan Burse <janburse@fastmail.fm>
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.
.

[toc] | [prev] | [next] | [standalone]


#14398

FromLeif Roar Moldskred <leifm@dimnakorr.com>
Date2012-05-08 05:34 -0500
Message-ID<idydnXO4isxcazXSnZ2dnUVZ8j2dnZ2d@giganews.com>
In reply to#14395
Roedy Green <see_website@mindprod.com.invalid> wrote:
> 
> It is pretty easy to turn any exe into an ant task, so you can widen
> your net.

It's also usually a bad idea to do so. Your build process should
be platform agnostic when possible.

-- 
Leif Roar Moldskred

[toc] | [prev] | [next] | [standalone]


#14399

FromDonkey Hottie <donkey@fredriksson.dy.fi>
Date2012-05-08 14:13 +0300
Message-ID<snbn79-ct6.ln1@hurricane.fredriksson.dy.fi>
In reply to#14394
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.

[toc] | [prev] | [next] | [standalone]


#14400

FromJan Burse <janburse@fastmail.fm>
Date2012-05-08 13:20 +0200
Message-ID<joavia$gkd$1@news.albasani.net>
In reply to#14399
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

[toc] | [prev] | [next] | [standalone]


#14401

FromDonkey Hottie <donkey@fredriksson.dy.fi>
Date2012-05-08 15:09 +0300
Message-ID<b1fn79-7f8.ln1@hurricane.fredriksson.dy.fi>
In reply to#14400
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/30/subversion-svn-keywords-property.html

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

[toc] | [prev] | [next] | [standalone]


#14402

FromJan Burse <janburse@fastmail.fm>
Date2012-05-08 14:17 +0200
Message-ID<job2s7$n5m$1@news.albasani.net>
In reply to#14401
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/30/subversion-svn-keywords-property.html
>
> The next "svn commit" will update the file with revision number.
>
>

Cool! I will give it a try!

[toc] | [prev] | [next] | [standalone]


#14404

FromJan Burse <janburse@fastmail.fm>
Date2012-05-08 14:23 +0200
Message-ID<job38e$o6m$1@news.albasani.net>
In reply to#14401
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/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.




[toc] | [prev] | [next] | [standalone]


#14406

FromLew <noone@lewscanon.com>
Date2012-05-08 05:44 -0700
Message-ID<job4fq$qp4$1@news.albasani.net>
In reply to#14404
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/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.

<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/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#14407

FromNigel Wade <nmw@ion.le.ac.uk>
Date2012-05-08 14:56 +0100
Message-ID<a0sn2cFpuhU1@mid.individual.net>
In reply to#14394
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

[toc] | [prev] | [next] | [standalone]


#14408

FromJan Burse <janburse@fastmail.fm>
Date2012-05-08 16:21 +0200
Message-ID<joba60$73t$1@news.albasani.net>
In reply to#14407
Nigel Wade schrieb:

> HTH.

Looks perfect!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web