tags:

views:

26

answers:

1

I'm trying to add an excludes list to my ant build script. I have a property (lets call it build.excludes) which looks something like this:

build.excludes=MyApp,AnotherApp

in my build script I have an if statement similar to the following:

<for list="${appsList}" delimiter="" trim="true" param="currentApp" keepgoing="yes">
    <sequential>
        <if>
         <!-- check if my current build item is in the build.excludes list -->
            <then>
                <!-- build of a project happens here -->
            </then>
        </if>
    </sequential>
</for>

The only way I can think of doing it is to have a for loop to iterate over my build.excludes list and then do something (but I don't know where to put this for loop... perhaps in a macro?).

Thanks!

EDIT: Ant 1.6.5 and can't upgrade.

A: 

Looks like you're using the ant-contrib for task. if supports the same elements as the ant condition task, which has been around long enough to be in version 1.6.5.

Here's an example:

<property name="build.excludes" value="MyApp,AnotherApp" />
<property name="appsList" value="MyApp,ExtraApp" />

<for list="${appsList}" delimiter="," trim="true" param="currentApp" keepgoing="yes">
    <sequential>
        <echo message="Checking @{currentApp}" />
        <if>
        <not>
            <contains string=",${build.excludes}," substring=",@{currentApp}," />
        </not>
        <then>
            <echo message="Building @{currentApp}" />
        </then>
        <else>
            <echo message="Not Building @{currentApp} - excluded" />
        </else>
        </if>
    </sequential>
</for>

Gives:

 [echo] Checking MyApp
 [echo] Not Building MyApp - excluded
 [echo] Checking ExtraApp
 [echo] Building ExtraApp
martin clayton