Skip to content

Commit

Permalink
Bump plugin baseline to 2.164.3 and code cleanup (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Aug 16, 2019
1 parent 2ff124f commit e0fc0fc
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 72 deletions.
7 changes: 6 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
// Builds a module using https://github.com/jenkins-infra/pipeline-library
buildPlugin(platforms: ['linux'], useAci: true)
def configurations = [
[ platform: "linux", jdk: "8", jenkins: null ]
// tests need some work for java 11
// [ platform: "linux", jdk: "11", jenkins: null, javaLevel: "8" ]
]
buildPlugin(configurations: configurations, useAci: true)
4 changes: 3 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter" />
<module name="NewlineAtEndOfFile" />
Expand Down
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.42</version>
<version>3.48</version>
</parent>

<artifactId>slack</artifactId>
Expand All @@ -16,16 +16,16 @@
<url>http://wiki.jenkins-ci.org/display/JENKINS/Slack+Plugin</url>

<properties>
<jenkins.version>2.138.4</jenkins.version>
<jenkins.version>2.164.3</jenkins.version>
<hpi.compatibleSinceVersion>2.0</hpi.compatibleSinceVersion>

<revision>2.4</revision>
<changelist>-SNAPSHOT</changelist>
<java.level>8</java.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<hamcrest.version>1.3</hamcrest.version>
<configuration-as-code.version>1.20</configuration-as-code.version>
<hamcrest.version>2.1</hamcrest.version>
<configuration-as-code.version>1.27</configuration-as-code.version>
</properties>

<licenses>
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom</artifactId>
<version>2.138.1</version>
<version>2.164.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand All @@ -81,17 +81,17 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
<version>2.9.9</version>
<version>2.9.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
<version>4.5.9</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -102,7 +102,7 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
<version>1.13</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -112,7 +112,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
<version>1.4</version>
<version>1.5</version>
</dependency>
<!-- for workflow support -->
<dependency>
Expand Down Expand Up @@ -209,7 +209,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.18</version>
<version>8.23</version>
</dependency>
</dependencies>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/plugins/slack/ActiveNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private String[] extractReplaceLinks(Matcher aTag, StringBuffer sb) {

public String escape(String string) {
StringBuffer pattern = new StringBuffer();
String[] links = extractReplaceLinks(aTag.matcher(string), pattern);
Object[] links = extractReplaceLinks(aTag.matcher(string), pattern);
return MessageFormat.format(escapeCharacters(pattern.toString()), links);
}

Expand Down
13 changes: 3 additions & 10 deletions src/main/java/jenkins/plugins/slack/SlackNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import hudson.model.BuildListener;
import hudson.model.Item;
import hudson.model.Project;
import hudson.security.ACL;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
Expand Down Expand Up @@ -47,7 +46,7 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.verb.POST;

import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
import static java.util.Collections.singletonList;

public class SlackNotifier extends Notifier {

Expand Down Expand Up @@ -782,7 +781,6 @@ public FormValidation doCheckBaseUrl(@QueryParameter String value, @QueryParamet
}

public ListBoxModel doFillTokenCredentialIdItems(@AncestorInPath Item context) {

Jenkins jenkins = Jenkins.get();

if(context == null && !jenkins.hasPermission(Jenkins.ADMINISTER) ||
Expand All @@ -791,13 +789,8 @@ public ListBoxModel doFillTokenCredentialIdItems(@AncestorInPath Item context) {
}

return new StandardListBoxModel()
.withEmptySelection()
.withAll(lookupCredentials(
StringCredentials.class,
context,
ACL.SYSTEM,
new HostnameRequirement("*.slack.com"))
);
.includeEmptyValue()
.include(context, StringCredentials.class, singletonList(new HostnameRequirement("*.slack.com")));
}

public boolean isApplicable(Class<? extends AbstractProject> aClass) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jenkins.plugins.slack;

import jenkins.plugins.slack.matrix.MatrixTriggerMode;
import jenkins.plugins.slack.user.SlackUserIdResolver;;
import jenkins.plugins.slack.user.SlackUserIdResolver;

public class SlackNotifierBuilder {
String baseUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* Borrowed from https://github.com/jenkinsci/hipchat-plugin
*/
package jenkins.plugins.slack.matrix;

import jenkins.plugins.slack.Messages;
Expand All @@ -20,7 +17,7 @@ public enum MatrixTriggerMode {
public final boolean forParent;
public final boolean forChild;

private MatrixTriggerMode(Localizable description, boolean forParent, boolean forChild) {
MatrixTriggerMode(Localizable description, boolean forParent, boolean forChild) {
this.description = description;
this.forParent = forParent;
this.forChild = forChild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ protected SlackUserIdResolverDescriptor() {

public static DescriptorExtensionList<SlackUserIdResolver, SlackUserIdResolverDescriptor> all() {
Jenkins jenkins = Jenkins.get();
return jenkins.<SlackUserIdResolver, SlackUserIdResolverDescriptor>getDescriptorList(SlackUserIdResolver.class);
return jenkins.getDescriptorList(SlackUserIdResolver.class);
}
}
13 changes: 3 additions & 10 deletions src/main/java/jenkins/plugins/slack/workflow/SlackSendStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import hudson.model.Project;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.security.ACL;
import hudson.util.ListBoxModel;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -41,7 +40,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
import static java.util.Collections.singletonList;

/**
* Workflow step to send a Slack channel notification.
Expand Down Expand Up @@ -235,7 +234,6 @@ public String getDisplayName() {
}

public ListBoxModel doFillTokenCredentialIdItems(@AncestorInPath Item item) {

Jenkins jenkins = Jenkins.get();

if (item == null && !jenkins.hasPermission(Jenkins.ADMINISTER) ||
Expand All @@ -244,13 +242,8 @@ public ListBoxModel doFillTokenCredentialIdItems(@AncestorInPath Item item) {
}

return new StandardListBoxModel()
.withEmptySelection()
.withAll(lookupCredentials(
StringCredentials.class,
item,
ACL.SYSTEM,
new HostnameRequirement("*.slack.com"))
);
.includeEmptyValue()
.include(item, StringCredentials.class, singletonList(new HostnameRequirement("*.slack.com")));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:section>
<f:entry field="userId" title="${%User Id}">
<f:textbox />
</f:entry>
<f:entry field="disableNotifications" title="${%Disable Notifications}">
<f:checkbox />
</f:entry>
</f:section>
<f:entry field="userId" title="${%User Id}">
<f:textbox/>
</f:entry>
<f:entry field="disableNotifications" title="${%Disable Notifications}">
<f:checkbox/>
</f:entry>
</j:jelly>
11 changes: 5 additions & 6 deletions src/test/java/jenkins/plugins/slack/CloseableHttpClientStub.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package jenkins.plugins.slack;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@SuppressWarnings("deprecation") // lots of deprecated abstract methods
public class CloseableHttpClientStub extends CloseableHttpClient {

private int numberOfCallsToExecuteMethod;
Expand All @@ -33,7 +30,8 @@ public CloseableHttpResponse execute(HttpUriRequest post) {
}

@Override
public ClientConnectionManager getConnectionManager() {
@SuppressWarnings("deprecation") // deprecated abstract method
public org.apache.http.conn.ClientConnectionManager getConnectionManager() {
return null;
}

Expand All @@ -43,7 +41,8 @@ public void close() {
}

@Override
public HttpParams getParams() {
@SuppressWarnings("deprecation") // deprecated abstract method
public org.apache.http.params.HttpParams getParams() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.params.HttpParams;

public class CloseableHttpResponseStub implements CloseableHttpResponse {

Expand Down Expand Up @@ -165,12 +164,14 @@ public HeaderIterator headerIterator(String s) {
}

@Override
public HttpParams getParams() {
@SuppressWarnings("deprecation") // deprecated abstract method
public org.apache.http.params.HttpParams getParams() {
return null;
}

@Override
public void setParams(HttpParams httpParams) {
@SuppressWarnings("deprecation") // deprecated abstract method
public void setParams(org.apache.http.params.HttpParams httpParams) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import hudson.scm.ChangeLogSet;
import hudson.tasks.MailAddressResolver;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import jenkins.plugins.slack.user.EmailSlackUserIdResolver;
Expand All @@ -42,8 +43,9 @@
import org.jvnet.hudson.test.FakeChangeLogSCM.FakeChangeLogSet;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.mock;
Expand Down Expand Up @@ -71,7 +73,7 @@ public EmailSlackUserIdResolverTest() throws IOException {
public void setUp() {
httpClient = new CloseableHttpClientStub();
mailAddressResolver = getMailAddressResolver();
resolver = getResolver(httpClient, mailAddressResolver);
resolver = getResolver(mailAddressResolver);
}

@Test
Expand All @@ -86,7 +88,7 @@ public void testResolveUserIdForEmailAddress() throws IOException {
// Test handling of an error response from Slack
httpClient.setHttpResponse(getResponseError());
userId = resolver.resolveUserIdForEmailAddress(EMAIL_ADDRESS);
assertEquals(null, userId);
assertNull(userId);
}

@Test
Expand All @@ -99,7 +101,7 @@ public void testResolveUserIdForUser() throws Exception {
}

@Test
public void testResolveUserIdForUserWithSlackUserProperty() throws Exception {
public void testResolveUserIdForUserWithSlackUserProperty() {
SlackUserProperty userProperty = new SlackUserProperty();
userProperty.setUserId(EXPECTED_USER_ID);
User mockUser = mock(User.class);
Expand Down Expand Up @@ -140,7 +142,7 @@ public void testResolveUserIdForChangelogSet() throws Exception {
}

private String readResource(String resourceName) throws IOException {
return IOUtils.toString(this.getClass().getResourceAsStream(resourceName));
return IOUtils.toString(this.getClass().getResourceAsStream(resourceName), StandardCharsets.UTF_8);
}

private CloseableHttpResponse getResponse(String content) throws IOException {
Expand All @@ -163,7 +165,7 @@ private MailAddressResolver getMailAddressResolver() {
return mailAddressResolver;
}

private EmailSlackUserIdResolver getResolver(CloseableHttpClientStub httpClientMailAddressResolver, MailAddressResolver mailAddressResolver) {
private EmailSlackUserIdResolver getResolver(MailAddressResolver mailAddressResolver) {
List<MailAddressResolver> mailAddressResolverList = new ArrayList<>();
mailAddressResolverList.add(mailAddressResolver);
return new EmailSlackUserIdResolver(AUTH_TOKEN, httpClient, mailAddressResolverList);
Expand Down
Loading

0 comments on commit e0fc0fc

Please sign in to comment.