ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r593020 - /ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/Retry.java
Date Thu, 08 Nov 2007 05:42:55 GMT
Author: kevj
Date: Wed Nov  7 21:42:53 2007
New Revision: 593020

URL: http://svn.apache.org/viewvc?rev=593020&view=rev
Log:
-use StringUtils

Modified:
    ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/Retry.java

Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/Retry.java
URL: http://svn.apache.org/viewvc/ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/Retry.java?rev=593020&r1=593019&r2=593020&view=diff
==============================================================================
--- ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/Retry.java (original)
+++ ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/Retry.java Wed
Nov  7 21:42:53 2007
@@ -21,9 +21,11 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.TaskContainer;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Retries the nested task a set number of times
+ * @since Ant 1.7.1
  */
 public class Retry extends Task implements TaskContainer {
 
@@ -39,14 +41,20 @@
 
     /**
      * set the task
+     * @param t the task to retry.
      */
-    public void addTask(Task t) {
+    public synchronized void addTask(Task t) {
+        if (nestedTask != null) {
+            throw new BuildException(
+                "The retry task container accepts a single nested task"
+                + " (which may be a sequential task container)");
+        }
         nestedTask = t;
     }
 
     /**
      * set the number of times to retry the task
-     * @param n
+     * @param n the number to use.
      */
     public void setRetryCount(int n) {
         retryCount = n;
@@ -58,26 +66,23 @@
      */
     public void execute() throws BuildException {
         StringBuffer errorMessages = new StringBuffer();
-        for(int i=0; i<=retryCount; i++) {
+        for (int i = 0; i <= retryCount; i++) {
             try {
                 nestedTask.perform();
                 break;
             } catch (Exception e) {
-                if (i<retryCount) {
-                    log("Attempt ["+i+"] error occurred, retrying...", e, Project.MSG_INFO);
-                    errorMessages.append(e.getMessage());
-                    errorMessages.append(getProject().getProperty("line.separator"));
-                } else {
-                    errorMessages.append(e.getMessage());
+                errorMessages.append(e.getMessage());
+                if (i >= retryCount) {
                     StringBuffer exceptionMessage = new StringBuffer();
                     exceptionMessage.append("Task [").append(nestedTask.getTaskName());
                     exceptionMessage.append("] failed after [").append(retryCount);
-                    exceptionMessage.append("] attempts, giving up.");
-                    exceptionMessage.append(getProject().getProperty("line.separator"));
-                    exceptionMessage.append("Error messages:").append(getProject().getProperty("line.separator"));
+                    exceptionMessage.append("] attempts; giving up.").append(StringUtils.LINE_SEP);
+                    exceptionMessage.append("Error messages:").append(StringUtils.LINE_SEP);
                     exceptionMessage.append(errorMessages);
                     throw new BuildException(exceptionMessage.toString(), getLocation());
                 }
+                log("Attempt [" + i + "]: error occurred; retrying...", e, Project.MSG_INFO);
+                errorMessages.append(StringUtils.LINE_SEP);
             }
         }
     }



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


Mime
View raw message