When building cross-platform (different OS) sometimes we need to perform tasks that differ across OS families. This is rather simple to do with Ant-scripting. This is a skeleton structure for checking conditional-statements first and executing tasks.

<target name="start">
    <!-- do some initial stuff here if any... -->
</target>

<!-- Main task stuff here if any... -->

<!-- set the operating system test properties -->
<condition property="isMac">
    <os family="mac" />
</condition>

<condition property="isWindows">
    <os family="windows" />
</condition>

<condition property="isUnix">
    <os family="unix" />
</condition>

<!-- define the operating system specific targets -->
<target name="doMac" if="isMac">
    <echo message="Do the mac stuff" />
</target>

<target name="doWindows" if="isWindows">
    <echo message="Do the windows stuff" />
</target>

<target name="doUnix" if="isUnix">
    <echo message="Do the unix stuff" />
</target>

<target name="os_dependent_task" depends="doMac,doWindows,doUnix">
    <echo message="Execute task depending on OS family" />
</target>

<target name="final" depends="os_dependent_task, start" />

That’s all that it takes. Go Ant!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.