Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
� Conflicts:
�	pom.xml
  • Loading branch information
Pldi23 committed Jan 11, 2022
2 parents ac3d82b + cbda5ed commit d726a11
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 80 deletions.
2 changes: 0 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@

_extends: .github
tag-template: mailer-$NEXT_MINOR_VERSION
59 changes: 59 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins

name: cd
on:
workflow_dispatch:
check_run:
types:
- completed

jobs:
validate:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.verify-ci-status.outputs.result == 'success' && steps.interesting-categories.outputs.interesting == 'true' }}
steps:
- name: Verify CI status
uses: jenkins-infra/verify-ci-status-action@v1.2.0
id: verify-ci-status
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
output_result: true

- name: Release Drafter
uses: release-drafter/release-drafter@v5
if: steps.verify-ci-status.outputs.result == 'success'
with:
name: next
tag: next
version: next
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check interesting categories
uses: jenkins-infra/interesting-category-action@v1.0.0
id: interesting-categories
if: steps.verify-ci-status.outputs.result == 'success'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
runs-on: ubuntu-latest
needs: [validate]
if: needs.validate.outputs.should_release == 'true'
steps:
- name: Check out
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: 8
- name: Release
uses: jenkins-infra/jenkins-maven-cd-action@v1.1.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.1</version>
<version>1.3</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
-Dchangelist.format=%d.v%s
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ If your environment requires the use of SMTP authentication, specify the user na
Defaults to port `465`.
Other advanced configurations can be done by setting system properties. See this document for possible values and effects.
* **Use TLS**: Whether or not to use TLS for connecting to the SMTP server.
Defaults to port `465`.
Defaults to port `587`.
Other advanced configurations can be done by setting system properties. See this document for possible values and effects.
* **SMTP Port**: Port number for the mail server.
Leave it empty to use the default port for the protocol (`465` if using SSL, `25` if not).
Leave it empty to use the default port for the protocol (`587` if using TLS, `465` if using SSL, `25` if not using encryption).
* **Reply-To Address**: Address to include in the `Reply-To` header.
Up to version `1.16`, only one address is allowed, starting in version `1.17` more than one can be used.
* **Charset**: character set to use to construct the message.
Expand Down
62 changes: 33 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.27</version>
<version>4.32</version>
<relativePath />
</parent>

<artifactId>mailer</artifactId>
<packaging>hpi</packaging>
<version>${revision}${changelist}</version>
<version>${changelist}</version>
<name>Jenkins Mailer Plugin</name>
<description>This plugin allows you to configure email notifications for build results</description>
<url>https://github.com/jenkinsci/mailer-plugin</url>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>

