How do I get the username of the last svn commit using ant?

I would like to use Ant to get the username of the last commit of the svn repository.

how can i make this as cross-platform as possible?

thank!

+3


source to share


4 answers


So here's an example for "svnant":

<path id="devlibs.path">
    <fileset dir="devlib" includes="**/*.jar" />
</path>

<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="devlibs.path" />

<svnSetting
        id="svn.settings"
        svnkit="false"
        javahl="false"
        username="${svn.username}"
        password="${svn.password}" />

<target name="get-svn-author">
    <svn refid="svn.settings">
        <singleinfo target="${svn.repo.url}" property="author.result" request="author" />
    </svn>

    <echo message="Author of last commit: ${author.result}" />
</target>

      



You must put "svnant.jar" and "svnClientAdapter.jar" in the path identified by "devlibs.path". And other libraries required by "javahl" or "svnkit" for your "$ ANT_HOME" / lib.

If you have an SVN repository with format 1.6 you can use "svnkit" (set to "true" in "svnSetting" -block Because "svnkit" is a pure Java toolkit and is best used when you need a cross platform solution. If you've already switched to 1.7, I recommend using the SVN command line client ("svnSetting" configured for the command line client lines in my example) Check this page (Slik SVN) for information onwhere to find and how to install different SVN command line clients.

+7


source


Just in case, if you prefer a solution that doesn't use optional tasks, here's the gist of how you can do it:

<target name="get-svn-author">
    <tempfile property="svninfo.result"/>
    <exec executable="svn" output="${svninfo.result}">
        <arg value="info"/>
        <arg value="${svn.repo.url}"/>
    </exec>
    <tempfile property="svnauthor.result"/>
    <copy file="${svninfo.result}" tofile="${svnauthor.result}">
        <filterchain>
            <linecontainsregexp>
                <regexp pattern="Last Changed Author:*"/>
            </linecontainsregexp>
        </filterchain>
    </copy>
    <concat>
        <filelist files="${svnauthor.result}"/>
    </concat>
    <delete file="${svninfo.result}"/>
    <delete file="${svnauthor.result}"/>
</target>

      



One catch is that you write / delete files which may not always be possible (i.e. if you don't have permissions). Another problem is that the svn client must be installed (which can be started with a command svn

from the command line).

+7


source


I thought I posted an answer. This is more or less malenkiy_scot's answer . However, I am using the flag --xml

in the command svn info

. This outputs the output of the command svn info

to xml output. Then I was able to use the task <xmlproperty>

to read it.

By using resource collections, I also avoided the problem of saving the output to a file that needs to be deleted later.

<project>
    <property name="svn.url" value="http://svn.foo.com/src/repos"/>
    <exec executable="svn"
        outputproperty="svn.info">
        <arg value="info"/>
        <arg value="--xml"/>
        <arg value="${svn.url}"/>
    </exec>
    <xmlproperty prefix="svn">
        <propertyresource name="svn.info"/>
    </xmlproperty>
    <echo message="Last committer = ${svn.info.entry.commit.author}"/>
</project>

      

I tried to figure out if I can avoid using the task itself <exec>

as a resource. This way I wouldn't even have to save the command output svn info

to a property. But alas, I couldn't figure out how to do it.


The most neutral platform way is Vadim Ponomarev's answer . So I was going to answer this question.

However, I would include the svnkit jar file in the directory devlib

and force the use svnkit

. This will ensure that it works no matter which Subversion client is installed. It even works even if the Subversion client is not installed. Just save the required jars in a directory in the project.

+1


source


An executable shell already has a good solution. This solution has the advantage that you can do it as part of the build phase using scripts rather than in the post-build phase. This is explained below. See fooobar.com/questions/147165 / ...

In fact, you can access the information prior to the completion of the build phase by reading / analyzing the .. / builds / $ BUILD_NUMBER / changelog.xml file inside the build folder. This file is generated when SVN commit is run, not at the end of the build phase or post_build. This means that you can parse it at the start of the build phase of the same job with a script and insert data into env variables.

0


source







All Articles