ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: Retry task available in svn head
Date Mon, 21 May 2007 06:29:01 GMT
>+            } catch (Exception e) {
>+                if (i<retryCount) {
>+                    log("Attempt ["+i+"] error occured, retrying...",
e, Project.MSG_INFO);
>+                } else {
>+                    throw new BuildException("Task
["+nestedTask.getTaskName()+"] failed after ["+retryCount+"] attempts,
giving up");
>+                }
>+            }
>
>I do not know very much about ant exception handling in general.
>So it seems to me that e is lost in some cases and I think it 
>is not a good idea.

Would this be more useful?

    public void execute() throws BuildException {
        StringBuffer errorMessages = new StringBuffer();
        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());
                    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(errorMessages);
                    throw new
BuildException(exceptionMessage.toString(), getLocation());
                }
            }
        }
    }


  <target name="test-fail-and-retry">
    <property name="i" value="3"/>
    <property name="dest" value="${java.io.tmpdir}/dest"/>
    <!-- just in case this ever becomes a legit url... -->
    <property name="src" value="http://iojasodjojaosdj"/>
      <retry retrycount="${i}">
        <get src="${src}" dest="${dest}"/>
      </retry>
  </target>


test-fail-and-retry:
      [get] Getting: http://iojasodjojaosdj
      [get] To: c:\temp\dest
      [get] Error getting http://iojasodjojaosdj to c:\temp\dest
    [retry] Attempt [0] error occured, retrying...
      [get] Getting: http://iojasodjojaosdj
      [get] To: c:\temp\dest
      [get] Error getting http://iojasodjojaosdj to c:\temp\dest
    [retry] Attempt [1] error occured, retrying...
      [get] Getting: http://iojasodjojaosdj
      [get] To: c:\temp\dest
      [get] Error getting http://iojasodjojaosdj to c:\temp\dest
    [retry] Attempt [2] error occured, retrying...
      [get] Getting: http://iojasodjojaosdj
      [get] To: c:\temp\dest
      [get] Error getting http://iojasodjojaosdj to c:\temp\dest

BUILD FAILED
C:\TEMP\retry-test.xml:9: Task [get] failed after [3] attempts, giving
up.
Error messages:
java.net.UnknownHostException: iojasodjojaosdj
java.net.UnknownHostException: iojasodjojaosdj
java.net.UnknownHostException: iojasodjojaosdj
java.net.UnknownHostException: iojasodjojaosdj




Jan

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


Mime
View raw message