AFAIK there is no built-in condition. But writing conditions is easy - just implement org.apache.tools.ant.taskdefs.condition.Condition (contains only >>boolean eval() throws BuildException<<).
You get a reference to the actual project instance if you have a setProject(Project) method. This is done by the Ant runtime. You can implement this setter (and the holding variable) by yourself or by subclassing ProjectComponent. PC also gives you helper methods like getLocation() (location inside the buildfile) and log(...). Additional parameters are dynamically handled via setters like in tasks. A quick implementation of <hastarget> would be: import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.condition.Condition; public class HasTargetCondition implements Condition { // dynamically set by Ant runtime Project project; public void setProject(Project p) { project = p; } public Project getProject() { return project; } // target to check String target; public void setTarget(String t) { target = t; } //implements Condition public boolean eval() throws BuildException { if (target == null) { throw new BuildException("Must specify 'target' to test."); } return getProject().getTargets().containsKey(target); } } <typedef name="hastarget" classname="HasTargetCondition" classpath="."/> <condition property="x.onlyA.exists"> <hastarget target="onlyA"/> </condition> I am "working" on a <targetIsOverwritten> condition ... Jan >-----Ursprüngliche Nachricht----- >Von: Cyril Sagan [mailto:[EMAIL PROTECTED] >Gesendet: Montag, 17. September 2007 22:46 >An: user@ant.apache.org >Betreff: Query definition of target? > > >Our Ant build logic would be much cleaner if there was a way to >determine if a particular target was overriden. > >Does anyone know how to check for the existence/definition of a >specified target name? > >Ideally, we'd like to have something like this: > > <condition property="target.exists"> > <istargetdefined name="foo-target" /> > </condition> > >I searched all the resouces I know about and I can't find anything, I >thought I'd ask here before I research writing a custom <condition>. > >I'd appreciate any advice. Thanks. > >--Cyril > >ps. Yes, I realize that proper OO methodology says that I should never >have to do this, but Ant isn't exactly an object oriented language. > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]