diff --git a/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java b/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java index 6d472a231..60b23b97e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java @@ -43,6 +43,10 @@ public class ConditionTask extends ConditionBase { private String value = "true"; private String alternative = null; + public ConditionTask() { + super("condition"); + } + /** * The name of the property to set. Required. * @param p the name of the property @@ -81,11 +85,12 @@ public class ConditionTask extends ConditionBase { public void execute() throws BuildException { if (countConditions() > 1) { throw new BuildException("You must not nest more than one " - + "condition into "); + + "condition into " + + getTaskName()); } if (countConditions() < 1) { throw new BuildException("You must nest a condition into " - + ""); + + getTaskName()); } if (property == null) { throw new BuildException("The property attribute is required."); diff --git a/src/main/org/apache/tools/ant/taskdefs/WaitFor.java b/src/main/org/apache/tools/ant/taskdefs/WaitFor.java index 8a7d7e330..0b8935675 100644 --- a/src/main/org/apache/tools/ant/taskdefs/WaitFor.java +++ b/src/main/org/apache/tools/ant/taskdefs/WaitFor.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs; import java.util.Hashtable; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.condition.Condition; import org.apache.tools.ant.taskdefs.condition.ConditionBase; import org.apache.tools.ant.types.EnumeratedAttribute; @@ -42,6 +43,8 @@ import org.apache.tools.ant.types.EnumeratedAttribute; * The maxwaitunit and checkeveryunit are allowed to have the following values: * millisecond, second, minute, hour, day and week. The default is millisecond. * + * For programmatic use/subclassing, there are two methods that may be overrridden, + * processSuccess and processTimeout * @since Ant 1.5 * * @ant.task category="control" @@ -55,6 +58,10 @@ public class WaitFor extends ConditionBase { private long checkEveryMultiplier = 1L; private String timeoutProperty; + public WaitFor() { + super("waitfor"); + } + /** * Set the maximum length of time to wait. * @param time a long value @@ -103,11 +110,12 @@ public class WaitFor extends ConditionBase { public void execute() throws BuildException { if (countConditions() > 1) { throw new BuildException("You must not nest more than one " - + "condition into "); + + "condition into " + + getTaskName()); } if (countConditions() < 1) { throw new BuildException("You must nest a condition into " - + ""); + + getTaskName()); } Condition c = (Condition) getConditions().nextElement(); @@ -121,6 +129,7 @@ public class WaitFor extends ConditionBase { while (System.currentTimeMillis() < end) { if (c.eval()) { + processSuccess(); return; } try { @@ -130,15 +139,36 @@ public class WaitFor extends ConditionBase { } } - if (timeoutProperty != null) { - getProject().setNewProperty(timeoutProperty, "true"); - } + processTimeout(); } finally { maxWaitMillis = savedMaxWaitMillis; checkEveryMillis = savedCheckEveryMillis; } } + /** + * Actions to be taken on a successful waitfor. + * This is an override point. The base implementation does nothing. + * @since Ant1.7 + */ + protected void processSuccess() { + log(getTaskName()+": condition was met", Project.MSG_VERBOSE); + } + + /** + * Actions to be taken on an unsuccessful wait. + * This is an override point. It is where the timeout processing takes place. + * The base implementation sets the timeoutproperty if there was a timeout + * and the property was defined. + * @since Ant1.7 + */ + protected void processTimeout() { + log(getTaskName() +": timeout", Project.MSG_VERBOSE); + if (timeoutProperty != null) { + getProject().setNewProperty(timeoutProperty, "true"); + } + } + /** * The enumeration of units: * millisecond, second, minute, hour, day, week diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java b/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java index 4db85f0ee..61051f9b1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java @@ -32,8 +32,35 @@ import org.apache.tools.ant.taskdefs.UpToDate; * @since Ant 1.4 */ public abstract class ConditionBase extends ProjectComponent { + + + /** + * name of the component + */ + private String taskName="condition"; + + /** + * + */ private Vector conditions = new Vector(); + /** + * simple constructor. + */ + protected ConditionBase() { + taskName = "component"; + } + + /** + * constructor that takes the name of the task + * in the task name + * @param taskName + * @since Ant1.7 + */ + protected ConditionBase(String taskName) { + this.taskName = taskName; + } + /** * Count the conditions. * @@ -54,6 +81,27 @@ public abstract class ConditionBase extends ProjectComponent { return conditions.elements(); } + /** + * Sets the name to use in logging messages. + * + * @param name The name to use in logging messages. + * Should not be null. + * @since Ant 1.7 + */ + public void setTaskName(String name) { + this.taskName = name; + } + + /** + * Returns the name to use in logging messages. + * + * @return the name to use in logging messages. + * @since Ant 1.7 + */ + public String getTaskName() { + return taskName; + } + /** * Add an <available> condition. * @param a an available condition @@ -216,6 +264,7 @@ public abstract class ConditionBase extends ProjectComponent { /** * Add an <typefound> condition. * @param test a TypeFound condition + * @since Ant 1.7 */ public void addTypeFound(TypeFound test) { conditions.addElement(test); @@ -242,6 +291,7 @@ public abstract class ConditionBase extends ProjectComponent { * Add an <isreachable> condition. * * @param test the condition + * @since Ant 1.7 */ public void addIsReachable(IsReachable test) { conditions.addElement(test); @@ -251,6 +301,7 @@ public abstract class ConditionBase extends ProjectComponent { * Add an <issigned> condition. * * @param test the condition + * @since Ant 1.7 */ public void addIsSigned(IsSigned test) { conditions.addElement(test); @@ -260,6 +311,7 @@ public abstract class ConditionBase extends ProjectComponent { * Add an <parsersupports> condition. * * @param test the condition + * @since Ant 1.7 */ public void addParserSupports(ParserSupports test) { conditions.addElement(test); @@ -269,6 +321,7 @@ public abstract class ConditionBase extends ProjectComponent { * Add a <ResourcesMatch> condition. * * @param test the condition + * @since Ant 1.7 */ public void addResourcesMatch(ResourcesMatch test) { conditions.addElement(test); @@ -279,6 +332,7 @@ public abstract class ConditionBase extends ProjectComponent { * Add an <xor> condition. * * @param test the condition + * @since Ant 1.7 */ public void addXor(Xor test) { conditions.addElement(test);