<licenses>
<license>
Expand All @@ -22,18 +21,18 @@
</license>
</licenses>
<properties>
<revision>1.36</revision>
<changelist>-SNAPSHOT</changelist>
<changelist>999999-SNAPSHOT</changelist>
<java.level>8</java.level>
<jenkins.version>2.235.5</jenkins.version>
<jenkins.version>2.289.1</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.235.x</artifactId>
<version>918.vae501d2cdc99</version>
<artifactId>bom-2.289.x</artifactId>
<version>1075.v14bef33e5d7b</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand All @@ -54,31 +53,33 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
<exclusion> <!-- TODO pending https://github.com/jenkinsci/plugin-util-api-plugin/releases/tag/v2.9.0 in bom -->
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>instance-identity</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!--
This must come before javax-mail-api in the class path in order to avoid eclipse-ee4j/mail#350.
-->
<dependency>
<groupId>org.jvnet.mock-javamail</groupId>
<artifactId>mock-javamail</artifactId>
<version>1.9</version>
<version>1.12</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--
This must come after mock-javamail in the class path in order to avoid eclipse-ee4j/mail#350.
-->
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>javax-mail-api</artifactId>
<version>1.6.2-2</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand All @@ -101,6 +102,12 @@
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<scope>test</scope>
<exclusions>
<exclusion> <!-- Not even sure how this was possible to begin with? -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -140,9 +147,9 @@
</dependency>
</dependencies>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/mailer-plugin</url>
<connection>scm:git:git://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>
<repositories>
Expand All @@ -157,7 +164,4 @@
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<defaultGoal>clean hpi:run</defaultGoal>
</build>
</project>
6 changes: 3 additions & 3 deletions src/main/java/hudson/tasks/MailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.Transport;
Expand Down Expand Up @@ -460,7 +460,7 @@ String getCulpritsOfEmailList(AbstractProject upstreamProject, AbstractBuild<?,
/** If set, send to unauthorized users. Unauthorized users are users where {@link User#impersonate()} fails with a security-related exception. */
static /* not final */ boolean SEND_TO_UNAUTHORIZED_USERS = Boolean.getBoolean(MailSender.class.getName() + ".SEND_TO_UNAUTHORIZED_USERS");

@Nonnull
@NonNull
String getUserEmailList(TaskListener listener, AbstractBuild<?, ?> build) throws AddressException, UnsupportedEncodingException {
Set<User> users = build.getCulprits();
StringBuilder userEmails = new StringBuilder();
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/hudson/tasks/Mailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package hudson.tasks;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Util;
Expand Down Expand Up @@ -62,8 +63,6 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
Expand Down Expand Up @@ -215,8 +214,8 @@ public static InternetAddress StringToAddress(String strAddress, String charset)
* @throws UnsupportedEncodingException Unsupported encoding
* @since TODO
*/
public static @Nonnull InternetAddress stringToAddress(@Nonnull String strAddress,
@Nonnull String charset) throws AddressException, UnsupportedEncodingException {
public static @NonNull InternetAddress stringToAddress(@NonNull String strAddress,
@NonNull String charset) throws AddressException, UnsupportedEncodingException {
Matcher m = ADDRESS_PATTERN.matcher(strAddress);
if(!m.matches()) {
return new InternetAddress(strAddress);
Expand Down Expand Up @@ -263,8 +262,9 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>
@Deprecated
private transient String smtpAuthUsername;

@Deprecated

/** @deprecated as of 1.23, use {@link #authentication} */
@Deprecated
private transient Secret smtpAuthPassword;

private SMTPAuthentication authentication;
Expand Down Expand Up @@ -369,6 +369,7 @@ public Session createSession() {
private static Session createSession(String smtpHost, String smtpPort, boolean useSsl, boolean useTls, String smtpAuthUserName, Secret smtpAuthPassword) {
final String SMTP_PORT_PROPERTY = "mail.smtp.port";
final String SMTP_SOCKETFACTORY_PORT_PROPERTY = "mail.smtp.socketFactory.port";
final String SMTP_SSL_ENABLE_PROPERTY = "mail.smtp.ssl.enable";

smtpHost = Util.fixEmptyAndTrim(smtpHost);
smtpPort = Util.fixEmptyAndTrim(smtpPort);
Expand All @@ -393,11 +394,9 @@ private static Session createSession(String smtpHost, String smtpPort, boolean u
props.put(SMTP_PORT_PROPERTY, port);
props.put(SMTP_SOCKETFACTORY_PORT_PROPERTY, port);
}
if (props.getProperty("mail.smtp.socketFactory.class") == null) {
// TODO SocketFactory properties are now discouraged. Using (`mail.smtp.ssl.enable`, "true") should suffice
// https://javaee.github.io/javamail/FAQ#commonmistakes
// Example also found at https://javaee.github.io/javamail/FAQ#smtpssl
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
if (props.getProperty(SMTP_SSL_ENABLE_PROPERTY) == null) {
props.put(SMTP_SSL_ENABLE_PROPERTY, "true");
props.put("mail.smtp.ssl.checkserveridentity", true);
}
props.put("mail.smtp.socketFactory.fallback", "false");
if (props.getProperty("mail.smtp.ssl.checkserveridentity") == null) {
Expand Down Expand Up @@ -431,7 +430,9 @@ private static Session createSession(String smtpHost, String smtpPort, boolean u
}

private static Authenticator getAuthenticator(final String smtpAuthUserName, final String smtpAuthPassword) {
if(smtpAuthUserName==null) return null;
if(smtpAuthUserName == null) {
return null;
}
return new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
Expand All @@ -443,20 +444,18 @@ protected PasswordAuthentication getPasswordAuthentication() {
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {

// TODO(alfabravoteam): try-with-resources for BulkChange instance? (JENIINS-TODO)
BulkChange b = new BulkChange(this);
// Nested Describable (SMTPAuthentication) is not set to null in case it is not configured.
// To mitigate that, it is being set to null before (so it gets set to sent value or null correctly) and, in
// case of failure to databind, it gets reverted to previous value.
// Would not be necessary by https://github.com/jenkinsci/jenkins/pull/3669
SMTPAuthentication current = this.authentication;
try {

try (BulkChange b = new BulkChange(this)) {
this.authentication = null;
req.bindJSON(this, json);
b.commit();
} catch (IOException e) {
this.authentication = current;
b.abort();
throw new FormException("Failed to apply configuration", e, null);
}

Expand All @@ -472,8 +471,9 @@ public String getSmtpHost() {
return smtpHost;
}

@Deprecated

/** @deprecated as of 1.23, use {@link #getSmtpHost()} */
@Deprecated
public String getSmtpServer() {
return smtpHost;
}
Expand Down Expand Up @@ -710,7 +710,6 @@ public FormValidation doSendTestMail(
@QueryParameter String sendTestMailTo) throws IOException {
try {
Jenkins.get().checkPermission(DescriptorImpl.getJenkinsManageOrAdmin());

if (!authentication) {
username = null;
password = null;
Expand Down
Loading

0 comments on commit d726a11

Please sign in to comment.