Skip to content

Commit

Permalink
Detach JavaMail
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Jan 6, 2022
1 parent c31d930 commit 92380c9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
5 changes: 0 additions & 5 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@ THE SOFTWARE.
<artifactId>symbol-annotation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.5</version>
</dependency>

<!--XStream-->
<dependency>
Expand Down
4 changes: 0 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ THE SOFTWARE.
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
Expand Down
39 changes: 34 additions & 5 deletions core/src/main/java/jenkins/model/JenkinsLocationConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import hudson.util.XStream2;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.servlet.ServletContext;
import jenkins.util.SystemProperties;
import jenkins.util.UrlHelper;
Expand Down Expand Up @@ -211,10 +210,40 @@ public FormValidation doCheckUrl(@QueryParameter String value) {

public FormValidation doCheckAdminAddress(@QueryParameter String value) {
try {
new InternetAddress(value);
Class<?> internetAddress = Jenkins.get().pluginManager.uberClassLoader.loadClass("javax.mail.internet.InternetAddress");
internetAddress.getDeclaredConstructor(String.class).newInstance(value);
return FormValidation.ok();
} catch (AddressException e) {
return FormValidation.error(e.getMessage());
} catch (ClassNotFoundException x) {
return FormValidation.ok();
} catch (NoSuchMethodException x) {
NoSuchMethodError e = new NoSuchMethodError(x.getMessage());
e.initCause(x);
throw e;
} catch (IllegalAccessException x) {
IllegalAccessError e = new IllegalAccessError(x.getMessage());
e.initCause(x);
throw e;
} catch (InstantiationException x) {
InstantiationError e = new InstantiationError(x.getMessage());
e.initCause(x);
throw e;
} catch (InvocationTargetException x) {
Throwable t = x.getCause();
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof IOException) {
throw new UncheckedIOException((IOException) t);
} else if (t instanceof Exception) {
if (t.getClass().getName().equals("javax.mail.internet.AddressException")) {
return FormValidation.error(t.getMessage());
} else {
throw new RuntimeException(t);
}
} else if (t instanceof Error) {
throw (Error) t;
} else {
throw new Error(x);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/jenkins/split-plugin-cycles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ junit jaxb
bouncycastle-api jaxb
command-launcher jaxb
jdk-tool jaxb

javax-activation-api javax-mail-api
3 changes: 3 additions & 0 deletions core/src/main/resources/jenkins/split-plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ trilead-api 2.184 1.0.4

# JENKINS-64107
sshd 2.281 3.0.1

javax-activation-api 2.328 1.2.0-1
javax-mail-api 2.328 1.6.2-1
6 changes: 6 additions & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ THE SOFTWARE.
<version>391.ve4a_38c1b_cf4b_</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>javax-mail-api</artifactId>
<version>1.6.2-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ THE SOFTWARE.
<version>1.0.4</version>
<type>hpi</type>
</artifactItem>
<artifactItem>
<groupId>io.jenkins.plugins</groupId>
<artifactId>javax-activation-api</artifactId>
<version>1.2.0-1</version>
<type>hpi</type>
</artifactItem>
<artifactItem>
<groupId>io.jenkins.plugins</groupId>
<artifactId>javax-mail-api</artifactId>
<version>1.6.2-1</version>
<type>hpi</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/detached-plugins</outputDirectory>
<stripVersion>true</stripVersion>
Expand Down

0 comments on commit 92380c9

Please sign in to comment.