From 4718f9b92c414ec1e8d1189bb917a78ead52f530 Mon Sep 17 00:00:00 2001 From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:51:25 +0100 Subject: [PATCH] SONAR-21569 Remove usage of deprecated methods after upgrading commons-email. --- .../src/main/java/org/sonar/server/email/EmailSender.java | 8 +++++--- .../notification/email/EmailNotificationChannel.java | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/email/EmailSender.java b/server/sonar-server-common/src/main/java/org/sonar/server/email/EmailSender.java index b43deb8846d..08d5f84c524 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/email/EmailSender.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/email/EmailSender.java @@ -19,6 +19,8 @@ */ package org.sonar.server.email; +import java.net.MalformedURLException; +import java.time.Duration; import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; @@ -26,14 +28,14 @@ import org.apache.commons.mail.MultiPartEmail; import org.sonar.api.config.EmailSettings; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.time.temporal.ChronoUnit.SECONDS; import static org.apache.commons.lang.StringUtils.equalsIgnoreCase; import static org.apache.commons.lang.StringUtils.isBlank; import static org.apache.commons.lang.StringUtils.isNotBlank; -import java.net.MalformedURLException; public abstract class EmailSender { - protected static final int SOCKET_TIMEOUT = 30_000; + private static final Duration SOCKET_TIMEOUT = Duration.of(30, SECONDS); protected final EmailSettings emailSettings; @@ -56,7 +58,7 @@ public abstract class EmailSender { } } - public HtmlEmail createEmail(T report) throws MalformedURLException, EmailException { + public HtmlEmail createEmail(T report) throws MalformedURLException, EmailException { HtmlEmail email = new HtmlEmail(); setEmailSettings(email); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java index e89fc8a31c2..8dca6805161 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java @@ -21,6 +21,7 @@ package org.sonar.server.notification.email; import java.net.MalformedURLException; import java.net.URL; +import java.time.Duration; import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; @@ -43,6 +44,7 @@ import org.sonar.server.issue.notification.EmailMessage; import org.sonar.server.issue.notification.EmailTemplate; import org.sonar.server.notification.NotificationChannel; +import static java.time.temporal.ChronoUnit.SECONDS; import static java.util.Objects.requireNonNull; /** @@ -60,10 +62,10 @@ public class EmailNotificationChannel extends NotificationChannel { private static final Logger LOG = LoggerFactory.getLogger(EmailNotificationChannel.class); /** - * @see org.apache.commons.mail.Email#setSocketConnectionTimeout(int) - * @see org.apache.commons.mail.Email#setSocketTimeout(int) + * @see org.apache.commons.mail.Email#setSocketConnectionTimeout(Duration) + * @see org.apache.commons.mail.Email#setSocketTimeout(Duration) */ - private static final int SOCKET_TIMEOUT = 30_000; + private static final Duration SOCKET_TIMEOUT = Duration.of(30, SECONDS); private static final Pattern PATTERN_LINE_BREAK = Pattern.compile("[\n\r]"); -- 2.39.5