summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortwogee <g.grigelionis@gmail.com>2021-10-30 19:33:57 +0200
committertwogee <g.grigelionis@gmail.com>2021-10-30 19:35:25 +0200
commit068e14ec348e1f9520a91e5ab97051e3117008ae (patch)
treefb37cf4d44924a19f5729d7a5d4f4d97f0d2fa53 /src
parentc3585aef09399e44f1a10c61cf7e4af80c017a3d (diff)
downloadant-068e14ec348e1f9520a91e5ab97051e3117008ae.tar.gz
Support Jakarta Mail in MailLogger
Diffstat (limited to 'src')
-rw-r--r--src/main/org/apache/tools/ant/listener/MailLogger.java57
1 files 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 de9cda0c6..897f0000b 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());
+ }
+ }
}