I've got an ant build script which I should modify. Specifically I should make a subversion checkout conditional: currently only the trunk gets checked out, the new version should checkout a given branch if needed.
<target name="do-svn-checkout" depends="init"
<property name="branch" value=""/>
<exec executable="svn">
<arg value="checkout"/>
<arg value="-r"/>
<arg value="HEAD"/>
<arg value="http://t01/java/trunk"/>
<arg value="zzz"/>
<arg value="--password"/>
<arg value="xxx"/>
<arg value="--username"/>
<arg value="yyy"/>
</exec>
</target>
The property branch
will be set via the command line like for instance -Dbranch=mybranch
.
If the property branch
is empty, the trunk should be checked out, but if the property has any other value, the respective branch should be checked out, like http://t01/svn/hlfg/HLFG/java/branch/the-value-of-the-property
. So depending on the property the respective arg-value of the svn
call should be modified.
Is it possible to solve this with basic Ant or would I need to use an inline script?
You could define a wrapper target which depends on two other targets - one of which does trunk checkout, the other of which does branch checkout - and each of which is conditional on existence of your optional branch property.
You could further abstract the exec call into a macrodef to which you pass the trunk or branch url.
For example:
Output with no branch property defined:
Output with branch property defined:
When using Ant >= 1.9.3 it's a piece of cake with the new if/unless feature introduced with Ant 1.9.1 (but you should at least use Ant 1.9.3 because of bugs in Ant 1.9.1, see this answer for details)
Don't forget the namespaces to activate that feature, f.e. :
in your case something like :