Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the optional dependencies #138

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@
</or>
</selector>

<selector id="needs.jakartamail">
<or>
<filename name="${ant.package}/taskdefs/email/JakartaMimeMailer*"/>
</or>
</selector>

<selector id="needs.netrexx">
<filename name="${optional.package}/NetRexxC*"/>
</selector>
Expand Down Expand Up @@ -507,6 +513,9 @@
<available property="javamail.present"
classname="javax.mail.Transport"
classpathref="classpath" ignoresystemclasses="${ignoresystemclasses}"/>
<available property="jakartamail.present"
classname="jakarta.mail.Transport"
classpathref="classpath" ignoresystemclasses="${ignoresystemclasses}"/>
<available property="graaljs.present"
classname="com.oracle.truffle.js.scriptengine.GraalJSScriptEngine"
classpathref="classpath" ignoresystemclasses="${ignoresystemclasses}"/>
Expand Down Expand Up @@ -704,6 +713,7 @@
<selector refid="needs.commons-logging" unless="commons.logging.present"/>
<selector refid="needs.apache-bsf" unless="bsf.present"/>
<selector refid="needs.javamail" unless="javamail.present"/>
<selector refid="needs.jakartamail" unless="jakartamail.present"/>
<selector refid="needs.netrexx" unless="netrexx.present"/>
<selector refid="needs.commons-net" unless="commons.net.present"/>
<selector refid="needs.antlr" unless="antlr.present"/>
Expand Down
6 changes: 6 additions & 0 deletions fetch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ Set -Ddest=LOCATION on the command line
<f2 project="which"/>
</target>

<target name="javamail"
description="load Java Mail"
depends="init">
<f2 project="com.sun.mail" archive="javax.mail"/>
</target>

<target name="jakartamail"
description="load Jakarta Mail"
depends="init">
Expand Down
10 changes: 6 additions & 4 deletions lib/libraries.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ bsh.version=2.0b5
commons-net.version=3.8.0
commons-logging.version=1.1
commons-logging-api.version=${commons-logging.version}
js.version=20.1.0
js.version=21.1.0
js-scriptengine.version=${js.version}
hamcrest-core.version=1.3
hamcrest-library.version=${hamcrest-core.version}
jai-core.version=1.1.3
jai-codec.version=1.1.3
jakarta.mail.version=1.6.4
# Later 1.6 versions call themselves "jakarta.mail" but do not use the namespace yet
javax.mail.version=1.6.2
jakarta.mail.version=2.0.1
jakarta-regexp.version=1.4
# Later versions of Tomcat provide a jspc task
jasper-compiler.version=4.1.36
jasper-runtime.version=${jasper-compiler.version}
jdepend.version=2.9.1
jruby.version=1.6.8
junit.version=4.13.1
rhino.version=1.7.11
junit.version=4.13.2
rhino.version=1.7.13
junit-platform-launcher.version=1.2.0
# Only used for internal tests in Ant project
junit-vintage-engine.version=5.2.0
Expand Down
Binary file not shown.
65 changes: 42 additions & 23 deletions src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void addMessage(Message message) throws BuildException {
}

/**
* Add a from address element.
* Add a "from" address element.
*
* @param address The address to send from.
*/
Expand All @@ -251,7 +251,7 @@ public void addFrom(EmailAddress address) {
}

/**
* Shorthand to set the from address element.
* Shorthand to set the "from" address element.
*
* @param address The address to send mail from.
*/
Expand All @@ -263,7 +263,7 @@ public void setFrom(String address) {
}

/**
* Add a replyto address element.
* Add a "replyto" address element.
*
* @param address The address to reply to.
* @since Ant 1.6
Expand All @@ -273,7 +273,7 @@ public void addReplyTo(EmailAddress address) {
}

/**
* Shorthand to set the replyto address element.
* Shorthand to set the "replyto" address element.
*
* @param address The address to which replies should be directed.
* @since Ant 1.6
Expand All @@ -283,7 +283,7 @@ public void setReplyTo(String address) {
}

/**
* Add a to address element.
* Add a "to" address element.
*
* @param address An email address.
*/
Expand Down Expand Up @@ -449,16 +449,9 @@ public void execute() {
// prepare for the auto select mechanism
boolean autoFound = false;
// try MIME format
if (MIME.equals(encoding)
|| (AUTO.equals(encoding) && !autoFound)) {
if (MIME.equals(encoding) || AUTO.equals(encoding)) {
try {
//check to make sure that activation.jar
//and mail.jar are available - see bug 31969
Class.forName("javax.activation.DataHandler");
Class.forName("javax.mail.internet.MimeMessage");

mailer = ClasspathUtils.newInstance(
"org.apache.tools.ant.taskdefs.email.MimeMailer",
mailer = ClasspathUtils.newInstance(getMailerImplementation(),
EmailTask.class.getClassLoader(), Mailer.class);
autoFound = true;

Expand All @@ -467,16 +460,16 @@ public void execute() {
logBuildException("Failed to initialise MIME mail: ", e);
}
}
// SMTP auth only allowed with MIME mail
if (!autoFound && ((user != null) || (password != null))
&& (UU.equals(encoding) || PLAIN.equals(encoding))) {
throw new BuildException("SMTP auth only possible with MIME mail");
if ((UU.equals(encoding) || PLAIN.equals(encoding))
&& !autoFound) {
// SMTP auth only allowed with MIME mail
if (user != null || password != null) {
throw new BuildException("SMTP auth only possible with MIME mail");
}
// SSL only allowed with MIME mail
if (ssl || starttls) {
throw new BuildException("SSL and STARTTLS only possible with MIME mail");
}
// SSL only allowed with MIME mail
if (!autoFound && (ssl || starttls)
&& (UU.equals(encoding) || PLAIN.equals(encoding))) {
throw new BuildException(
"SSL and STARTTLS only possible with MIME mail");
}
// try UU format
if (UU.equals(encoding)
Expand Down Expand Up @@ -600,6 +593,32 @@ public void execute() {
}
}

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();
log(reason + t.getMessage(), Project.MSG_WARN);
Expand Down
Loading