From d7c1a1daa55904f11eb356fe77c85edb07a7c0b0 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Tue, 11 Dec 2001 09:23:56 +0000 Subject: [PATCH] task lacked a failonerror flag. sigh. now you can handle a missing server without the build keeling over. Also now we can start writing some unit tests on this item, no? git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270112 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/SendEmail.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/SendEmail.java b/src/main/org/apache/tools/ant/taskdefs/SendEmail.java index 446527044..e62320fb8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SendEmail.java +++ b/src/main/org/apache/tools/ant/taskdefs/SendEmail.java @@ -65,6 +65,7 @@ import java.util.Enumeration; import org.apache.tools.mail.MailMessage; import org.apache.tools.ant.Task; +import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; /** @@ -126,6 +127,11 @@ public class SendEmail extends Task { private String subject; private Vector files = new Vector(); private boolean includefilenames; + /** + * failure flag + */ + private boolean failOnError = true; + /** Creates new SendEmail */ public SendEmail() { @@ -201,11 +207,22 @@ public class SendEmail extends Task { * Sets Includefilenames attribute * * @param includefilenames Set to true if file names are to be included. + * @since 1.5 */ public void setIncludefilenames(boolean includefilenames) { this.includefilenames = includefilenames; } + /** + * Sets the FailOnError attribute of the MimeMail object + * + * @param failOnError The new FailOnError value + * @since 1.5 + */ + public void setFailOnError(boolean failOnError) { + this.failOnError = failOnError; + } + /** * Executes this build task. * @@ -267,7 +284,9 @@ public class SendEmail extends Task { } } finally { if (in != null) { - in.close(); + try { + in.close(); + } catch (IOException ioe) {} } } @@ -286,7 +305,13 @@ public class SendEmail extends Task { log("Sending email"); mailMessage.sendAndClose(); } catch (IOException ioe) { - throw new BuildException("IO error sending mail", ioe); + String err="IO error sending mail "+ioe.toString(); + if(failOnError) { + throw new BuildException(err,ioe,location); + } + else { + log(err,Project.MSG_ERR); + } } }