java: generating a properties file that contains t

2019-05-25 02:35发布

问题:

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?

回答1:

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>   


回答2:

What I used is to execute svn info --xml, then loaded the resulted xml file using <XmlProperty> 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.



标签: svn ant