Listing 3 Hand-crafted Ant tasks that can be called as part of Maven’s build lifecycle
<project name="SubversionTasks" basedir="." default="help">
<!-- Date: 2006-04-27
Developer: Craig Caulfield
Description: some basic Subversion operations that are executed
when required as part of a CruiseControl build loop. -->
<!-- These incoming parameters are set as properties (-Dname=value)
when this build file is invoked. -->
<fail message="svn.repository.URL parameter must be set."
unless="svn.repository.URL"/>
<fail message="svn.repository.name parameter must be set."
unless="svn.repository.name"/>
<fail message="svn.repository.subproject parameter must be set."
unless="svn.repository.subproject"/>
<!-- An optional parameter: svn.copy.type will be either tags or
branches. Set to BLANK by default. -->
<property name="svn.copy.type" value="BLANK"/>
<property name="checkout.dir" value="checkout/${svn.repository.subproject}"/>
<tstamp>
<format property="copy.message.date" pattern="yyyy-MM-d hh:mm aa"/>
<format property="copy.file.date" pattern="yyyyMMdhhmm"/>
</tstamp>
<!-- -->
<target name="help" description="Describes the basic usage of this
build file.">
<echo message="Executes some basic Subversion commands (currently
update and copy) when required by a controlling CruiseControl
build loop."/>
<echo message="Usage: ant [ant options]
-Dsvn.repository.URL=value -Dsvn.repository.name=value
-Dsvn.repository.subproject=value [svn-update | svn-copy]"/>
<echo message=" "/>
<echo message=" svn.repository.URL
For example, http://snagglepuss/svn"/>
<echo message=" svn.repository.name
For example, DEVELOPER"/>
<echo message=" svn.repository.subproject
For example, SunDeveloper"/>
<echo message=" svn.copy.type
For example, tags OR branches (only needed for the svn-copy task)"/>
</target>
<target name="svn-update" description="Executes an SVN update operation.">
<!-- Make sure the checkout directory exists. -->
<condition property="verify.svn.command">
<available file="${checkout.dir}" type="dir"/>
</condition>
<fail message="ERROR: the update directory (${checkout.dir})
doesn't exist." unless="verify.svn.command"/>
<!-- Update the local working copy with the latest from SVN -->
<property name="svn.update.statement" value="update
${checkout.dir}"/>
<echo message="${svn.update.statement}"/>
<exec executable="svn">
<arg line="${svn.update.statement}"/>
</exec>
</target>
<target name="svn-copy" description="Create a branch or tag from
the current head revision.">
<condition property="valid.svn.copy.parameter">
<or>
<equals arg1="${svn.copy.type}" arg2="tags"/>
<equals arg1="${svn.copy.type}" arg2="branches"/>
</or>
</condition>
<fail message="ERROR: svn.copy.type = "${svn.copy.type}",
but this parameter must be either tags or branches."
unless="valid.svn.copy.parameter"/>
<!-- Create a branch or tag from the current head revision. -->
<property name="copy.from"
value="${svn.repository.URL}/${svn.repository.name}/ \
trunk/${svn.repository.subproject}"/>
<property name="copy.to"
value="${svn.repository.URL}/${svn.repository.name}/ \
${svn.copy.type}/${svn.repository.subproject}${copy.file.date}"/>
<property name="copy.message" value=""Successful build.
Copied by CruiseControl at ${copy.message.date}""/>
<property name="svn.copy.statement" value="copy ${copy.from}
${copy.to} --message ${copy.message}"/>
<echo message="${svn.copy.statement}"/>
<exec executable="svn">
<arg line="${svn.copy.statement}"/>
</exec>
</target>
<!-- Add any more Subversion commands below here. -->
</project>
|