You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2021/11/06 13:33:49 UTC
[ant] branch master updated: Support Jakarta Mail in MailLogger
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new 068e14e Support Jakarta Mail in MailLogger
new 5db51ce Merge pull request #166 from twogee/jakarta-mail
068e14e is described below
commit 068e14ec348e1f9520a91e5ab97051e3117008ae
Author: twogee <g....@gmail.com>
AuthorDate: Sat Oct 30 19:33:57 2021 +0200
Support Jakarta Mail in MailLogger
---
.../org/apache/tools/ant/listener/MailLogger.java | 57 +++++++++++++++++-----
1 file changed, 44 insertions(+), 13 deletions(-)
diff --git a/src/main/org/apache/tools/ant/listener/MailLogger.java b/src/main/org/apache/tools/ant/listener/MailLogger.java
index de9cda0..897f000 100644
--- a/src/main/org/apache/tools/ant/listener/MailLogger.java
+++ b/src/main/org/apache/tools/ant/listener/MailLogger.java
@@ -47,12 +47,12 @@ import org.apache.tools.mail.MailMessage;
* <ul>
* <li> MailLogger.mailhost [default: localhost] - Mail server to use</li>
* <li> MailLogger.port [default: 25] - Default port for SMTP </li>
- * <li> Maillogger.user [no default] - user name for SMTP auth
- * (requires JavaMail)</li>
- * <li> Maillogger.password [no default] - password for SMTP auth
- * (requires JavaMail)</li>
- * <li> Maillogger.ssl [default: false] - on or true if ssl is
- * needed (requires JavaMail)</li>
+ * <li> MailLogger.user [no default] - user name for SMTP auth
+ * (requires Java or Jakarta Mail)</li>
+ * <li> MailLogger.password [no default] - password for SMTP auth
+ * (requires Java or Jakarta Mail)</li>
+ * <li> MailLogger.ssl [default: false] - on or true if ssl is
+ * needed (requires Java or Jakarta Mail)</li>
* <li> MailLogger.from [required] - Mail "from" address</li>
* <li> MailLogger.from [no default] - Mail "replyto" address(es),
* comma-separated</li>
@@ -82,8 +82,8 @@ import org.apache.tools.mail.MailMessage;
* mail body for a successful build, default is to send the logfile</li>
* <li> MailLogger.mimeType [default: text/plain] - MIME-Type of email</li>
* <li> MailLogger.charset [no default] - character set of email</li>
- * <li> Maillogger.starttls.enable [default: false] - on or true if
- * STARTTLS should be supported (requires JavaMail)</li>
+ * <li> MailLogger.starttls.enable [default: false] - on or true if
+ * STARTTLS should be supported (requires Java or Jakarta Mail)</li>
* <li> MailLogger.properties.file [no default] - Filename of
* properties file that will override other values.</li>
* </ul>
@@ -386,15 +386,13 @@ public class MailLogger extends DefaultLogger {
private void sendMimeMail(Project project, Values values, String message) {
Mailer mailer = null;
try {
- mailer = ClasspathUtils.newInstance(
- "org.apache.tools.ant.taskdefs.email.MimeMailer",
+ mailer = ClasspathUtils.newInstance(getMailerImplementation(),
MailLogger.class.getClassLoader(), Mailer.class);
} catch (BuildException e) {
- Throwable t = e.getCause() == null ? e : e.getCause();
- log("Failed to initialise MIME mail: " + t.getMessage());
+ logBuildException("Failed to initialise MIME mail: ", e);
return;
}
- // convert the replyTo string into a vector of emailaddresses
+ // convert the replyTo string into a vector of EmailAddresses
Vector<EmailAddress> replyToList = splitEmailAddresses(values.replytoList());
mailer.setHost(values.mailhost());
mailer.setPort(values.port());
@@ -428,4 +426,37 @@ public class MailLogger extends DefaultLogger {
return Stream.of(listString.split(",")).map(EmailAddress::new)
.collect(Collectors.toCollection(Vector::new));
}
+
+ private String getMailerImplementation() {
+ //check to make sure that activation.jar
+ //and mail.jar are available - see bug 31969
+ try {
+ Class.forName("jakarta.activation.DataHandler");
+ Class.forName("jakarta.mail.internet.MimeMessage");
+
+ return "org.apache.tools.ant.taskdefs.email.JakartaMimeMailer";
+ } catch (ClassNotFoundException cnfe) {
+ logBuildException("Could not find Jakarta MIME mail: ",
+ new BuildException(cnfe));
+ }
+
+ try {
+ Class.forName("javax.activation.DataHandler");
+ Class.forName("javax.mail.internet.MimeMessage");
+
+ return "org.apache.tools.ant.taskdefs.email.MimeMailer";
+ } catch (ClassNotFoundException cnfe) {
+ logBuildException("Could not find MIME mail: ",
+ new BuildException(cnfe));
+ }
+
+ return "org.apache.tools.ant.taskdefs.email.Mailer";
+ }
+
+ private void logBuildException(String reason, BuildException e) {
+ Throwable t = e.getCause() == null ? e : e.getCause();
+ if (Project.MSG_WARN <= msgOutputLevel) {
+ log(reason + t.getMessage());
+ }
+ }
}