Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT - retrieving the current task name [duplicate]

How can an ANT task like this one:

<target name="mytask">
  <echo>processing ${blabla}</echo>
</target>

print processing mytask ?

What should I replace blabla with ? Or this is actually even possible ?

like image 415
Display Name Avatar asked Sep 06 '25 17:09

Display Name


1 Answers

This might work for you with vanilla Ant, if your version is recent enough to include javascript support.

<scriptdef name="currenttarget" language="javascript">
    <attribute name="property"/>
    <![CDATA[
    importClass( java.lang.Thread );

    project.setProperty(
        attributes.get( "property" ),
        project.getThreadTask(
            Thread.currentThread( ) ).getTask( ).getOwningTarget( ).getName( ) );
    ]]>
</scriptdef>

<target name="foobar">
    <currenttarget property="my_target" />
    <echo message="${my_target}" />
</target>

The scriptdef sets up a task currenttarget that can be used to get the current target in a property, which you can then use as you see fit.

like image 122
martin clayton Avatar answered Sep 09 '25 02:09

martin clayton