ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r386065 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs: ConditionTask.java WaitFor.java condition/ConditionBase.java
Date Wed, 15 Mar 2006 13:01:14 GMT
Author: stevel
Date: Wed Mar 15 05:01:10 2006
New Revision: 386065

URL: http://svn.apache.org/viewcvs?rev=386065&view=rev
Log:
Adding some low level diagnostics for waitfor, calling the processSucess and processTimeout
methods at appropriate times

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/WaitFor.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java?rev=386065&r1=386064&r2=386065&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java Wed Mar 15 05:01:10
2006
@@ -43,6 +43,10 @@
     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 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.");

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/WaitFor.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/WaitFor.java?rev=386065&r1=386064&r2=386065&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/WaitFor.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/WaitFor.java Wed Mar 15 05:01:10
2006
@@ -19,6 +19,7 @@
 
 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 @@
  * 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 @@
     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 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 @@
 
             while (System.currentTimeMillis() < end) {
                 if (c.eval()) {
+                    processSuccess();
                     return;
                 }
                 try {
@@ -130,12 +139,33 @@
                 }
             }
 
-            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");
         }
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java?rev=386065&r1=386064&r2=386065&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java Wed
Mar 15 05:01:10 2006
@@ -32,9 +32,36 @@
  * @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.
      *
      * @return the number of conditions in the container
@@ -55,6 +82,27 @@
     }
 
     /**
+     * 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 &lt;available&gt; condition.
      * @param a an available condition
      * @since 1.1
@@ -216,6 +264,7 @@
     /**
      * Add an &lt;typefound&gt; condition.
      * @param test a TypeFound condition
+     * @since Ant 1.7
      */
     public void addTypeFound(TypeFound test) {
         conditions.addElement(test);
@@ -242,6 +291,7 @@
      * Add an &lt;isreachable&gt; condition.
      *
      * @param test the condition
+     * @since Ant 1.7
      */
     public void addIsReachable(IsReachable test) {
         conditions.addElement(test);
@@ -251,6 +301,7 @@
      * Add an &lt;issigned&gt; condition.
      *
      * @param test the condition
+     * @since Ant 1.7
      */
     public void addIsSigned(IsSigned test) {
         conditions.addElement(test);
@@ -260,6 +311,7 @@
      * Add an &lt;parsersupports&gt; condition.
      *
      * @param test the condition
+     * @since Ant 1.7
      */
     public void addParserSupports(ParserSupports test) {
         conditions.addElement(test);
@@ -269,6 +321,7 @@
      * Add a &lt;ResourcesMatch&gt; condition.
      *
      * @param test the condition
+     * @since Ant 1.7
      */
     public void addResourcesMatch(ResourcesMatch test) {
         conditions.addElement(test);
@@ -279,6 +332,7 @@
      * Add an &lt;xor&gt; condition.
      *
      * @param test the condition
+     * @since Ant 1.7
      */
     public void addXor(Xor test) {
         conditions.addElement(test);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message