Skip to content

Commit c8cfb0f

Browse files
committed
Update okhttp3
1 parent f7f69c9 commit c8cfb0f

5 files changed

Lines changed: 36 additions & 51 deletions

File tree

pom.xml

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
8-
<version>3.57</version>
8+
<version>4.2</version>
99
<relativePath />
1010
</parent>
1111

@@ -47,7 +47,7 @@
4747
</issueManagement>
4848

4949
<properties>
50-
<jenkins.version>2.60.3</jenkins.version>
50+
<jenkins.version>2.164.3</jenkins.version>
5151
<release.skipTests>false</release.skipTests>
5252
<maven.javadoc.skip>true</maven.javadoc.skip>
5353
<findbugs-maven-plugin.version>3.0.4</findbugs-maven-plugin.version>
@@ -79,23 +79,10 @@
7979
<version>3.9</version>
8080
</dependency>
8181

82-
<dependency>
83-
<groupId>org.slf4j</groupId>
84-
<artifactId>slf4j-jdk14</artifactId>
85-
<version>${slf4jVersion}</version>
86-
</dependency>
87-
88-
<dependency>
89-
<groupId>com.squareup.okhttp</groupId>
90-
<artifactId>okhttp-urlconnection</artifactId>
91-
<version>2.7.5</version>
92-
<optional>false</optional>
93-
</dependency>
94-
9582
<dependency>
9683
<groupId>org.jenkins-ci.plugins</groupId>
9784
<artifactId>github-api</artifactId>
98-
<version>1.90</version>
85+
<version>1.114.2</version>
9986
</dependency>
10087

10188
<dependency>
@@ -143,14 +130,14 @@
143130
<dependency>
144131
<groupId>org.jenkins-ci.modules</groupId>
145132
<artifactId>instance-identity</artifactId>
146-
<version>2.1</version><!-- Version matches https://mvnrepository.com/artifact/org.jenkins-ci.main/jenkins-war/2.60.3 -->
133+
<version>2.2</version>
147134
<scope>provided</scope><!-- https://wiki.jenkins.io/display/JENKINS/Instance+Identity "add a provided scope dependency to this module into your plugin" -->
148135
</dependency>
149136

150137
<dependency>
151138
<groupId>javax.servlet</groupId>
152139
<artifactId>javax.servlet-api</artifactId>
153-
<scope>provided</scope><!-- Provided by core: https://mvnrepository.com/artifact/org.jenkins-ci.main/jenkins-core/2.60.3 -->
140+
<scope>provided</scope>
154141
</dependency>
155142

156143
<!--TEST DEPS-->
@@ -312,6 +299,16 @@
312299

313300
</dependencies>
314301

302+
<dependencyManagement>
303+
<dependencies>
304+
<dependency>
305+
<groupId>org.jenkins-ci</groupId>
306+
<artifactId>annotation-indexer</artifactId>
307+
<version>1.12</version>
308+
</dependency>
309+
</dependencies>
310+
</dependencyManagement>
311+
315312
<build>
316313
<plugins>
317314
<plugin>

