Aliaspooryorik
ColdFusion ORM Book

Automated deployment of SVN revisions with ANT

Automated deployment from Subversion using ANT is one of those things that has been on my to-do list for a very long time and I've finally got around to giving it a serious look.

My aim was to create a script that would get files from SVN that had changed between two specified revisions.

Eclipse (and CFBuilder) come with ANT installed, however, you will still need some additional libraries.

As the ANT SVN library doesn't support the log command, I also needed to install SVN so that I had command line access.

I installed them all in the my C:\dev\ folder, but the path isn't important, although avoid using spaces.

Finally I created a build.xml file (similar to the one shown below), which I run from the ANT view in Eclipse.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
********************************************************************
Dependancies:
********************************************************************
Apache Ant 1.8.0 or higher

ANT Contrib, ant-contrib-0.6.jar
http://sourceforge.net/projects/ant-contrib/files/ant-contrib/

SVN
http://sourceforge.net/projects/win32svn/

XMLTask
http://www.oopsconsultancy.com/software/xmltask
********************************************************************
-->

<project name="deploy from SVN" basedir=".">

<!-- path to svn.exe executable -->
<property name="svn.bin" location="C://dev//Subversion//bin//" />
<!-- when you want to put changed files -->
<property name="temp.dir" value="${basedir}\tmp" />

<!-- the revision range -->
<property name="svn.revision.start" value="38" />
<property name="svn.revision.end" value="HEAD" />

<!-- url to svn repository -->
<property name="svn.repoURL" value="http://myserver/svn/someproject/" />
<property name="svn.base" value="" />
<property name="svn.username" value="your-usename" />
<property name="svn.password" value="your-password" />

<!-- paths to required ANT libraries -->
<property name="lib.path.ant-contrib" value="C:\Dev\ant-contrib-0.6-bin\lib\ant-contrib-0.6.jar" />
<property name="lib.path.xmltask" value="C:\Dev\ant-xmltask\xmltask.jar" />

<target name="init">
<!-- load ant-contrib -->
<property name="ant-contrib.jar" location="${lib.path.ant-contrib}"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${ant-contrib.jar}"/>
<!-- load xmltask -->
<property name="xmltask.jar" location="${lib.path.xmltask}"/>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="${xmltask.jar}"/>
</target>

<target name="parseLog" depends="init" description="parses the svn log">
<!-- use xmltask to get all the files names -->
<xmltask source="${basedir}\svnlog.xml">
<!-- use XPath to get file nodes -->
<copy path="/log/logentry/paths/path[@kind='file']/text()" property="files" append="true" />
</xmltask>

<mkdir dir="${temp.dir}" />

<!-- iterate through files -->
<for list="${files}" param="filepath" delimiter=" ">
<sequential>
<!-- create directory -->
<antcall target="_mkdirFromFilepath">
<param name="filepath" value="@{filepath}"/>
</antcall>
<!-- get the file from SVN -->
<antcall target="_getFileFromSVN">
<param name="filepath" value="@{filepath}"/>
</antcall>
</sequential>
</for>

</target>

<target name="svnlog" description="Exports given revision from the given repository URL to temp.dir" depends="init">
<antcall target="cleanup" />
<!-- creates log in an xml file for revision x to xx -->
<exec executable="${svn.bin}/svn" outputproperty="svnlog.out" output="${basedir}\svnlog.xml" >
<arg line="log --xml -v -r${svn.revision.start}:${svn.revision.end} ${svn.repoURL} --username ${svn.username} --password ${svn.password}" />
</exec>
</target>

<target name="cleanup">
<delete dir="${temp.dir}" />
</target>

<target name="_getFileFromSVN" description="gets the file from SVN if doesn't exist">
<get src="${svn.repoURL}${filepath}" dest="${temp.dir}${filepath}" username="${svn.username}" password="${svn.password}" ignoreerrors="true"/>
</target>

<target name="_mkdirFromFilepath" description="creates a directory from filepath. Requires Apache Ant 1.8.0 or higher for locally scoped properties">
<dirname property="file.dir" file="${temp.dir}${filepath}" />
<mkdir dir="${file.dir}" />
</target>

</project>

No comments

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts