Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#35)!: update dependencies according new Jenkins version(2.379+) #36

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.19</version>
<version>4.54</version>
</parent>

<properties>
<jenkins.version>1.653</jenkins.version>
<java.level>7</java.level>
<jenkins.version>2.379</jenkins.version>
<java.level>11</java.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jenkins.plugin.workflow.version>1.11</jenkins.plugin.workflow.version>
<jenkins.plugin.structs.version>1.2</jenkins.plugin.structs.version>
<jenkins.plugin.junit.version>1.19</jenkins.plugin.junit.version>
<junit.version>4.12</junit.version>
<mockito.version>1.10.19</mockito.version>
<mockito.version>4.11.0</mockito.version>
<powermock.version>1.7.4</powermock.version>
<objenesis.version>2.6</objenesis.version>
<mockserver.version>5.4.1</mockserver.version>
Expand Down Expand Up @@ -54,6 +54,12 @@
<artifactId>junit</artifactId>
<version>${jenkins.plugin.junit.version}</version>
</dependency>
<!-- See Jenkins changelog 2.379 (2022-11-22)-->
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-httpclient3-api</artifactId>
<version>3.1-3</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -69,7 +75,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jenkins/plugins/zulip/DescriptorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public DescriptorImpl() {
} else {
XStream2 xstream = new XStream2();
xstream.alias("hudson.plugins.humbug.DescriptorImpl", DescriptorImpl.class);
XmlFile oldConfig = new XmlFile(xstream, new File(Jenkins.getInstance().getRootDir(), OLD_CONFIG_FILE_NAME));
XmlFile oldConfig = new XmlFile(xstream, new File(Jenkins.getInstanceOrNull().getRootDir(), OLD_CONFIG_FILE_NAME));
if (oldConfig.exists()) {
try {
oldConfig.unmarshal(this);
Expand Down Expand Up @@ -146,7 +146,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
save();

// Cleanup the configuration file from previous plugin id - humbug
File oldConfig = new File(Jenkins.getInstance().getRootDir(), OLD_CONFIG_FILE_NAME);
File oldConfig = new File(Jenkins.getInstanceOrNull().getRootDir(), OLD_CONFIG_FILE_NAME);
if (oldConfig.exists()) {
if (oldConfig.delete()) {
logger.log(Level.INFO, "Old humbug configuration file successfully cleaned up.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/plugins/zulip/Zulip.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Zulip(String url, String email, Secret apiKey) {
*/
protected void configureProxy(HttpClient httpClient) throws MalformedURLException {
LOGGER.log(Level.FINE, "Setting up HttpClient proxy");
ProxyConfiguration proxyConfiguration = Jenkins.getInstance().proxy;
ProxyConfiguration proxyConfiguration = Jenkins.getInstanceOrNull().proxy;
if (proxyConfiguration != null && ZulipUtil.isValueSet(proxyConfiguration.name)) {
URL urlObj = new URL(url);
Proxy proxy = proxyConfiguration.createProxy(urlObj.getHost());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/plugins/zulip/ZulipSendStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ZulipSendStep() {
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener)
throws InterruptedException, IOException {
jenkins.plugins.zulip.DescriptorImpl globalConfig =
Jenkins.getInstance().getDescriptorByType(jenkins.plugins.zulip.DescriptorImpl.class);
Jenkins.getInstanceOrNull().getDescriptorByType(jenkins.plugins.zulip.DescriptorImpl.class);
Zulip zulip = new Zulip(globalConfig.getUrl(), globalConfig.getEmail(), globalConfig.getApiKey());
String stream = ZulipUtil.expandVariables(run, listener, ZulipUtil.getDefaultValue(getStream(), globalConfig.getStream()));
String defaultTopic = displayItem(run.getParent(), globalConfig, globalConfig.isFullJobPathAsDefaultTopic(), false);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/plugins/zulip/ZulipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static String getDefaultValue(String value, String defaultValue) {
* @return The Jenkins instance Url
*/
public static String getJenkinsUrl(DescriptorImpl globalConfig) {
String jenkinsUrl = getDefaultValue(globalConfig.getJenkinsUrl(), Jenkins.getInstance().getRootUrl());
String jenkinsUrl = getDefaultValue(globalConfig.getJenkinsUrl(), Jenkins.getInstanceOrNull().getRootUrl());
if (jenkinsUrl != null && jenkinsUrl.length() > 0 && !jenkinsUrl.endsWith("/")) {
jenkinsUrl = jenkinsUrl + "/";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
package jenkins.plugins.zulip;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.User;
import hudson.Launcher;
import hudson.model.*;
import hudson.scm.ChangeLogSet;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.FakeChangeLogSCM;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
Expand All @@ -30,16 +19,13 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

import java.util.Arrays;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.verifyNew;
import static org.powermock.api.mockito.PowerMockito.when;

Expand Down Expand Up @@ -91,10 +77,10 @@ public class ZulipNotifierFullJobPathTest {
public void setUp() throws Exception {
PowerMockito.whenNew(Zulip.class).withAnyArguments().thenReturn(zulip);
PowerMockito.mockStatic(Jenkins.class);
when(Jenkins.getInstance()).thenReturn(jenkins);
when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
when(jenkins.getDisplayName()).thenReturn("Jenkins");
PowerMockito.mockStatic(User.class);
when(User.get(anyString())).thenAnswer(new Answer<User>() {
when(User.getOrCreateByIdOrFullName(anyString())).thenAnswer(new Answer<User>() {
@Override
public User answer(InvocationOnMock invocation) throws Throwable {
String arg = (String) invocation.getArguments()[0];
Expand All @@ -121,7 +107,7 @@ public User answer(InvocationOnMock invocation) throws Throwable {
when(job.getParent()).thenReturn(folder);
when(folder.getDisplayName()).thenReturn("Folder");
when(folder.getUrl()).thenReturn("job/Folder");
when(folder.getParent()).thenReturn((ItemGroup)jenkins);
when(folder.getParent()).thenReturn((ItemGroup) jenkins);
when(build.getEnvironment(buildListener)).thenReturn(envVars);
when(envVars.expand(anyString())).thenAnswer(new Answer<String>() {
@Override
Expand All @@ -136,7 +122,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {
@Test
public void testShouldUseDefaults() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verifyNew(Zulip.class).withArguments(eq("zulipUrl"), eq("jenkins-bot@zulip.com"), any(Secret.class));
verify(envVars, times(2)).expand(expandCaptor.capture());
assertThat("Should expand stream, topic and message", expandCaptor.getAllValues(),
Expand All @@ -149,7 +135,7 @@ public void testShouldUseDefaults() throws Exception {
reset(zulip);
notifier.setStream("");
notifier.setTopic("");
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use default stream", "defaultStream", streamCaptor.getValue());
assertEquals("Should use default topic", "defaultTopic", topicCaptor.getValue());
Expand All @@ -160,7 +146,7 @@ public void testShouldUseProjectConfig() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
notifier.setStream("projectStream");
notifier.setTopic("projectTopic");
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use project stream", "projectStream", streamCaptor.getValue());
assertEquals("Should use topic stream", "projectTopic", topicCaptor.getValue());
Expand All @@ -172,7 +158,7 @@ public void testShouldUseFullJobPathAsTopic() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getTopic()).thenReturn("");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Topic should be project's full job path", "Folder » TestJob", topicCaptor.getValue());
assertEquals("Message should not contain project name", "**Build: **#1: **SUCCESS** :check_mark:", messageCaptor.getValue());
Expand All @@ -189,7 +175,7 @@ public void testJenkinsUrl() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getJenkinsUrl()).thenReturn("JenkinsUrl");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should contain links to Jenkins",
"**Project: **[Folder](JenkinsUrl/job/Folder) » [TestJob](JenkinsUrl/job/Folder/TestJob) : **Build: **[#1](JenkinsUrl/job/Folder/TestJob/1): **SUCCESS** :check_mark:",
Expand Down
41 changes: 21 additions & 20 deletions src/test/java/jenkins/plugins/zulip/ZulipNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import hudson.EnvVars;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Job;
Expand Down Expand Up @@ -32,10 +33,10 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -93,9 +94,9 @@ public class ZulipNotifierTest {
public void setUp() throws Exception {
PowerMockito.whenNew(Zulip.class).withAnyArguments().thenReturn(zulip);
PowerMockito.mockStatic(Jenkins.class);
when(Jenkins.getInstance()).thenReturn(jenkins);
when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
PowerMockito.mockStatic(User.class);
when(User.get(anyString())).thenAnswer(new Answer<User>() {
when(User.getOrCreateByIdOrFullName(anyString())).thenAnswer(new Answer<User>() {
@Override
public User answer(InvocationOnMock invocation) throws Throwable {
String arg = (String) invocation.getArguments()[0];
Expand Down Expand Up @@ -131,7 +132,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {
@Test
public void testShouldUseDefaults() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verifyNew(Zulip.class).withArguments(eq("zulipUrl"), eq("jenkins-bot@zulip.com"), any(Secret.class));
verify(envVars, times(2)).expand(expandCaptor.capture());
assertThat("Should expand stream, topic and message", expandCaptor.getAllValues(),
Expand All @@ -144,7 +145,7 @@ public void testShouldUseDefaults() throws Exception {
reset(zulip);
notifier.setStream("");
notifier.setTopic("");
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use default stream", "defaultStream", streamCaptor.getValue());
assertEquals("Should use default topic", "defaultTopic", topicCaptor.getValue());
Expand All @@ -154,7 +155,7 @@ public void testShouldUseDefaults() throws Exception {
public void testFailedBuild() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(build.getResult()).thenReturn(Result.FAILURE);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should be failed build", "**Project: **TestJob : **Build: **#1: **FAILURE** :cross_mark:", messageCaptor.getValue());
}
Expand All @@ -164,7 +165,7 @@ public void testUnstableBuild() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(build.getResult()).thenReturn(Result.UNSTABLE);
when(build.getAction(AbstractTestResultAction.class)).thenReturn(new FakeTestResultAction());
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should be unstable build", "**Project: **TestJob : **Build: **#1: **UNSTABLE** :warning: (50 broken tests)",
messageCaptor.getValue());
Expand All @@ -175,7 +176,7 @@ public void testShouldUseProjectConfig() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
notifier.setStream("projectStream");
notifier.setTopic("projectTopic");
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use project stream", "projectStream", streamCaptor.getValue());
assertEquals("Should use topic stream", "projectTopic", topicCaptor.getValue());
Expand All @@ -187,7 +188,7 @@ public void testShouldUseProjectNameAsTopic() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getTopic()).thenReturn("");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Topic should be project display name", "TestJob", topicCaptor.getValue());
assertEquals("Message should not contain project name", "**Build: **#1: **SUCCESS** :check_mark:", messageCaptor.getValue());
Expand All @@ -206,7 +207,7 @@ public void testChangeLogSet() throws Exception {
FakeChangeLogSCM.FakeChangeLogSet changeLogSet = new FakeChangeLogSCM.FakeChangeLogSet(build, changes);
when(build.getChangeSet()).thenReturn(changeLogSet);
ZulipNotifier notifier = new ZulipNotifier();
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should contain change log", "**Project: **TestJob : **Build: **#1: **SUCCESS** :check_mark:\n" +
"\n" +
Expand All @@ -222,7 +223,7 @@ public void testJenkinsUrl() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getJenkinsUrl()).thenReturn("JenkinsUrl");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should contain links to Jenkins",
"**Project: **[TestJob](JenkinsUrl/job/TestJob) : **Build: **[#1](JenkinsUrl/job/TestJob/1): **SUCCESS** :check_mark:",
Expand All @@ -243,27 +244,27 @@ public void testSmartNotify() throws Exception {
reset(zulip);
when(build.getPreviousBuild()).thenReturn(null);
when(build.getResult()).thenReturn(Result.SUCCESS);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
when(build.getResult()).thenReturn(Result.FAILURE);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip, times(2)).sendStreamMessage(anyString(), anyString(), anyString());
// If the previous build was a failure, notification should be sent no matter what
reset(zulip);
when(build.getPreviousBuild()).thenReturn(previousBuild);
when(previousBuild.getResult()).thenReturn(Result.FAILURE);
when(build.getResult()).thenReturn(Result.SUCCESS);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
when(build.getResult()).thenReturn(Result.FAILURE);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip, times(2)).sendStreamMessage(anyString(), anyString(), anyString());
// If the previous build was a success, notification should be sent only for failed builds
reset(zulip);
when(build.getPreviousBuild()).thenReturn(previousBuild);
when(previousBuild.getResult()).thenReturn(Result.SUCCESS);
when(build.getResult()).thenReturn(Result.SUCCESS);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
when(build.getResult()).thenReturn(Result.FAILURE);
notifier.perform(build, null, buildListener);
notifier.perform(build, (Launcher) null, buildListener);
verify(zulip, times(1)).sendStreamMessage(anyString(), anyString(), anyString());
} finally {
// Be sure to return global setting back to original setup so other tests dont fail
Expand Down
Loading