tags:

views:

104

answers:

2

I want to generate a properties file, from my ant script, that contains the svn version number of my project. I'm 1/3 of the way done:

To do this I need to:

  1. use svnversion

    1a. define the svn task

    1b. use <svn><wcVersion></svn>

  2. put the result in a .properties file that ends up in my build path

I'm a bit lost with 1a and 2. any ideas?

+2  A: 

What I used is to execute svn info --xml, then loaded the resulted xml file using <XmlProperty> link text task and in the end just replacing a token in the property file that is path of the build path.

So something like this:

<target name="svn-build-number">
  <tempfile property="svninfo.file"/>
  <exec dir="." executable="svn" output="${svninfo.file}">
    <arg line="info --xml"/>
  </exec>
  <echo message="${svninfo.file}" />
  <xmlproperty file="${svninfo.file}" collapseAttributes="true" />
  <echo message="${info.entry.revision}" />
</target>

In ${info.entry.revision} is the revision of the repository in the current dir.

fikovnik
instead of temp. file, you can use a property: <exec executable="svn" outputproperty="svninfo.xml"> <arg line="info --xml"/> </exec> <xmlproperty collapseAttributes="true"> <propertyresource name="svninfo.xml"/> </xmlproperty> <echo message="${info.entry.revision}" />
kabado
+1  A: 

never mind, I got it working:

<target name="svnversion">
  <echo file="${srcDir}/${packagePath}/svnversion.properties">svnversion=</echo>
  <exec executable="svnversion"
      output="${srcDir}/${packagePath}/svnversion.properties" append="true">
  </exec>
</target>   
Jason S