Friday, 1 October 2010

Ant Conditional Property

Defining a new Ant task with a conditional property:

This is a way of doing 'ifs' with Ant.

<macrodef name="copy-and-filter">
    <attribute name="sys"/>
    <attribute name="target"/>
    <attribute name="source"/>
      <condition property="myProp" value="JUST1">
        <equals arg1="@{sys}" arg2="MySystem"/>
      <condition property="myProp" value="NOT1">
        <equals arg1="@{sys}" arg2="SomeOtherSystem"/>
      <copy tofile="@{target}" file="@{source}">
        <filterset onmissingfiltersfile="ignore" recurse="true">
          <filter token="replaceThis" value="${myProp}"/>
          <filtersfile file="myfilters/filterFile@{sys}.properties"/>

The conditional property myProp will be set depending on the values of the @sys@ attribute passed in.

All filters in the file: filtersFile@sys@ so you can specify a different file for each sys property.

No comments:

Post a Comment