Category Archives: ant-contrib

Ant ‘if’ with ‘equals’ doesn’t seem to be working

I'm running an Ant target in a Salesforce build.xml file. The target contains a task that loops through a list of strings separated by line endings in a .txt file (the 'metadata.types' variable in the code below references the .txt file, and I'm on Windows.)

One of the metatdata types in the list is 'CustomObject', so it should trigger the 'Sorting @{metadataType} buffer' echo statement below. However, it doesn't; it just skips through to the "i am at @{metadataType}" echo statement and prints out 'i am at CustomObject'.

What am I missing?

<for param="metadataType" list="${metadata.types}" delimiter="${line.separator}">
    <sequential>
        <local name="type"/>
        <echo level="warning" message="Hello @{metadataType}"/>
        <if>
            <equals arg1="@{metadataType}" arg2="CustomObject" />
            <then>
                <echo level="info" message="Sorting @{metadataType} buffer"/>
            </then>
            <else>
                <if>
                    <not>
                        <equals arg1="@{metadataType}" arg2=""/>
                    </not>
                    <then>
                        <echo level="warning" message="i am at @{metadataType}"/>
                        <xmltask sourcebuffer="pkgbuff" destbuffer="pkgbuff">
                            <insert path="/*[local-name()='Package']"><![CDATA[
                                <types>
                                    <name>@{metadataType}</name>
                                    <members>*</members>
                                </types> ]]>
                            </insert>
                        </xmltask>
                    </then>
                </if>
            </else>
        </if>
    </sequential>
</for>