git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@386065 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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>"); | |||
| + "condition into " | |||
| + getTaskName()); | |||
| } | |||
| if (countConditions() < 1) { | |||
| throw new BuildException("You must nest a condition into " | |||
| + "<condition>"); | |||
| + getTaskName()); | |||
| } | |||
| if (property == null) { | |||
| throw new BuildException("The property attribute is required."); | |||
| @@ -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, | |||
| * <code>processSuccess</code> and <code>processTimeout</code> | |||
| * @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 <code>long</code> 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 <waitfor>"); | |||
| + "condition into " | |||
| + getTaskName()); | |||
| } | |||
| if (countConditions() < 1) { | |||
| throw new BuildException("You must nest a condition into " | |||
| + "<waitfor>"); | |||
| + 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 | |||
| @@ -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 <code>null</code>. | |||
| * @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); | |||