From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:51:25 +0000 (+0100) Subject: SONAR-21569 Remove usage of deprecated methods after upgrading commons-email. X-Git-Tag: 10.5.0.89998~244 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4718f9b92c414ec1e8d1189bb917a78ead52f530;p=sonarqube.git SONAR-21569 Remove usage of deprecated methods after upgrading commons-email. --- 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]");