2

Requirement:

Run svn log -l 1 command and this will have an output like this.

    ------------------------------------------------------------------------
    r2633 | name | 2012-11-07 17:28:20 +0530 (Wed, 07 Nov 2012) | 1 line
    My comment.
    ------------------------------------------------------------------------

I need to extract the revision number 2633 and assign this as a property. I would prefer to avoid ant-contrib.

What I tried:

<echo>Run svn log -l 1</echo>
<exec executable="svn" outputproperty="svn.output" failonerror="false">
    <arg line="log -l 1"/>
</exec>   
<echo message="Output was: ${svn.output}" />

This gets the above output inside the property ${svn.ouput} but am not sure how do I extract version from this.

Other option is to write the variable in file, but again how do I extract the version into a property?

Thanks in advance.

PravinCG
  • 7,688
  • 3
  • 30
  • 55

1 Answers1

2

There isn't a clean way to pull out a substring from a property in standard Ant. See this Stack Overflow answer for some alternative solutions.

Community
  • 1
  • 1
gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
  • That is true. Thanks for the link, I had referred that earlier. I was wondering if using file to write output and then read the data required using regex would be better. I would like to avoid any more dependencies. – PravinCG Nov 30 '12 at 17:38
  • The fourth answer in the link does exactly that - writes a temp. file and searches it with a regex. – gareth_bowles Nov 30 '12 at 17:58