src/main/java/org/jenkinsci/plugins/github/internal/GitHubClientCacheOps.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import com.google.common.base.Function;
55
import com.google.common.base.Predicate;
66
import com.google.common.hash.Hashing;
7-
import com.squareup.okhttp.Cache;
7+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
8+
import okhttp3.Cache;
89
import org.apache.commons.io.FileUtils;
910
import org.jenkinsci.plugins.github.GitHubPlugin;
1011
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
@@ -94,6 +95,7 @@ public static Path getBaseCacheDir() {
9495
*
9596
* @param configs active server configs to exclude caches from cleanup
9697
*/
98+
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
9799
public static void clearRedundantCaches(List<GitHubServerConfig> configs) {
98100
Path baseCacheDir = getBaseCacheDir();
99101

@@ -170,7 +172,7 @@ private static String hashed(GitHubServerConfig config) {
170172
private static class CacheToName extends NullSafeFunction<Cache, String> {
171173
@Override
172174
protected String applyNullSafe(@Nonnull Cache cache) {
173-
return cache.getDirectory().getName();
175+
return cache.directory().getName();
174176
}
175177
}
176178

src/main/java/org/jenkinsci/plugins/github/internal/GitHubLoginFunction.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
package org.jenkinsci.plugins.github.internal;
22

33
import com.cloudbees.jenkins.GitHubWebHook;
4-
import com.squareup.okhttp.Cache;
5-
import com.squareup.okhttp.OkHttpClient;
6-
import com.squareup.okhttp.OkUrlFactory;
4+
import okhttp3.Cache;
5+
import okhttp3.OkHttpClient;
76
import jenkins.model.Jenkins;
87
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
98
import org.jenkinsci.plugins.github.util.misc.NullSafeFunction;
109
import org.kohsuke.accmod.Restricted;
1110
import org.kohsuke.accmod.restrictions.NoExternalUse;
1211
import org.kohsuke.github.GitHub;
1312
import org.kohsuke.github.GitHubBuilder;
14-
import org.kohsuke.github.HttpConnector;
1513
import org.kohsuke.github.RateLimitHandler;
14+
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;
1615
import org.slf4j.Logger;
1716
import org.slf4j.LoggerFactory;
1817

1918
import javax.annotation.CheckForNull;
2019
import javax.annotation.Nonnull;
2120
import java.io.IOException;
22-
import java.net.HttpURLConnection;
2321
import java.net.MalformedURLException;
2422
import java.net.Proxy;
2523
import java.net.URL;
@@ -46,6 +44,7 @@
4644
@Restricted(NoExternalUse.class)
4745
public class GitHubLoginFunction extends NullSafeFunction<GitHubServerConfig, GitHub> {
4846

47+
private static final OkHttpClient BASECLIENT = new OkHttpClient();
4948
private static final Logger LOGGER = LoggerFactory.getLogger(GitHubLoginFunction.class);
5049

5150
/**
@@ -107,31 +106,15 @@ private Proxy getProxy(String apiUrl) {
107106
* @return connector to be used as backend for client
108107
*/
109108
private OkHttpConnector connector(GitHubServerConfig config) {
110-
OkHttpClient client = new OkHttpClient().setProxy(getProxy(defaultIfBlank(config.getApiUrl(), GITHUB_URL)));
109+
OkHttpClient.Builder builder = BASECLIENT.newBuilder()
110+
.proxy(getProxy(defaultIfBlank(config.getApiUrl(), GITHUB_URL)));
111+
111112

112113
if (config.getClientCacheSize() > 0) {
113114
Cache cache = toCacheDir().apply(config);
114-
client.setCache(cache);
115-
}
116-
117-
return new OkHttpConnector(new OkUrlFactory(client));
118-
}
119-
120-
/**
121-
* Copy-paste due to class loading issues
122-
*
123-
* @see org.kohsuke.github.extras.OkHttpConnector
124-
*/
125-
private static class OkHttpConnector implements HttpConnector {
126-
private final OkUrlFactory urlFactory;
127-
128-
private OkHttpConnector(OkUrlFactory urlFactory) {
129-
this.urlFactory = urlFactory;
115+
builder.cache(cache);
130116
}
131117

132-
@Override
133-
public HttpURLConnection connect(URL url) throws IOException {
134-
return urlFactory.open(url);
135-
}
118+
return new OkHttpConnector(builder.build());
136119
}
137120
}

src/main/java/org/jenkinsci/plugins/github/util/JobInfoHelpers.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import hudson.model.Item;
1010
import hudson.model.Job;
1111
import hudson.triggers.Trigger;
12+
import hudson.triggers.TriggerDescriptor;
1213
import jenkins.model.ParameterizedJobMixIn;
1314
import org.jenkinsci.plugins.github.extension.GHEventsSubscriber;
1415

1516
import javax.annotation.CheckForNull;
1617
import java.util.Collection;
18+
import java.util.Map;
1719

1820
import static org.jenkinsci.plugins.github.extension.GHEventsSubscriber.isApplicableFor;
1921
import static org.jenkinsci.plugins.github.util.FluentIterableWrapper.from;
@@ -111,7 +113,8 @@ public static <T extends Trigger> T triggerFrom(Item item, Class<T> tClass) {
111113
if (item instanceof ParameterizedJobMixIn.ParameterizedJob) {
112114
ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) item;
113115

114-
for (Trigger candidate : pJob.getTriggers().values()) {
116+
Map<TriggerDescriptor, Trigger<?>> triggerMap = pJob.getTriggers();
117+
for (Trigger candidate : triggerMap.values()) {
115118
if (tClass.isInstance(candidate)) {
116119
return tClass.cast(candidate);
117120
}

src/test/java/org/jenkinsci/plugins/github/internal/GitHubClientCacheOpsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.jenkinsci.plugins.github.internal;
22

3-
import com.squareup.okhttp.Cache;
3+
import okhttp3.Cache;
44
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
55
import org.junit.ClassRule;
66
import org.junit.Rule;
@@ -43,7 +43,7 @@ public void shouldPointToSameCacheForOneConfig() throws Exception {
4343
Cache cache2 = toCacheDir().apply(config);
4444

4545
assertThat("same config should get same cache",
46-
cache1.getDirectory().getAbsolutePath(), equalTo(cache2.getDirectory().getAbsolutePath()));
46+
cache1.directory().getAbsolutePath(), equalTo(cache2.directory().getAbsolutePath()));
4747
}
4848

4949
@Test
@@ -57,7 +57,7 @@ public void shouldPointToDifferentCachesOnChangedApiPath() throws Exception {
5757
Cache cache2 = toCacheDir().apply(config2);
5858

5959
assertThat("with changed url",
60-
cache1.getDirectory().getAbsolutePath(), not(cache2.getDirectory().getAbsolutePath()));
60+
cache1.directory().getAbsolutePath(), not(cache2.directory().getAbsolutePath()));
6161
}
6262

6363
@Test
@@ -69,7 +69,7 @@ public void shouldPointToDifferentCachesOnChangedCreds() throws Exception {
6969
Cache cache2 = toCacheDir().apply(config2);
7070

7171
assertThat("with changed creds",
72-
cache1.getDirectory().getAbsolutePath(), not(cache2.getDirectory().getAbsolutePath()));
72+
cache1.directory().getAbsolutePath(), not(cache2.directory().getAbsolutePath()));
7373
}
7474

7575
@Test

0 commit comments

Comments
 (0)