Jens A. Koch

Subversion Tasks of Phing buildfile

The article shows some Subversion tasks of a Phing buildfile.
These tasks might be useful for those still working with SVN.

The tasks (1) “checking out” and (2) “updating”, deal both with a local SVN repository.

The tasks “exporting” an external (3) or local (4) repository have the purpose of getting a clean build directory without any “.svn” stuff.

The task “update repo and do local export” (5) is good for cronjob inclusion. Imagine that the next steps would be “compile” and “zip/tar.gz”.

The task “svn-lastrevision” is for fetching the revision number. You might use it for appending the product version (v1.2.3-#123).

There is also a task called “mrproper-svn-dir” – now, guess what?
Yes, it removes the export dirs for a fresh start.

Have a look and feel free to reuse. Regards, J

List of Subversion Commands
---------------------------

1 - svn-update : updates ${svn.local.directory} via svn update
2 - svn-checkout : svn checkout from ${svn.repository}
3 - svn-export-from-extern: svn export from ${svn.repository}
4 - svn-export-from-local : svn export from ${svn.local.directory}
5 - svn-up-export-local : svn-update + svn-export-from-local

    <!-- ============================================ -->
    <!-- ======          Subversion Tasks      ====== -->
    <!-- ============================================ -->

    <!-- setup the svn properties -->
    <property name="svn.path"        value="/usr/bin/svn" />                             <!-- Path to SVN -->
    <property name="svn.username"    value="YOUR_SVN_USERNAME" />                        <!-- SVN Username -->
    <property name="svn.password"    value="YOUR_SVN_PASSWORD" />                        <!-- SVN Password -->
    <property name="svn.repository"  value="http://your.company.com/svn/product/trunk/" />  <!-- SVN Repository URL -->
    <!-- We are building from /trunk. Later from /tag releases!
    <property name="repository" value="http://your.company.com/svn/product/tag/${product_version}/" />
    -->

    <target name="svn-update" description="Updates ${svn.local.directory} via svn update.">
        <echo>Performing an SVN Update</echo>
        <exec command="svn update ${svn.local.directory}"/>
    </target>

    <target name="svn-checkout" description="Checks out the external Subversion repository to the local directory ${svn.local.directory}.">
        <echo>Performing an SVN Checkout</echo>
        <svncheckout svnpath="${svn.path}" repositoryurl="${svn.repository}" todir="${svn.local.directory}" />
    </target>

    <target name="svn-export-from-extern" description="Exports the external Subversion repository to the local export directory ${svn.local.export.directory}.">
        <echo>Performing an SVN Export</echo>
        <svnexport svnpath="${svn.path}"
                   username="${svn.username}" password="${svn.password}"
                   nocache="true" force="true"
                   repositoryurl="${svn.repository}" todir="${svn.local.export.directory}" />
    </target>

    <target name="svn-export-from-local" description="Exports the local Subversion repository to the local export directory ${svn.local.export.directory}.">
        <echo>Performing an SVN Export on local SVN Repository</echo>
        <svnexport svnpath="${svn.path}" nocache="true" force="true"
                   repositoryurl="${svn.local.directory}" todir="${svn.local.export.directory}" />
    </target>

    <target name="svn-lastrevision" description="Fetches the SVN Revision Number to a Property">
        <echo>Fetching the Revision Number</echo>
        <svnlastrevision svnpath="${svn.path}" workingcopy="${svn.local.directory}" propertyname="svn.lastrevision"/>
    </target>

    <target name="mrproper-svn-dir" description="Mr.Proper will clean the SVN Export Dir">
        <echo>Removes and recreates the SVN Export Dir to have a clean copy</echo>
        <delete dir="${svn.local.export.directory}" failonerror="true" verbose="false" includeemptydirs="true" />
        <mkdir dir="${svn.local.export.directory}" />
    </target>

    <target name="svn-up-export-local" description="Combined tasks of svn update and svn export local">
        <echo>Combined tasks of svn update and svn export local</echo>
        <phingcall target="svn-update" />
        <phingcall target="svn-export-from-local" />
    </target>
Comments Off on Subversion Tasks of Phing buildfile

Comments are closed.