]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21569 Remove usage of deprecated methods after upgrading commons-email.
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Thu, 8 Feb 2024 10:51:25 +0000 (11:51 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 8 Feb 2024 20:02:47 +0000 (20:02 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/email/EmailSender.java
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java

index b43deb8846d1bde21cf57a270c3803162acf7fb2..08d5f84c52445e81fb8f56d6853fde982155d513 100644 (file)
@@ -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<T extends BasicEmail> {
 
-  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<T extends BasicEmail> {
     }
   }
 
-  public HtmlEmail createEmail(T report)  throws MalformedURLException, EmailException {
+  public HtmlEmail createEmail(T report) throws MalformedURLException, EmailException {
     HtmlEmail email = new HtmlEmail();
 
     setEmailSettings(email);
index e89fc8a31c2f879967ada95d87e505a1a2f13e34..8dca6805161c6c62d793724311128dbfbc4eb6a8 100644 (file)
@@ -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]");