Browse Source

Remove dependency to JavaMail for MailLogger by using the Mailer class

and Class.forName() instead of the MimeMailer class directly
Also remove another bug in the MailLogger which would have forbidden to send plain mail
PR: 5969


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274629 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
e1fc0ae7ec
3 changed files with 15 additions and 8 deletions
  1. +1
    -2
      build.xml
  2. +13
    -5
      src/main/org/apache/tools/ant/listener/MailLogger.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/email/Mailer.java

+ 1
- 2
build.xml View File

@@ -214,7 +214,6 @@
<selector id="needs.javamail">
<or>
<filename name="${ant.package}/taskdefs/email/MimeMailer*"/>
<filename name="${ant.package}/listener/MailLogger*"/>
</or>
</selector>
<selector id="needs.icontract">
@@ -1568,7 +1567,7 @@
<exclude name="${optional.package}/sos/SOSTest.java"
unless="tests.and.ant.share.classloader"/>
<exclude name="${optional.package}/vss/MSVSSTest.java"
unless="tests.and.ant.share.classloader"/>
unless="tests.and.ant.share.classloader"/>
<exclude name="${optional.package}/TraXLiaisonTest.java"
unless="tests.and.ant.share.classloader"/>
<exclude name="${optional.package}/metamata/MAuditParserTest.java"


+ 13
- 5
src/main/org/apache/tools/ant/listener/MailLogger.java View File

@@ -62,9 +62,9 @@ import java.util.*;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.email.MimeMailer;
import org.apache.tools.ant.taskdefs.email.EmailAddress;
import org.apache.tools.ant.taskdefs.email.Message;
import org.apache.tools.ant.taskdefs.email.Mailer;
import org.apache.tools.ant.util.DateUtils;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.mail.MailMessage;
@@ -155,14 +155,14 @@ public class MailLogger extends DefaultLogger {

String mailhost = getValue(properties, "mailhost", "localhost");
int port = Integer.parseInt(getValue(properties,"port",String.valueOf(MailMessage.DEFAULT_PORT)));
String user = getValue(properties, "user", null);
String password = getValue(properties, "password", null);
String user = getValue(properties, "user", "");
String password = getValue(properties, "password", "");
String from = getValue(properties, "from", null);
String replytoList = getValue(properties,"replyto","");
String toList = getValue(properties, prefix + ".to", null);
String subject = getValue(properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure");
if (user==null && password==null) {
if (user.equals("") && password.equals("")) {
sendMail(mailhost, port, from, replytoList, toList, subject, buffer.substring(0));
}
else {
@@ -266,8 +266,16 @@ public class MailLogger extends DefaultLogger {
private void sendMimeMail(Project project, String host, int port, String user, String password, String from, String replyToString, String toString,
String subject, String message) throws IOException {
// convert the replyTo string into a vector of emailaddresses
Mailer mailer = null;
try {
mailer =
(Mailer) Class.forName("org.apache.tools.ant.taskdefs.email.MimeMailer")
.newInstance();
} catch (Throwable e) {
log("Failed to initialise MIME mail: "+e.getMessage());
return;
}
Vector replyToList = vectorizeEmailAddresses(replyToString);
MimeMailer mailer=new MimeMailer();
mailer.setHost(host);
mailer.setPort(port);
mailer.setUser(user);


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/email/Mailer.java View File

@@ -64,7 +64,7 @@ import org.apache.tools.ant.util.DateUtils;
* @author roxspring@yahoo.com Rob Oxspring
* @since Ant 1.5
*/
abstract class Mailer {
public abstract class Mailer {
protected String host = null;
protected int port = -1;
protected String user = null;


Loading…
Cancel
Save