You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Scott Simpson <ss...@local.com> on 2007/05/05 01:45:34 UTC

Can ant macrodef expand attributes?

I want a macro to expand to an attribute or not depending on whether the
value is an empty string or not. Suppose I have the following script:
 
<?xml version="1.0"?>
<!DOCTYPE project []>
<project name="foo" default="foo">
  <macrodef name="foomac">
    <attribute name="attr"/>
    <sequential>
    <echo @{attr}>Running macro</echo>
    </sequential>
  </macrodef>
 
  <target name="foo">
    <foomac attr="file=&quot;bar&quot;"/>
  </target>
</project>

I want to optionally include an attribute to the <echo> element if the
parameter is given as the non-empty string (I'm not really doing this
with <echo>. This is an example).
 
Any other way to do this? Macros seem great for optionally including
elements and parts of strings but not so great for attributes.