A couple days ago I had my first experience with Apache Ant. If you have never heard of it before you should definitely check it out. Apache Ant is a very simple JAVA-based build tool with xml-based configuration files for automation.

I wanted to automate the process of importing/exporting specific MySQL database tables.In the next step I wanted to update and commit the data to SVN. After a quick research I found the JAVA lib svntask which is based on SVNKit very useful.

The only disadvantage in my opinion is that there is almost no documentation yet. To help other developers to get off on the right foot and save some time I’ll give some examples in the following section.

SVN update example:

<!-- SVN update -->
<target name="svn-update">
	<svn>
		<update
			path="/workspace/path"
			force="false" recursive="false"
		/>
	</svn>
</target>

Optional arguments you can use are recursive(default: true) and force(default: true).

SVN add example:

<!-- SVN add -->
<target name="svn-add">
	<svn>
		<add
			path="/workspace/project"
			force="false"
		/>
	</svn>
</target>

Optional boolean arguments are force, mkdir, climbUnversionedParents, includeIgnored and makeParents(default for all except mkrdir is true).

SVN commit example:

With version 1.0.7 authentication failed for me. So I added the username/password authentication to the commit class. You can get the temporary version here until the next update of svntask.

<!-- SVN Commit -->
<target name="svn-commit">
	<!-- don't store password in property files, use input  -->
	<input
		message="Enter SVN password:"
		addproperty="svn.password"
	 />
	<svn>
		<commit
			path="/workspace/project/trunk"
			commitMessage="Test commit"
			force="true"
			username="user" password="${svn.password}"
		/>
	</svn>
</target>

Optional boolean arguments are keepLocks and force.

SVN ls update example:

<!-- SVN ls -->
<target name="svn-ls">
	<svn>
		<ls
			repository="http://domain.tld"
			path="/svn/repos/project/trunk"
		/>
	</svn>
</target>

Optional argument is delimeter(default: , ).

SVN info example:

<!-- SVN info -->
<target name="svn-info">
	<svn>
		<info
			path="/workspace/project/trunk"
			committedRevisionProperty="revisionVersion"
			authorProperty="revisionAuthor"
			committedDateProperty="revisionDate"
		/>
	</svn>
	<!-- show revision, author and date -->
	<property
		name="version"
		value="At revision ${revisionVersion} by ${revisionAuthor} on ${revisionDate}"
	/>
	<echo message="${version}"/>
</target>

I didn’t use log, status and switch so far. I will post examples if I will use it in the future.

Some useful links:
svntask: http://code.google.com/p/svntask/
Apache Ant project: http://ant.apache.org/


4 Comments on “svntask examples for Apache Ant”

You can track this conversation through its atom feed.

  1. john Telford sagt:

    Nice work!

    You’re right, there is almost no svntask documentation.

    Would you be willing to tell me how to install svntask ?

    Thanks …John

  2. Chris sagt:

    To install it, just drop svntask.jar and svnkit.jar into the lib folder of your ant installation.

    Then put this near the top of your build.xml file:

  3. Stephen sagt:

    Erm, put what near the top of the build.xml file ??

    Thanks,
    Stephen

  4. Rohin sagt:

    Hi
    This is really great help from you.
    I am facing an issue what I need to do is check whether a(or multiple) file(s) if it is version-ed or not and if not then perform SVN add else perform SVN commit using SVNANT.

    Thanks in advance.

Einen Kommentar hinterlassen

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>