From 5c6ae59fccc6dba7646dc8076daed7542516dbd1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 24 Jul 2009 14:55:05 +0000 Subject: [PATCH] configurable number of retries in get, option to skip existing files. Submitted by David M. Lloyd. PR 40058 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@797509 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 4 +++ contributors.xml | 5 +++ docs/manual/CoreTasks/get.html | 12 +++++++ .../org/apache/tools/ant/taskdefs/Get.java | 34 +++++++++++++++++-- 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 6efe8d18c..268e6dfd9 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -72,6 +72,7 @@ David Gärtner David S. Johnson David Kavanagh David LeRoy +David M. Lloyd David Maclean David Rees Denis Hennessy diff --git a/WHATSNEW b/WHATSNEW index 438a53dee..d9f2fb3af 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -808,6 +808,10 @@ Other changes: expression based way to determine progress based on logged messages. Bugzilla Report 39957. + * the number of retries on error in is now configurable. + can be told to not download files that already exist locally. + Bugzilla Report 40058. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/contributors.xml b/contributors.xml index 0e31cbb4c..4b7382602 100644 --- a/contributors.xml +++ b/contributors.xml @@ -312,6 +312,11 @@ David LeRoy + + David + M. + Lloyd + David Maclean diff --git a/docs/manual/CoreTasks/get.html b/docs/manual/CoreTasks/get.html index 51b239468..9f41e0a7a 100644 --- a/docs/manual/CoreTasks/get.html +++ b/docs/manual/CoreTasks/get.html @@ -103,6 +103,18 @@ plain text' authentication is used. This is only secure over an HTTPS link. No: default 0 which means no maximum time + + retries + the number of retries on error
+ since Ant 1.8.0 + No; default "3" + + + skipexisting + skip files that already exist on the local filesystem
+ since Ant 1.8.0 + No; default "false" +

Examples

  <get src="http://ant.apache.org/" dest="help/index.html"/>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java index ba71cf3e4..f64a1272b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Get.java +++ b/src/main/org/apache/tools/ant/taskdefs/Get.java @@ -65,6 +65,8 @@ public class Get extends Task { private String uname = null; private String pword = null; private long maxTime = 0; + private int numberRetries = NUMBER_RETRIES; + private boolean skipExisting = false; /** * Does the work. @@ -108,6 +110,12 @@ public class Get extends Task { throws IOException { checkAttributes(); + if (dest.exists() && skipExisting) { + log("Destination already exists (skipping): " + + dest.getAbsolutePath(), logLevel); + return true; + } + //dont do any progress, unless asked if (progress == null) { progress = new NullProgress(); @@ -267,12 +275,34 @@ public class Get extends Task { * The time in seconds the download is allowed to take before * being terminated. * - * @since ant 1.8.0 + * @since Ant 1.8.0 */ public void setMaxTime(long maxTime) { this.maxTime = maxTime; } + /** + * The number of retries to attempt upon error, defaults to 3. + * + * @param r retry count + * + * @since Ant 1.8.0 + */ + public void setRetries(int r) { + this.numberRetries = r; + } + + /** + * Skip files that already exist locally. + * + * @param s "true" to skip existing destination files + * + * @since Ant 1.8.0 + */ + public void setSkipExisting(boolean s) { + this.skipExisting = s; + } + /** * Interface implemented for reporting * progess of downloading. @@ -536,7 +566,7 @@ public class Get extends Task { private boolean downloadFile() throws FileNotFoundException, IOException { - for (int i = 0; i < NUMBER_RETRIES; i++) { + for (int i = 0; i < numberRetries; i++) { // this three attempt trick is to get round quirks in different // Java implementations. Some of them take a few goes to bind // property; we ignore the first couple of such failures.