Skip to content

Commit bdd6815

Browse files
committed
Merge pull request #362 from npotluri-rh/additional-jdk-versions-on-ci-build
Fix build on Java 17
2 parents 8c16438 + 149150b commit bdd6815

11 files changed

Lines changed: 82 additions & 73 deletions

File tree

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* `buildPlugin` step provided by: https://github.com/jenkins-infra/pipeline-library */
44
buildPlugin(
55
useContainerAgent: true,
6+
failFast: false,
67
configurations: [
78
[platform: 'linux', jdk: 11],
89
[platform: 'linux', jdk: 17],

plugin/pom.xml

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,10 @@
4646

4747
<guava.version>32.1.1-jre</guava.version> <!-- version compatible with openstack4j -->
4848
<jsr305.version>1.3.9</jsr305.version>
49-
<openstack4j.version>3.10</openstack4j.version>
49+
<openstack4j.version>3.11</openstack4j.version>
5050
<okhttp.version>3.9.1</okhttp.version>
5151
<!-- Upper bound io.jenkins.configuration-as-code:test-harness -->
5252
<jenkins-test-harness.version>2064.vcd3b_b_8f3f2b_a_</jenkins-test-harness.version>
53-
<!-- Upper bound org.jenkins-ci.main:jenkins-test-harness -->
54-
<!-- <junit.version>5.10.0</junit.version>-->
55-
<jackson.version>2.15.3</jackson.version>
5653
</properties>
5754

5855
<developers>
@@ -107,7 +104,6 @@
107104
<dependency>
108105
<groupId>org.jenkins-ci.plugins</groupId>
109106
<artifactId>config-file-provider</artifactId>
110-
<version>3.7.1</version>
111107
</dependency>
112108
<dependency>
113109
<groupId>org.jenkins-ci.plugins</groupId>
@@ -151,6 +147,7 @@
151147
<artifactId>plexus-classworlds</artifactId>
152148
<version>2.4.2</version>
153149
</dependency>
150+
154151
<dependency>
155152
<groupId>org.jenkins-ci</groupId>
156153
<artifactId>symbol-annotation</artifactId>
@@ -160,28 +157,10 @@
160157
<artifactId>snakeyaml</artifactId>
161158
<version>2.2</version>
162159
</dependency>
163-
164-
<!--Specifying jenkins version to avoid maven.plugins.enforcer.RequireUpperBoundDeps error
165-
between configuration as code and openstack4j -->
166-
<dependency>
167-
<groupId>com.fasterxml.jackson.core</groupId>
168-
<artifactId>jackson-databind</artifactId>
169-
<version>${jackson.version}</version>
170-
</dependency>
171-
<dependency>
172-
<groupId>com.fasterxml.jackson.core</groupId>
173-
<artifactId>jackson-annotations</artifactId>
174-
<version>${jackson.version}</version>
175-
</dependency>
176-
<dependency>
177-
<groupId>com.fasterxml.jackson.core</groupId>
178-
<artifactId>jackson-core</artifactId>
179-
<version>${jackson.version}</version>
180-
</dependency>
181160
<dependency>
182-
<groupId>com.fasterxml.jackson.dataformat</groupId>
183-
<artifactId>jackson-dataformat-yaml</artifactId>
184-
<version>${jackson.version}</version>
161+
<groupId>org.jenkins-ci.plugins</groupId>
162+
<artifactId>jackson2-api</artifactId>
163+
<version>2.14.1-313.v504cdd45c18b</version>
185164
</dependency>
186165

187166
<!-- Test Dependencies -->
@@ -196,6 +175,7 @@
196175
<version>1.9.5</version>
197176
<scope>test</scope>
198177
</dependency>
178+
199179
<dependency>
200180
<groupId>org.jenkins-ci.plugins.workflow</groupId>
201181
<artifactId>workflow-cps</artifactId>
@@ -239,6 +219,12 @@
239219
<artifactId>test-harness</artifactId>
240220
<groupId>io.jenkins.configuration-as-code</groupId>
241221
<scope>test</scope>
222+
<exclusions>
223+
<exclusion>
224+
<groupId>org.jenkins-ci.plugins</groupId>
225+
<artifactId>jackson2-api</artifactId>
226+
</exclusion>
227+
</exclusions>
242228
</dependency>
243229
<!-- <dependency>-->
244230
<!-- <groupId>net.sourceforge.htmlunit</groupId>-->

plugin/src/test/java/jenkins/plugins/openstack/PluginTestRule.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
import hudson.slaves.NodeProperty;
2626
import hudson.slaves.NodeProvisioner.NodeProvisionerInvoker;
2727
import hudson.slaves.NodeProvisioner.PlannedNode;
28-
import hudson.slaves.OfflineCause;
2928
import hudson.util.FormValidation;
3029
import hudson.util.ProcessTree;
3130
import hudson.util.Secret;
3231
import hudson.util.StreamTaskListener;
3332
import jenkins.model.Jenkins;
3433
import jenkins.plugins.openstack.compute.JCloudsCleanupThread;
3534
import jenkins.plugins.openstack.compute.JCloudsCloud;
36-
import jenkins.plugins.openstack.compute.JCloudsComputer;
3735
import jenkins.plugins.openstack.compute.JCloudsPreCreationThread;
3836
import jenkins.plugins.openstack.compute.JCloudsSlave;
3937
import jenkins.plugins.openstack.compute.JCloudsSlaveTemplate;
@@ -90,13 +88,8 @@
9088
import java.util.stream.Collectors;
9189

9290
import static org.hamcrest.MatcherAssert.assertThat;
93-
import static org.mockito.Matchers.any;
94-
import static org.mockito.Mockito.RETURNS_SMART_NULLS;
95-
import static org.mockito.Mockito.doAnswer;
96-
import static org.mockito.Mockito.doCallRealMethod;
97-
import static org.mockito.Mockito.mock;
98-
import static org.mockito.Mockito.when;
99-
import static org.mockito.Mockito.withSettings;
91+
import static org.mockito.Mockito.*;
92+
10093

10194
/**
10295
* Test utils for plugin functional testing.

plugin/src/test/java/jenkins/plugins/openstack/compute/JCloudsSlaveTemplateTest.java

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Map;
99
import java.util.Properties;
1010
import java.util.stream.Stream;
11+
import java.lang.reflect.Field;
1112

1213
import org.htmlunit.html.HtmlForm;
1314
import hudson.util.FormValidation;
@@ -20,7 +21,6 @@
2021
import org.junit.Rule;
2122
import org.junit.Test;
2223
import org.mockito.ArgumentCaptor;
23-
import org.mockito.internal.util.reflection.Whitebox;
2424
import org.openstack4j.model.compute.BDMDestType;
2525
import org.openstack4j.model.compute.BDMSourceType;
2626
import org.openstack4j.model.compute.BlockDeviceMappingCreate;
@@ -36,12 +36,13 @@
3636

3737
import static jenkins.plugins.openstack.compute.JCloudsSlaveTemplate.parseSecurityGroups;
3838
import static jenkins.plugins.openstack.compute.JCloudsSlaveTemplate.selectNetworkIds;
39-
import static org.hamcrest.Matchers.*;
39+
import static org.hamcrest.Matchers.containsString;
40+
import static org.hamcrest.Matchers.equalTo;
41+
import static org.hamcrest.Matchers.hasSize;
4042
import static org.junit.Assert.*;
4143
import static org.junit.Assert.assertEquals;
4244
import static org.junit.Assert.assertNotNull;
4345
import static org.hamcrest.MatcherAssert.assertThat;
44-
import static org.mockito.Matchers.any;
4546
import static org.mockito.Mockito.*;
4647

4748
public class JCloudsSlaveTemplateTest {
@@ -275,9 +276,7 @@ private void testBootFromVolumeSnapshot(final String volumeSnapshotName, final S
275276
@SuppressWarnings("unchecked")
276277
private NovaBlockDeviceMappingCreate getBlockDeviceMapping(ServerCreateBuilder scbActual) {
277278
assertNotNull(scbActual);
278-
List<BlockDeviceMappingCreate> blockDeviceMapping = (List<BlockDeviceMappingCreate>) Whitebox.getInternalState(
279-
scbActual.build(), "blockDeviceMapping"
280-
);
279+
List<BlockDeviceMappingCreate> blockDeviceMapping = (List<BlockDeviceMappingCreate>) getInternalState(scbActual.build(), "blockDeviceMapping");
281280
assertThat(blockDeviceMapping, hasSize(1));
282281
return (NovaBlockDeviceMappingCreate) blockDeviceMapping.get(0);
283282
}
@@ -342,10 +341,43 @@ public void allowToUseVolumeSnapshotNameAsWellAsId() throws Exception {
342341
assertEquals("vs-id", getVolumeSnapshotId(builders.get(0)));
343342
assertEquals("something-else", getVolumeSnapshotId(builders.get(1)));
344343
}
344+
private static Object getInternalState(Object target, String field) {
345+
Class<?> c = target.getClass();
346+
try {
347+
Field f = getFieldFromHierarchy(c, field);
348+
f.setAccessible(true);
349+
return f.get(target);
350+
} catch (Exception e) {
351+
throw new RuntimeException("Unable to set internal state on a private field. Please report to mockito mailing list.", e);
352+
}
353+
}
354+
355+
private static Field getFieldFromHierarchy(Class<?> clazz, String field) {
356+
Field f = getField(clazz, field);
357+
while (f == null && clazz != Object.class) {
358+
clazz = clazz.getSuperclass();
359+
f = getField(clazz, field);
360+
}
361+
if (f == null) {
362+
throw new RuntimeException(
363+
"You want me to set value to this field: '" + field +
364+
"' on this class: '" + clazz.getSimpleName() +
365+
"' but this field is not declared withing hierarchy of this class!");
366+
}
367+
return f;
368+
}
369+
370+
private static Field getField(Class<?> clazz, String field) {
371+
try {
372+
return clazz.getDeclaredField(field);
373+
} catch (NoSuchFieldException e) {
374+
return null;
375+
}
376+
}
345377

346378
@SuppressWarnings("unchecked")
347379
private String getVolumeSnapshotId(ServerCreateBuilder builder) {
348-
List<BlockDeviceMappingCreate> mapping = (List<BlockDeviceMappingCreate>) Whitebox.getInternalState(
380+
List<BlockDeviceMappingCreate> mapping = (List<BlockDeviceMappingCreate>) getInternalState(
349381
builder.build(),
350382
"blockDeviceMapping"
351383
);

plugin/src/test/java/jenkins/plugins/openstack/compute/ProvisioningTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import static org.junit.Assert.*;
5757
import static org.mockito.Matchers.any;
5858
import static org.mockito.Matchers.anyInt;
59+
import static org.mockito.Matchers.anyString;
5960
import static org.mockito.Matchers.eq;
6061
import static org.mockito.Mockito.atLeastOnce;
6162
import static org.mockito.Mockito.mock;
@@ -101,7 +102,7 @@ public void abortProvisioningWhenOpenstackFails() throws Exception {
101102
JCloudsSlaveTemplate template = j.dummySlaveTemplate("label");
102103
JCloudsCloud cloud = j.dummyCloud(template);
103104
Openstack os = cloud.getOpenstack();
104-
when(os.bootAndWaitActive(any(ServerCreateBuilder.class), any(Integer.class))).thenThrow(new Openstack.ActionFailed("It is broken, alright!"));
105+
when(os.bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenThrow(new Openstack.ActionFailed("It is broken, alright!"));
105106

106107
FreeStyleProject p = j.createFreeStyleProject();
107108
p.setAssignedLabel(Label.get("label"));
@@ -110,7 +111,7 @@ public void abortProvisioningWhenOpenstackFails() throws Exception {
110111
Thread.sleep(1000);
111112
assertFalse(started.isDone());
112113

113-
verify(os, atLeastOnce()).bootAndWaitActive(any(ServerCreateBuilder.class), any(Integer.class));
114+
verify(os, atLeastOnce()).bootAndWaitActive(any(ServerCreateBuilder.class), anyInt());
114115
}
115116

116117
@Test @Issue("https://github.com/jenkinsci/openstack-cloud-plugin/issues/37")
@@ -119,8 +120,8 @@ public void detectBootTimingOut() {
119120
final JCloudsCloud cloud = j.dummyCloud(template);
120121
Openstack os = cloud.getOpenstack();
121122
Server server = j.mockServer().name("provisioned").status(Server.Status.BUILD).get();
122-
when(os.bootAndWaitActive(any(ServerCreateBuilder.class), any(Integer.class))).thenCallRealMethod();
123-
when(os._bootAndWaitActive(any(ServerCreateBuilder.class), any(Integer.class))).thenReturn(server);
123+
when(os.bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenCallRealMethod();
124+
when(os._bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenReturn(server);
124125
when(os.updateInfo(eq(server))).thenReturn(server);
125126

126127
try {
@@ -150,7 +151,7 @@ public void verifyOptionsPropagatedToLauncher() throws Exception {
150151
assertEquals(slave.getPublicAddress(), launcher.getHost());
151152
assertEquals("credid", launcher.getCredentialsId());
152153
//noinspection deprecation
153-
assertEquals("java", launcher.getJavaPath()); // https://github.com/jenkinsci/ssh-slaves-plugin/commit/9d25b12b1340e00d63a069f54c1b2361f745b6fc#commitcomment-49501649
154+
assertEquals("java", launcher.getHost()); // https://github.com/jenkinsci/ssh-slaves-plugin/commit/9d25b12b1340e00d63a069f54c1b2361f745b6fc#commitcomment-49501649
154155
assertEquals(expected.getJvmOptions(), launcher.getJvmOptions());
155156
assertEquals(10, (int) slave.getSlaveOptions().getRetentionTime());
156157

@@ -306,7 +307,7 @@ public void timeoutProvisioning() throws Exception {
306307
when(os._bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenReturn(null); // Timeout
307308
when(os.bootAndWaitActive(any(ServerCreateBuilder.class), anyInt())).thenCallRealMethod();
308309
Server server = mock(Server.class);
309-
when(os.getServersByName(any(String.class))).thenReturn(Collections.singletonList(server));
310+
when(os.getServersByName(anyString())).thenReturn(Collections.singletonList(server));
310311

311312
for (NodeProvisioner.PlannedNode pn : c.provision(Label.get("label"), 1)) {
312313
try {
@@ -472,7 +473,6 @@ public void failIfNoAccessIpFound() {
472473
private void verifyPreferredAddressUsed(String expectedAddress, Collection<NetworkAddress> addresses) throws Exception {
473474
CloudStatistics cs = CloudStatistics.get();
474475
assertThat(cs.getActivities(), Matchers.iterableWithSize(0));
475-
476476
j.autoconnectJnlpSlaves();
477477
JCloudsCloud cloud = j.configureSlaveProvisioning(j.dummyCloud(j.dummySlaveTemplate("label")), addresses);
478478

plugin/src/test/java/jenkins/plugins/openstack/compute/internal/OpenstackTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import static org.hamcrest.Matchers.containsString;
55
import static org.hamcrest.Matchers.equalTo;
66
import static org.junit.Assert.fail;
7-
import static org.mockito.Matchers.any;
8-
import static org.mockito.Matchers.anyMapOf;
9-
import static org.mockito.Matchers.argThat;
107
import static org.mockito.Mockito.*;
118

129
import org.junit.Before;
@@ -186,7 +183,7 @@ public void getImageIdsForGivenNameThenReturnsMatchingImageIdsSortedByAge() {
186183
when(mockImageNamedBar3.getCreatedAt()).thenReturn(new Date(1000));
187184
final ImageService mockIS = mock(ImageService.class);
188185
final List images = Arrays.asList(mockImageNamedBar1, mockImageNamedBar2, mockImageNamedBar3);
189-
when(mockIS.list(anyMapOf(String.class, String.class))).thenReturn(images);
186+
when(mockIS.list(anyMap())).thenReturn(images);
190187
final ArrayList<String> expected = new ArrayList<>(
191188
Arrays.asList("mockImageNamedBar2Id", "mockImageNamedBar3Id", "mockImageNamedBar1Id"));
192189

@@ -206,7 +203,7 @@ public void getImageIdsForGivenNameThenReturnsMatchingImageIdsSortedByAge() {
206203
@Test
207204
public void getImageIdsForGivenUnknownThenReturnsEmpty() {
208205
final ImageService mockIS = mock(ImageService.class);
209-
when(mockIS.list(anyMapOf(String.class, String.class))).thenReturn(Collections.EMPTY_LIST);
206+
when(mockIS.list(anyMap())).thenReturn(Collections.EMPTY_LIST);
210207

211208
when(osClient.imagesV2()).thenReturn(mockIS);
212209
final ArrayList<String> expected = new ArrayList<>();
@@ -230,7 +227,7 @@ public void getImageIdsForGivenIdOfActiveImageThenReturnsId() {
230227
when(mockImageNamedFoo.getName()).thenReturn("Foo");
231228
when(mockImageNamedFoo.getStatus()).thenReturn(Image.ImageStatus.ACTIVE);
232229
final ImageService mockIS = mock(ImageService.class);
233-
when(mockIS.list(anyMapOf(String.class, String.class))).thenReturn(Collections.EMPTY_LIST);
230+
when(mockIS.list(anyMap())).thenReturn(Collections.EMPTY_LIST);
234231
when(mockIS.get(imageId)).thenReturn(mockImageNamedFoo);
235232

236233
when(osClient.imagesV2()).thenReturn(mockIS);
@@ -239,7 +236,7 @@ public void getImageIdsForGivenIdOfActiveImageThenReturnsId() {
239236

240237
final List<String> actual = openstack.getImageIdsFor(imageId);
241238

242-
verify(mockIS).list(anyMapOf(String.class, String.class));
239+
verify(mockIS).list(anyMap());
243240
verify(mockIS).get(imageId);
244241
verifyNoMoreInteractions(mockIS);
245242
assertThat(new ArrayList<>(actual), equalTo(expected));
@@ -446,9 +443,9 @@ public void deleteAfterFailedBoot() {
446443
when(fault.getDetails()).thenReturn("I told you once");
447444
when(server.getFault()).thenReturn(fault);
448445

449-
doReturn(server).when(os)._bootAndWaitActive(any(ServerCreateBuilder.class), any(Integer.class));
446+
doReturn(server).when(os)._bootAndWaitActive((ServerCreateBuilder) any(ServerCreateBuilder.class), anyInt());
450447
doThrow(new Openstack.ActionFailed("Fake deletion failure")).when(os).destroyServer(server);
451-
doNothing().when(os).attachFingerprint(any(ServerCreateBuilder.class));
448+
doNothing().when(os).attachFingerprint((ServerCreateBuilder) any(ServerCreateBuilder.class));
452449

453450
try {
454451
os.bootAndWaitActive(mock(ServerCreateBuilder.class), 1);
@@ -476,9 +473,9 @@ public void deleteFloatingIpsWhenDeletingMachine() {
476473

477474
NetFloatingIPService fips = client.networking().floatingip();
478475
when(fips.list()).thenAnswer(sequencer.getAllFips());
479-
when(fips.delete(any(String.class))).thenAnswer(sequencer.deleteFip());
476+
when(fips.delete(anyString())).thenAnswer(sequencer.deleteFip());
480477
PortService ports = client.networking().port();
481-
when(ports.list(any(PortListOptions.class))).thenAnswer(sequencer.getAllPorts());
478+
when(ports.list((PortListOptions) any(PortListOptions.class))).thenAnswer(sequencer.getAllPorts());
482479

483480
Openstack os = new Openstack(client);
484481
os.destroyServer(server);

plugin/src/test/java/jenkins/plugins/openstack/compute/slaveopts/BootSourceTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
import static org.hamcrest.Matchers.containsString;
4848
import static org.junit.Assert.assertEquals;
4949
import static org.junit.Assert.fail;
50-
import static org.mockito.Matchers.any;
51-
import static org.mockito.Mockito.doReturn;
52-
import static org.mockito.Mockito.mock;
53-
import static org.mockito.Mockito.verify;
54-
import static org.mockito.Mockito.verifyNoMoreInteractions;
55-
import static org.mockito.Mockito.when;
50+
import static org.mockito.Mockito.*;
51+
//import static org.mockito.Mockito.doReturn;
52+
//import static org.mockito.Mockito.mock;
53+
//import static org.mockito.Mockito.verify;
54+
//import static org.mockito.Mockito.verifyNoMoreInteractions;
55+
//import static org.mockito.Mockito.when;
5656

5757
public class BootSourceTest {
5858
private static final FormValidation VALIDATION_REQUIRED = FormValidation.error(hudson.util.Messages._FormValidation_ValidateRequired().toString(US));

plugin/src/test/resources/jenkins/plugins/openstack/compute/JCloudsCloudTest/globalConfigMigrationFromV1/config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0' encoding='UTF-8'?>
22
<hudson>
33
<disabledAdministrativeMonitors/>
4-
<version>1.642.1</version>
4+
<version>2.387.1</version>
55
<numExecutors>2</numExecutors>
66
<mode>NORMAL</mode>
77
<useSecurity>true</useSecurity>
@@ -15,7 +15,7 @@
1515
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
1616
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
1717
<clouds>
18-
<jenkins.plugins.openstack.compute.JCloudsCloud plugin="openstack-cloud@1.8">
18+
<jenkins.plugins.openstack.compute.JCloudsCloud plugin="openstack-cloud">
1919
<name>OSCloud</name>
2020
<identity>tenant:user</identity>
2121
<credential>w52oEIGWBalT2GPsVd0pMODVwEohhbQ+fI8wOt0eVHo=</credential>

plugin/src/test/resources/jenkins/plugins/openstack/compute/JCloudsCloudTest/globalConfigMigrationFromV1/credentials.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials@1.24">
2+
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials">
33
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
44
<entry>
55
<com.cloudbees.plugins.credentials.domains.Domain>
66
<specifications/>
77
</com.cloudbees.plugins.credentials.domains.Domain>
88
<java.util.concurrent.CopyOnWriteArrayList>
9-
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials@1.11">
9+
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials">
1010
<scope>GLOBAL</scope>
1111
<id>2d07660b-c5c7-4e8b-82fd-a6ffe3429b39</id>
1212
<description></description>

0 commit comments

Comments
 (0)