You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Sagi Mann <sa...@gmail.com> on 2008/12/10 19:07:25 UTC

AntX: $map example from guide fails when key is missing?

Hi all,
I'm trying to adopt example #2 from the $map URI guide:
http://antxtras.sourceforge.net/AntXtras/docs/userguide/valueuris/map.html
http://antxtras.sourceforge.net/AntXtras/docs/userguide/valueuris/map.html 

like so:
For each property in the 'p1' set, I print the value of the same property in
set 'p2'. For testing purposes, I print this TWICE: once by directly
echoing:
${$map:xxx?@(key)} 
and second by assigning the values to variables first, then echo the
variables:

<ax:foreach i="key" list="${$map:p1?keys}" mode="local">
		<echo message="prop ${key}: expected=${$map:p1?@(key)}
existing=${$map:p2?@(key)}"/>
		<ax:assign name="expected" value="${$map:p1?@(key)}"/>
		<ax:assign name="existing" value="${$map:p2?@(key)}"/>
		<echo message="prop ${key} values: expected=${$var:expected}
existing=${$var:existing}"/>
</ax:foreach>

If p1 and p2 contain the same property keys, all is ok. If p1 contains a
property that does NOT exist in p2, the first echo is ok and displays (as it
should):
prop myprop: expected=1 existing=${$map:p2?@(key)}
But the second assign fails with the error:
Syntax error in property: ${key

I need to be able to assign the result to variables (or use it in a domatch
value attribute, which generates the same error). Does someone has any idea
why this does not work properly?

thanks.
-- 
View this message in context: http://www.nabble.com/AntX%3A-%24map-example-from-guide-fails-when-key-is-missing--tp20940737p20940737.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: AntX: $map example from guide fails when key is missing?

Posted by Sagi Mann <sa...@gmail.com>.
Hi, I was unable to get your script to work.
the echo message was literally showing the $prop URI.

the script:

<ax:properties id="p1">
   <ax:property name="prop1" value="xxx"/>
</ax:properties>
<ax:foreach i="key" list="${$map:p1?keys}" mode="local">
   <echo>
   ${key}: p1='${$prop:p1->@(key)}'
   </echo>
</ax:foreach>

the output:

prop1: p1='${$prop:p1->@(key)}'


so I'm still stuck :-)
any ideas?
thanks...

-- 
View this message in context: http://www.nabble.com/AntX%3A-%24map-example-from-guide-fails-when-key-is-missing--tp20940737p21056607.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: AntX: $map example from guide fails when key is missing?

Posted by Wascally Wabbit <wa...@earthling.net>.
Hi Sagi,

A couple of things:
  1) Try using ${$prop:p1->@(key)} inside the loop instead of $map:
     Less overhead and a bit clearer.
  2) In AntXtras 0.5.x you cannot assign an empty string to a var
     (this is fixed in AntXtras 2.0.0 but that's still in alpha)
     So if the key does not exist in p2, you need a dummy marker
     string like 'MISSING' or something.

I don't completely understand what you're trying to do...but here
is some reworked example script for AntX 0.5.1:

<t:foreach i="key" list="${$map:p1?keys}" mode="local">
   <echo>
   ${key}: p1='${$prop:p1->@(key)}'; p2='${$prop:p2->@(key)?}'"
   </echo>
   <t:assign var="existing" value="${$prop:p2->@(key)?MISSING}"/>
   <t:domatch variable="existing">
     <t:equals value="MISSING"/>
     <t:otherwise>
       [Do you processing here...]
     </t:otherwise>
   </t:domatch>
</t:foreach>


HTH,
The Wabbit

Sagi Mann wrote:
> Hi all,
> I'm trying to adopt example #2 from the $map URI guide:
> http://antxtras.sourceforge.net/AntXtras/docs/userguide/valueuris/map.html
> http://antxtras.sourceforge.net/AntXtras/docs/userguide/valueuris/map.html 
> 
> like so:
> For each property in the 'p1' set, I print the value of the same property in
> set 'p2'. For testing purposes, I print this TWICE: once by directly
> echoing:
> ${$map:xxx?@(key)} 
> and second by assigning the values to variables first, then echo the
> variables:
> 
> <ax:foreach i="key" list="${$map:p1?keys}" mode="local">
> 		<echo message="prop ${key}: expected=${$map:p1?@(key)}
> existing=${$map:p2?@(key)}"/>
> 		<ax:assign name="expected" value="${$map:p1?@(key)}"/>
> 		<ax:assign name="existing" value="${$map:p2?@(key)}"/>
> 		<echo message="prop ${key} values: expected=${$var:expected}
> existing=${$var:existing}"/>
> </ax:foreach>
> 
> If p1 and p2 contain the same property keys, all is ok. If p1 contains a
> property that does NOT exist in p2, the first echo is ok and displays (as it
> should):
> prop myprop: expected=1 existing=${$map:p2?@(key)}
> But the second assign fails with the error:
> Syntax error in property: ${key
> 
> I need to be able to assign the result to variables (or use it in a domatch
> value attribute, which generates the same error). Does someone has any idea
> why this does not work properly?
> 
> thanks.


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