Skip to content

Commit c76767e

Browse files
committed
Add jakarta.mail metadata
Focused on SMTP for now Closes gh-18
1 parent bf0d957 commit c76767e

File tree

10 files changed

+195
-0
lines changed

10 files changed

+195
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"reflect-config.json",
3+
"resource-config.json"
4+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"condition": {
4+
"typeReachable": "jakarta.mail.Session"
5+
},
6+
"allDeclaredConstructors": true,
7+
"name": "com.sun.mail.smtp.SMTPTransport"
8+
}
9+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"resources": {
3+
"includes": [
4+
{
5+
"pattern": "\\QMETA-INF/hk2-locator/default\\E"
6+
},
7+
{
8+
"pattern": "\\QMETA-INF/gfprobe-provider.xml\\E"
9+
},
10+
{
11+
"pattern": "\\QMETA-INF/javamail.charset.map\\E"
12+
},
13+
{
14+
"pattern": "\\QMETA-INF/javamail.default.address.map\\E"
15+
},
16+
{
17+
"pattern": "\\QMETA-INF/javamail.default.providers\\E"
18+
},
19+
{
20+
"pattern": "\\QMETA-INF/mailcap\\E"
21+
}
22+
]
23+
}
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"latest": true,
4+
"metadata-version": "2.0.1",
5+
"module": "com.sun.mail:jakarta.mail",
6+
"tested-versions": [
7+
"2.0.1"
8+
]
9+
}
10+
]

metadata/index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@
7474
{
7575
"directory": "org.flywaydb/flyway-core",
7676
"module": "org.flywaydb:flyway-core"
77+
},
78+
{
79+
"directory": "com.sun.mail/jakarta.mail",
80+
"module": "com.sun.mail:jakarta.mail"
7781
}
7882
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
8+
import org.graalvm.internal.tck.TestUtils
9+
10+
plugins {
11+
id "org.graalvm.internal.tck"
12+
}
13+
14+
String libraryVersion = TestUtils.testedLibraryVersion
15+
16+
dependencies {
17+
testImplementation("org.slf4j:slf4j-api:1.7.36")
18+
testImplementation("org.slf4j:slf4j-simple:1.7.36")
19+
testImplementation("com.sun.mail:jakarta.mail:$libraryVersion")
20+
testImplementation 'org.assertj:assertj-core:3.22.0'
21+
testImplementation 'org.awaitility:awaitility:4.2.0'
22+
testImplementation 'commons-io:commons-io:2.11.0'
23+
}
24+
25+
graalvmNative {
26+
binaries {
27+
test {
28+
buildArgs.add('--no-fallback')
29+
}
30+
}
31+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
library.version = 2.0.1
2+
metadata.dir = com.sun.mail/jakarta.mail/2.0.1/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
8+
pluginManagement {
9+
def tckPath = Objects.requireNonNullElse(
10+
System.getenv("GVM_TCK_TCKDIR"),
11+
"../../../../tck-build-logic"
12+
)
13+
includeBuild(tckPath)
14+
}
15+
16+
plugins {
17+
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
18+
}
19+
20+
rootProject.name = 'jakarta-mail-tests'
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
package com.sun.mail;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.time.Duration;
15+
import java.util.Properties;
16+
17+
import jakarta.mail.Message;
18+
import jakarta.mail.MessagingException;
19+
import jakarta.mail.Session;
20+
import jakarta.mail.Transport;
21+
import jakarta.mail.internet.InternetAddress;
22+
import jakarta.mail.internet.MimeMessage;
23+
import org.apache.commons.io.FileUtils;
24+
import org.assertj.core.api.Assertions;
25+
import org.awaitility.Awaitility;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.Test;
29+
30+
public class JakartaMailTest {
31+
32+
@BeforeAll
33+
static void beforeAll() throws IOException {
34+
System.out.println("Starting email server ...");
35+
new ProcessBuilder("docker", "run", "--cidfile", "greenmail.cid", "-p", "3025:3025", "--rm", "-e",
36+
"GREENMAIL_OPTS=-Dgreenmail.setup.test.all -Dgreenmail.hostname=0.0.0.0 -Dgreenmail.auth.disabled -Dgreenmail.verbose", "greenmail/standalone:1.6.10")
37+
.redirectOutput(new File("greenmail-stdout.txt"))
38+
.redirectError(new File("greenmail-stderr.txt")).start();
39+
Awaitility.await().atMost(Duration.ofSeconds(10)).until(() -> {
40+
String logs = FileUtils.readFileToString(new File("greenmail-stdout.txt"), StandardCharsets.UTF_8);
41+
return logs.contains("smtp.SmtpServer| Started") && logs.contains("pop3.Pop3Server| Started") && logs.contains("imap.ImapServer| Started");
42+
});
43+
}
44+
45+
@AfterAll
46+
static void tearDown() throws InterruptedException, IOException {
47+
File cidFile = new File("greenmail.cid");
48+
String cid = FileUtils.readFileToString(cidFile, StandardCharsets.UTF_8);
49+
Files.delete(cidFile.toPath());
50+
new ProcessBuilder("docker", "kill", cid).start().waitFor();
51+
Files.delete(Path.of("greenmail-stdout.txt"));
52+
Files.delete(Path.of("greenmail-stderr.txt"));
53+
}
54+
55+
@Test
56+
void sendMailWithSmtp() throws MessagingException {
57+
Properties properties = new Properties();
58+
properties.put("mail.smtp.host", "localhost");
59+
properties.put("mail.smtp.port", "3025");
60+
Session session = Session.getInstance(properties);
61+
Message message = new MimeMessage(session);
62+
message.setFrom(new InternetAddress("alice@localhost"));
63+
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("bob@localhost"));
64+
message.setSubject("This is a test");
65+
message.setText("Dear Bob, hello world! Alice.");
66+
Transport.send(message);
67+
}
68+
69+
@Test
70+
void resources() {
71+
ClassLoader classLoader = getClass().getClassLoader();
72+
Assertions.assertThat(classLoader.getResource("META-INF/hk2-locator/default")).isNotNull();
73+
Assertions.assertThat(classLoader.getResource("META-INF/gfprobe-provider.xml")).isNotNull();
74+
Assertions.assertThat(classLoader.getResource("META-INF/javamail.charset.map")).isNotNull();
75+
Assertions.assertThat(classLoader.getResource("META-INF/javamail.default.address.map")).isNotNull();
76+
Assertions.assertThat(classLoader.getResource("META-INF/javamail.default.providers")).isNotNull();
77+
Assertions.assertThat(classLoader.getResource("META-INF/mailcap")).isNotNull();
78+
}
79+
80+
}

tests/src/index.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,16 @@
185185
]
186186
}
187187
]
188+
},
189+
{
190+
"test-project-path": "com.sun.mail/jakarta.mail/2.0.1",
191+
"libraries": [
192+
{
193+
"name": "com.sun.mail:jakarta.mail",
194+
"versions": [
195+
"2.0.1"
196+
]
197+
}
198+
]
188199
}
189200
]

0 commit comments

Comments
 (0)