You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Davy Toch <Da...@belgacom.net> on 2005/09/13 19:20:11 UTC

Scoped variables in macrodefs using entity includes.

Just wanted to share our (temporary) solution we currently use to have 
scoped variables in macrodefs. Not ideal, but it currently works.

build.xml:

<?xml version='1.0'?>
<!DOCTYPE project [
  <!ENTITY uid "be.steria.ant.addon.0.3.base">
]>
<project basedir="." name="&uid;" default="test">

  <import file="macrodef.xml"/>

  <target name="test">
    <property name="&uid;.test" value="zzz"/>
    <echo>&uid;.test : ${&uid;.test}</echo>
    <test-macrodef test="${&uid;test}"/>
  </target>

</project>

macrodef.xml

<?xml version='1.0'?>
<!DOCTYPE project [
  <!ENTITY uid "be.steria.ant.addon.0.3.test">
]>
<project basedir="." name="&uid;">

  <macrodef name="test-macrodef">
    <attribute name="test"/>
    <sequential>
      <property name="&uid;.test" value="yyy"/>
      <echo>&uid;.test : ${&uid;.test}</echo>
    </sequential>
  </macrodef>

</project>

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


Re: Scoped variables in macrodefs using entity includes.

Posted by Dominique Devienne <dd...@gmail.com>.
I don't see how this really helps, I'm sorry ;-)

The problem is when you invoke *several times* a macrodef that uses
<property> internally. You would need to use a different prefix (that
what your entity is equivalent to) for the different runs of the same
macro to use different property names.

Which is why the 'canonical' work-around is to base the name of the
<property>s used on some likely-to-be-unique param of the macro
itself, and do ${@{param}suffix} to reference the 'internal' property.

One could also of course have the macro require an extra param to be
used as the uniq key or prefix to be used by internal properties, but
that's pushing on a client of the macro something she shouldn't be
aware of. --DD

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