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 ?
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 ?
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.
The task name is always output to console by Ant:
Here is 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 is the output:
C:\tmp\ant>ant
Buildfile: c:\tmp\ant\build.xml
mytask-silent:
mytask-echo:
[echo] processing
test:
BUILD SUCCESSFUL
Total time: 0 seconds
The only way I know it do this is to write an ANT task or use a groovy script as follows:
<target name="mytask" depends="init">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
println "processing ${target}"
</groovy>
</target>