You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Eric Fetzer <el...@yahoo.com> on 2009/08/11 22:52:07 UTC

If any one from list then

I'm not sure exactly how to write something and am looking for suggestions.  A break command for <for> would work (obviously I'm ok with antcontrib as well), but I don't think antcontrib has one.

Say I have a property ${myProp} that contains a comma delimited list, such as "a,w,x,z"

I need to do something based on a subset of those values such as:

    if myprop contains element a b c or d
            do something...
    endif

Is there a simple way to do this?  I can think of clumsy ways to do this with regex, but nothing that would make me warm and fuzzy inside...

Thanks,
Eric


      

Re: If any one from list then

Posted by Eric Fetzer <el...@yahoo.com>.
Very nice Francis, Thanks!  I like this MUCH better.




________________________________
From: Francis GALIEGUE <fg...@one2team.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Friday, August 14, 2009 10:09:44 AM
Subject: Re: If any one from list then

On Fri, Aug 14, 2009 at 18:01, Francis GALIEGUE<fg...@one2team.com> wrote:
> On Wed, Aug 12, 2009 at 18:48, Eric Fetzer<el...@yahoo.com> wrote:
>> 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)?
>>
>
> This is a solution.
>

Another solution, which is more clean, I think. It makes use of
ant-contrib's <foreach>.

With a little exercise, it can be easily generalized to n lists.

The <trycatch> would then be in the doit target, and fail at the first match.

<property name="outerlist" value="a,b,c"/>
<property name="innerlist" value="c,d,e"/>

<target name="doit">
    <foreach list="${outerlist}" param="outer" target="do-inner"
        inheritall="true"/>
</target>

<target name="do-inner">
    <for list="${innerlist}" param="inner">
        <sequential>
            <if>
                <equals arg1="${outer}" arg2="@{inner}"/>
                <then>
                    <sequential>
                        <echo message="Found match for ${outer}"/>
                    </sequential>
                </then>
            </if>
        </sequential>
    </for>
</target>

-- 

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


      

Re: If any one from list then

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Fri, Aug 14, 2009 at 18:01, Francis GALIEGUE<fg...@one2team.com> wrote:
> On Wed, Aug 12, 2009 at 18:48, Eric Fetzer<el...@yahoo.com> wrote:
>> 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)?
>>
>
> This is a solution.
>

Another solution, which is more clean, I think. It makes use of
ant-contrib's <foreach>.

With a little exercise, it can be easily generalized to n lists.

The <trycatch> would then be in the doit target, and fail at the first match.

<property name="outerlist" value="a,b,c"/>
<property name="innerlist" value="c,d,e"/>

<target name="doit">
    <foreach list="${outerlist}" param="outer" target="do-inner"
        inheritall="true"/>
</target>

<target name="do-inner">
    <for list="${innerlist}" param="inner">
        <sequential>
            <if>
                <equals arg1="${outer}" arg2="@{inner}"/>
                <then>
                    <sequential>
                        <echo message="Found match for ${outer}"/>
                    </sequential>
                </then>
            </if>
        </sequential>
    </for>
</target>

-- 

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: If any one from list then

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Aug 12, 2009 at 18:48, Eric Fetzer<el...@yahoo.com> wrote:
> 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)?
>

This is a solution.

Note that if you want to stop at the first match, then you can
surround the inner for with ant-contrib's <trycatch>, and do what is
needed in the <catch> block.

<property name="outerlist" value="a,b,c"/>
<property name="innerlist" value="c,d,e"/>

<target name="doit">
    <for list="${outerlist}" param="outer">
        <sequential>
            <for list="${innerlist}" param="inner">
                <sequential>
                    <if>
                        <equals arg1="@{outer}" arg2="@{inner}"/>
                        <then>
                            <sequential>
                                <echo message="Found match for @{outer}"/>
                            </sequential>
                        </then>
                    </if>
                </sequential>
            </for>
        </sequential>
    </for>
</target>


-- 

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: If any one from list then

Posted by Eric Fetzer <el...@yahoo.com>.
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 <el...@yahoo.com>
To: Ant Users List <us...@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 <Al...@sas.com>
To: Ant Users List <us...@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:fge@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<Al...@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
>> fge@one2team.com
>> 40 avenue Raymond Poincaré
>> 75116 Paris
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>> 


      

Re: If any one from list then

Posted by Eric Fetzer <el...@yahoo.com>.
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 <Al...@sas.com>
To: Ant Users List <us...@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:fge@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<Al...@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
>> fge@one2team.com
>> 40 avenue Raymond Poincaré
>> 75116 Paris
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>> 


      

RE: If any one from list then

Posted by Alec Fernandez <Al...@sas.com>.
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:fge@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<Al...@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
>> fge@one2team.com
>> 40 avenue Raymond Poincaré
>> 75116 Paris
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>> 


Re: If any one from list then

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Aug 12, 2009 at 10:05, Alec Fernandez<Al...@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
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: If any one from list then

Posted by Alec Fernandez <Al...@sas.com>.
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>





>> -----Original Message-----
>> From: Eric Fetzer [mailto:elstonkers@yahoo.com]
>> Sent: Tuesday, August 11, 2009 10:52 PM
>> To: Ant Users
>> Subject: If any one from list then
>> 
>> I'm not sure exactly how to write something and am looking for
>> suggestions.  A break command for <for> would work (obviously I'm ok
>> with antcontrib as well), but I don't think antcontrib has one.
>> 
>> Say I have a property ${myProp} that contains a comma delimited list,
>> such as "a,w,x,z"
>> 
>> I need to do something based on a subset of those values such as:
>> 
>>     if myprop contains element a b c or d
>>             do something...
>>     endif
>> 
>> Is there a simple way to do this?  I can think of clumsy ways to do
>> this with regex, but nothing that would make me warm and fuzzy
>> inside...
>> 
>> Thanks,
>> Eric
>> 
>> 
>> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org