Get Rev Number from SVN to Display in Web App

Discussion in 'Java' started by Jan Burse, May 8, 2012.

  1. Jan Burse

    Jan Burse Guest

    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
    Jan Burse, May 8, 2012
    #1
    1. Advertising

  2. Jan Burse

    Roedy Green Guest

    On Tue, 08 May 2012 12:15:35 +0200, Jan Burse <>
    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.
    ..
    Roedy Green, May 8, 2012
    #2
    1. Advertising

  3. 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.
    Donkey Hottie, May 8, 2012
    #3
  4. Jan Burse

    Jan Burse Guest

    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
    Jan Burse, May 8, 2012
    #4
  5. 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.
    Donkey Hottie, May 8, 2012
    #5
  6. Jan Burse

    Jan Burse Guest

    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!
    Jan Burse, May 8, 2012
    #6
  7. Jan Burse

    Jan Burse Guest

    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.
    Jan Burse, May 8, 2012
    #7
  8. Jan Burse

    Lew Guest

    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
    Lew, May 8, 2012
    #8
  9. Jan Burse

    Nigel Wade Guest

    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
    Nigel Wade, May 8, 2012
    #9
  10. Jan Burse

    Jan Burse Guest

    Nigel Wade schrieb:

    > HTH.


    Looks perfect!
    Jan Burse, May 8, 2012
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. "a" tag rel and rev

    , Nov 1, 2006, in forum: HTML
    Replies:
    5
    Views:
    384
    Jukka K. Korpela
    Nov 2, 2006
  2. name

    Wrap rev 2.

    name, Aug 25, 2004, in forum: C Programming
    Replies:
    8
    Views:
    414
  3. R. David Murray
    Replies:
    0
    Views:
    189
    R. David Murray
    Mar 17, 2009
  4. Robert P. J. Day
    Replies:
    0
    Views:
    210
    Robert P. J. Day
    Jan 19, 2010
  5. Simon Strandgaard
    Replies:
    3
    Views:
    93
    Simon Strandgaard
    Jul 22, 2005
Loading...

Share This Page