From 291e7b02172f3947d095b0b04e734ec9c5f11ff9 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 6 Dec 2011 16:33:19 +0000 Subject: [PATCH] Allow retry task to sleep between retry attempts. Submitted by Arjan Veenstra. PR 52076 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1211004 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 4 +++ contributors.xml | 4 +++ .../org/apache/tools/ant/taskdefs/Retry.java | 32 ++++++++++++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 72d285856..f131c3d67 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -25,6 +25,7 @@ Anthony Wat Antoine Baudoux Antoine Levy-Lambert Anton Mazkovoi +Arjan Veenstra Arnaud Vandyck Arnout J. Kuiper Aslak Hellesôy diff --git a/WHATSNEW b/WHATSNEW index 43f3427ae..e3c50e309 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -163,6 +163,10 @@ Other changes: * URLResources#isExists has become less noisy. Bugzilla Report 51802. + * The task has a new optional attribute retryDelay that can + be used to make the task sleep between retry attempts. + Bugzilla Report 52076. + Changes from Ant 1.8.1 TO Ant 1.8.2 =================================== diff --git a/contributors.xml b/contributors.xml index b22916a9b..8e22b25cb 100644 --- a/contributors.xml +++ b/contributors.xml @@ -123,6 +123,10 @@ Anton Mazkovoi + + Arjan + Veenstra + Arnaud Vandyck diff --git a/src/main/org/apache/tools/ant/taskdefs/Retry.java b/src/main/org/apache/tools/ant/taskdefs/Retry.java index ece55a025..89ca6ebd2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Retry.java +++ b/src/main/org/apache/tools/ant/taskdefs/Retry.java @@ -39,6 +39,11 @@ public class Retry extends Task implements TaskContainer { */ private int retryCount = 1; + /** + * The time to wait between retries in milliseconds, default to 0. + */ + private int retryDelay = 0; + /** * set the task * @param t the task to retry. @@ -60,6 +65,18 @@ public class Retry extends Task implements TaskContainer { retryCount = n; } + /** + * set the delay between retries (in miliseconds) + * @param n the time between retries. + * @since Ant 1.8.3 + */ + public void setRetryDelay(int retryDelay) { + if (retryDelay < 0) { + throw new BuildException("delay must be a non-negative number"); + } + this.retryDelay = retryDelay; + } + /** * perform the work * @throws BuildException if there is an error. @@ -81,8 +98,21 @@ public class Retry extends Task implements TaskContainer { exceptionMessage.append(errorMessages); throw new BuildException(exceptionMessage.toString(), getLocation()); } - log("Attempt [" + i + "]: error occurred; retrying...", e, Project.MSG_INFO); + String msg; + if (retryDelay > 0) { + msg = "Attempt [" + i + "]: error occurred; retrying after " + retryDelay + " ms..."; + } else { + msg = "Attempt [" + i + "]: error occurred; retrying..."; + } + log(msg, e, Project.MSG_INFO); errorMessages.append(StringUtils.LINE_SEP); + if (retryDelay > 0) { + try { + Thread.sleep(retryDelay); + } catch (InterruptedException ie) { + // Ignore Exception + } + } } } }