ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r556987 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/Retry.java src/tests/antunit/taskdefs/retry-test.xml
Date Tue, 17 Jul 2007 17:36:31 GMT
Author: mbenson
Date: Tue Jul 17 10:36:28 2007
New Revision: 556987

URL: http://svn.apache.org/viewvc?view=rev&rev=556987
Log:
fmt/refac

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Retry.java
    ant/core/trunk/src/tests/antunit/taskdefs/retry-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=556987&r1=556986&r2=556987
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Jul 17 10:36:28 2007
@@ -186,6 +186,8 @@
 
 * "rawblobs" attribute added to SQL task.
 
+* Add new retry task container.
+
 
 Changes from Ant 1.6.5 to Ant 1.7.0
 ===================================

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Retry.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Retry.java?view=diff&rev=556987&r1=556986&r2=556987
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Retry.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Retry.java Tue Jul 17 10:36:28 2007
@@ -24,6 +24,7 @@
 
 /**
  * Retries the nested task a set number of times
+ * @since Ant 1.7.1
  */
 public class Retry extends Task implements TaskContainer {
 
@@ -31,19 +32,23 @@
      * task to execute n times
      */
     private Task nestedTask;
-    
+
     /**
      * set retryCount to 1 by default
      */
     private int retryCount = 1;
-    
+
     /**
      * set the task
      */
-    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
@@ -51,32 +56,30 @@
     public void setRetryCount(int n) {
         retryCount = n;
     }
-    
+
     /**
      * perform the work
      */
     public void execute() throws BuildException {
         StringBuffer errorMessages = new StringBuffer();
-        for(int i=0; i<=retryCount; i++) {
+        String br = getProject().getProperty("line.separator");
+        for (int i = 0; i <= retryCount; i++) {
             try {
                 nestedTask.perform();
                 break;
             } catch (Exception e) {
-                if (i<retryCount) {
-                    log("Attempt ["+i+"] error occured, 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(br);
+                    exceptionMessage.append("Error messages:").append(br);
                     exceptionMessage.append(errorMessages);
                     throw new BuildException(exceptionMessage.toString(), getLocation());
                 }
+                log("Attempt [" + i + "]:  error occurred; retrying...", e, Project.MSG_INFO);
+                errorMessages.append(br);
             }
         }
     }

Modified: ant/core/trunk/src/tests/antunit/taskdefs/retry-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/retry-test.xml?view=diff&rev=556987&r1=556986&r2=556987
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/retry-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/retry-test.xml Tue Jul 17 10:36:28 2007
@@ -7,12 +7,12 @@
     <property name="dest" value="${java.io.tmpdir}/dest"/>
     <!-- just in case this ever becomes a legit url... -->
     <property name="src" value="http://iojasodjojaosdj"/>
-    <au:expectfailure expectedmessage="Task [get] failed after [${i}] attempts, giving
up">
+    <au:expectfailure expectedmessage="Task [get] failed after [${i}] attempts; giving
up">
       <retry retrycount="${i}">
         <get src="${src}" dest="${dest}"/>
       </retry>
     </au:expectfailure>
-    <au:assertLogContains text="Attempt [1] error occured, retrying..."/>
+    <au:assertLogContains text="Attempt [1]:  error occurred; retrying..."/>
   </target>
 
   <target name="test-success">
@@ -21,7 +21,7 @@
     <retry retrycount="${i}">
       <touch file="${dest}"/>
     </retry>
-    <au:assertLogDoesntContain text="Attempt [1] error occured, retrying..."/>
+    <au:assertLogDoesntContain text="Attempt [1]:  error occurred; retrying..."/>
   </target>
 
 </project>



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


Mime
View raw message