Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

macrodef versus script versus javascript

Tags:

javascript

ant

I want to create a task defined by a macrodef within a script element. I was hoping to find that there would be 'set' functions corresponding to each attribute. No such luck. Is there some other API for specifying the attributes?

 var statustask = project.createTask("service-status");
 statustask.setPath(project.getProperty("path"));
 statustask.setStatusproperty("status");
 statustask.setTimeout=("1"); // this isn't suppose to take a long time.
 statustask.perform();
like image 706
bmargulies Avatar asked Oct 27 '11 16:10

bmargulies


1 Answers

You can probably achieve what you want using methods of the MacroInstance (a subclass of Task) you'll get from the createTask method for a macro. This:

<macrodef name="my.macro">
    <attribute name="attr1" default="NOT SET"/>
    <sequential>
        <echo message="attr1=@{attr1}" />
    </sequential>
</macrodef>

<script language="javascript"><![CDATA[
    var macro = project.createTask( "my.macro" );
    macro.setDynamicAttribute( "attr1", "value_1" );
    macro.execute();
]]></script>

Produces this when run:

[echo] attr1=value_1
like image 81
martin clayton Avatar answered Sep 28 '22 05:09

martin clayton