tags:

views:

34

answers:

2

Say I'd like to set some variables if the name of an ant's target contains certain words. Is this possible? Can I obtain the current executed target's name?

EDIT: I tried running ant with -d, and I noticed an environment variable TEMP_A which seems to hold the current target's name. I wonder, will this work across different ant versions?

+2  A: 

If you need that information during the build, then you should always be able to determine the target name because most of the time you're inside a target. So one could add a line of code to the target body that sets the property/ies according to the name. That would be the pure manual approach.

Maybe you want some kind of general (custom) task, say a line of code that can be copied to any target and determines the current target name. I don't know of a build in property that provides this name. But if you write a custom task and subclass org.apache.tools.ant.Task then you may be able to get the name of the 'parent' target and build the property.

(If apache had published the API on the web then I'd been able to give a more precise answer...)

EDIT

It could be possible from outside. One can implement a listener and attach it to ant. So the listener would get notified when a target is entered. But the problem could be to change a property 'inside' ant. I don't know actually if this listener 'lives' in the same VM as the ant thread.

Andreas_D
I need to do this before a certain task has been executed.
Geo
+1  A: 

There is no built-in property for the current executing target name. This is apparently by design; the property was present in an earlier version of Ant but was removed to avoid potential abuse.

Check out this question: Print/Access the Name of the Currently Executing Ant Target

Also, see the discussion in this email thread by the Ant creators: link text

Tom Tresansky