processing ${blabla} pr...">

ANT - get the current task name

How can an ANT task like this:

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

      

print processing mytask

?

What should I replace blabla

with? Or is it even possible?

+3


source to share


3 answers


This might work for you with vanilla Ant if your version is recent enough to enable 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>

      



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.

+3


source


The task name is always printed to the console using Ant:

Here's an example:

<project default="test">

    <target name="test" depends="mytask-silent, mytask-echo"/>

    <target name="mytask-echo">
        <echo>processing</echo>
    </target>

    <target name="mytask-silent"/>

</project>

      



Here's the result:

C:\tmp\ant>ant
Buildfile: c:\tmp\ant\build.xml

mytask-silent:

mytask-echo:
     [echo] processing

test:

BUILD SUCCESSFUL
Total time: 0 seconds

      

0


source


The only way I know is to write an ANT task or use a groovy script like this:

<target name="mytask" depends="init">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <groovy>
        println "processing ${target}"
    </groovy>
</target>

      

0


source







All Articles