OK, so here's how I did it.  It works at least...  Can anyone think of a better 
way (I think it's kind of ugly)?

<project default="main">
  <taskdef resource="net/sf/antcontrib/antlib.xml"/>
  <taskdef name="unset" classname="ise.antelope.tasks.Unset"/>
  <target name="main" description="Find if a single property is contained in a 
propertyList">
    <md.isInPropList var.propertyList="myDog,yourDog,hisDog,herDog" 
var.item="Dog"/>
    <echo>${isInList}</echo>
    <md.isInPropList var.propertyList="myDog,yourDog,hisDog,herDog" 
var.item="myDog"/>
    <echo>${isInList}</echo>
    <md.isInPropList var.propertyList="myDog,yourDog,hisDog,herDog" 
var.item="bigDog"/>
    <echo>${isInList}</echo>
  </target>
  <macrodef name="md.isInPropList" description="Find if a single property is 
contained in a propertyList">
    <attribute name="var.propertyList"/>
    <attribute name="var.item"/>
    <sequential>
      <!--First get rid of any values left from previous calls to this md-->
      <unset name="isInList"/>
      <unset name="regExResult"/>
      <!--Set var's with the delimiter around them so the search is true-->
      <var name="propertyList" value=",@{var.propertyList},"/>
      <var name="listItem" value=",@{var.item},"/>
      <!--Regex expression that will result in the value if it is in there-->
      <propertyregex property="regExResult"
        input="${propertyList}"
        override="true"
        regexp=".*(${listItem})"
        select="\1"
        casesensitive="true"
      />
      <!--If isInList is set to the value of the comma surrounded item, we have 
a match-->
      <if>
        <equals arg1="${regExResult}" arg2="${listItem}"/>
        <then>
          <property name="isInList" value="true"/>
        </then>
        <else>
          <property name="isInList" value="false"/>
        </else>
      </if>
    </sequential>
  </macrodef>
</project>





________________________________
From: Eric Fetzer <elstonk...@yahoo.com>
To: Ant Users List <user@ant.apache.org>
Sent: Wednesday, August 12, 2009 9:46:09 AM
Subject: Re: If any one from list then

The only think I can come up with is to write a macrodef that is passed a 
propertyName and a value to be search if it is contained within:

1)  Take the list and add a , to the beginning and , to the end
2)  Do a regex on ",${searchString},"

If it's there, the item is contained within the list, set a property to 
"true"...




________________________________
From: Alec Fernandez <alec.fernan...@sas.com>
To: Ant Users List <user@ant.apache.org>
Sent: Wednesday, August 12, 2009 5:28:51 AM
Subject: RE: If any one from list then

Excellent point.

Delimiting the items in the list may be necessary.  Unfortunately, there is not 
a containsregexp condition to help with separating the values from the 
delimiters and boundaries.

Scriptcondition might be a better alternative if you have the bsf.jar and a 
supported language


>> -----Original Message-----
>> From: Francis GALIEGUE [mailto:f...@one2team.com]
>> Sent: Wednesday, August 12, 2009 1:12 PM
>> To: Ant Users List
>> Subject: Re: If any one from list then
>> 
>> On Wed, Aug 12, 2009 at 10:05, Alec Fernandez<alec.fernan...@sas.com>
>> wrote:
>> > After spending 2 days convincing myself that there was a problem
>> with the <different> selector only to discover that my diff tool was
>> lying and that one of the files was indeed different (unix line ends
>> versus pc line ends so my editor was deceiving me too), I'm feeling
>> the need to respond :-)
>> >
>> > I think the condition task is what you are after.
>> >
>> > <condition>
>> >  <or>
>> >    <contains string="${myprop}" substring="foo" />
>> >    <contains string="${myprop}" substring="foo2" />
>> >  </or>
>> > </condition>
>> >
>> 
>> The problem is that if you want "foo" and the list is "foobar, baz",
>> the condition will match.
>> 
>> This is not an easy problem, admittedly. It could be done with two
>> imbricated <foreach> statements, but that would be an O(n^2)
>> algorithm. It may, or may not, be a problem, depending on the problem
>> size.
>> 
>> --
>> 
>> Francis Galiegue
>> ONE2TEAM
>> Ingénieur système
>> Mob : +33 (0) 683 877 875
>> Tel : +33 (0) 178 945 552
>> f...@one2team.com
>> 40 avenue Raymond Poincaré
>> 75116 Paris
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
>> For additional commands, e-mail: user-h...@ant.apache.org
>> 


      

Reply via email to