Alexander Abramovich
Alexander Abramovich

Reputation: 11438

Conditional concatenation in Ant

I have a task like:

<target name="someTarget">
    <concat destfile="someFile">
        <string>someString</string>

        <string>someOtherString</string>
    </concat>
</target>

<target name="someOtherTarget">
    <antcall target="someTarget">
        <param name="myParam" value="myValue"></param>
    </antcall>

    <antcall target="someTarget">
    </antcall>
</target>

How can I concatenate the someOtherString only if myParam was supplied when calling the someTarget target?

Upvotes: 2

Views: 996

Answers (1)

creemama
creemama

Reputation: 6665

Without Ant extensions, just use conditional Ant execution:

<project default="someOtherTarget">
    <target name="someTarget" depends="-someString,-someOtherString"/>

    <target name="-someString" unless="myParam">
        <concat destfile="someFile">
            <string>someString</string>
        </concat>
    </target>

    <target name="-someOtherString" if="myParam">
        <concat destfile="someOtherFile">
            <string>someString</string>
            <string>someOtherString</string>
        </concat>
    </target>

    <target name="someOtherTarget">
        <antcall target="someTarget">
            <param name="myParam" value="myValue"></param>
        </antcall>
        <antcall target="someTarget"/>
    </target>
</project>

If you don't mind adding Ant extensions to your project, check out Ant-Contrib's If task.

Upvotes: 4

Related Questions