ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Implicit element for macrodef
Date Wed, 26 May 2004 08:23:29 GMT
Michael Sunde wrote:

>Hi,
>
>This is a feature that I have been waiting for. Thanks.
>
>
>There is one other issue with macrodef that has been bothering me a
>little. The issue comes up when I compare macrodef to scriptdef.
>Scriptdef has a type attribute on the elements which makes the usage of
>the script cleaner:
>
>  <scriptdef name="scripttest2" language="javascript">
>    <element name="files" type="fileset"/>
>    <![CDATA[
>    // do something with files
>    ]]>
>  </scriptdef>
>
>  <scripttest2>
>    <files dir="src"/>
>    <files dir="main"/>
>  </scripttest2>
>
>Since macrodef does not have a type attribute, the usage would look
>something like:
>
>  <processFilesMacro>
>    <files>
>      <fileset dir="src"/>
>      <fileset dir="main"/>
>    </files>
>  </processFilesMacro>
>
>Notice the extra 'files' element. Would it be possible to add an
>optional type attribute to the element declarations in macrodef so that
>the syntax would look something like:
>
>  <macrodef name="processFilesMacro">
>    <element name="files" type="fileset"/>
>    <sequential>
>      <copy todir="dir">
>        <files/>
>      </copy>
>    </sequential>
>  </macrodef>
>
>  <processFilesMacro>
>    <files dir="src"/>
>    <files dir="main"/>
>  </processFilesMacro>
>  
>
I am not too sure that this would be possible with macrodef. Macrodef
does not look at the types of the nested elements, it simply copies the
parsed trees of elements before they are resolved into 
tasks/types/nested-elements.

With the implicit addition to macrodef the example above may be written as:

<macrodef name="processFilesMacro">
    <element name="files" implicit="true"/>
    <sequential>
       <copy todir="dir">
          <files/>
       </copy>
    </sequential>
</macrodef>

<processFilesMacro>
    <fileset dir="src"/>
    <fileset dir="main"/>
</processFilesMacro>

Peter

>Shall I log an enhancement request?
>
>So far, macrodef has been very useful in my build files.
>
>Thanks,
>Michael
>
>-----Original Message-----
>From: Dominique Devienne [mailto:DDevienne@lgc.com] 
>Sent: Tuesday, May 25, 2004 10:20 AM
>To: 'Ant Developers List'
>Subject: RE: Implicit element for macrodef
>
>  
>
>>From: Peter Reilly [mailto:peter.reilly@corvil.com]
>>
>>I am looking into an implementation of implicit nested elements for
>>macrodef:
>>    
>>
>
>Cool.
>
>  
>
>>    <showfiles property="x">
>>      <fileset dir="." includes="*.xml"/>
>>    </showfiles>
>>  </target>
>>
>>The implementation does however involve a small Backward Incompatible
>>change to the implementation of MacroInstance.
>>    
>>
>
>I'd say this is young enough that the benefits outweigh the drawbacks.
>
>Own would implicit elements interact with nested macros, each having
>an implicit element?
>
>I personally have one request for <macrodef>: Is it possible to
>determine whether an element or attribute was set in the macro
>instance? Here is my use case: I have a macro that performs several
>tasks, each of them using a different element of the macro. If one
>of those elements is not specified in a macro instance, I'd like
>to completely skip the corresponding macro task (use <ac:if> or a
>builtin condition on that task). Currently, I have to define on
>additional attribute on the macro to turn ON the execution of a
>task, when the mere presence of the element for that task is enough
>to determine whether it should run or not. Maybe something like:
>
><macrodef name="...">
>  <element name="schemas" optional="yes" />
>  <attribute name="jaxb" default="@?schemas?" />
>  ...
>  <sequential>
>    <jaxb ... ifTrue="@{jaxb}">
>      <schemas>
>    </jaxb>
>    ...
>  </sequential>
></macrodef>
>
>The @?element? is purely arbitrary, and just to illustrate my point.
>I guess I can get by with the attribute/element twins, but I'm just
>wondering if there's a way to basically discover info on the macro
>instance itself, and put it to some use, as above.
>
>Thanks, --DD
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>  
>


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


Mime
View raw message