Skip to content

Commit

Permalink
Switch to okhttp3.OkHttpConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed May 1, 2020
1 parent 6dc9a85 commit 5bac543
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
49 changes: 48 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.57</version>
<version>4.1</version>
<relativePath />
</parent>
<artifactId>github-branch-source</artifactId>
Expand All @@ -26,6 +26,10 @@
<hpi.compatibleSinceVersion>2.2.0</hpi.compatibleSinceVersion>
<java.level>8</java.level>
<jenkins.version>2.164.3</jenkins.version>
<scm-api.version>2.6.3</scm-api.version>
<hamcrest.version>2.2</hamcrest.version>
<okhttp3.version>4.4.0</okhttp3.version>
<okio.version>2.5.0</okio.version>
<useBeta>true</useBeta>
<jcasc.version>1.35</jcasc.version>
<jjwt.version>0.10.5</jjwt.version>
Expand Down Expand Up @@ -64,6 +68,18 @@
<artifactId>jjwt-api</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>${okio.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp3.version}</version>
</dependency>

<!-- Currently just here for interactive testing via hpi:run: -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
Expand Down Expand Up @@ -133,6 +149,12 @@
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.26</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
Expand All @@ -147,4 +169,29 @@
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-taglib-interface</goal>
</goals>
</execution>
</executions>
<configuration>
<compatibleSinceVersion>2.2.0</compatibleSinceVersion>
<!-- <pluginFirstClassLoader>true</pluginFirstClassLoader> -->
<maskClasses>
okhttp3.
okio.
</maskClasses>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.AbortException;
import hudson.Extension;
Expand Down Expand Up @@ -80,7 +79,7 @@
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import org.kohsuke.github.RateLimitHandler;
import org.kohsuke.github.extras.OkHttpConnector;
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;

import static java.util.logging.Level.FINE;

Expand All @@ -104,6 +103,8 @@ protected boolean removeEldestEntry(Map.Entry<String,Long> eldest) {
};
private static final Random ENTROPY = new Random();
private static final String SALT = Long.toHexString(ENTROPY.nextLong());
private static final OkHttpClient baseClient = new OkHttpClient();


private Connector() {
throw new IllegalAccessError("Utility class");
Expand Down Expand Up @@ -374,7 +375,8 @@ public static void checkApiUrlValidity(@Nonnull GitHub gitHub, @CheckForNull Sta
gb.withEndpoint(apiUrl);
gb.withRateLimitHandler(CUSTOMIZED);

OkHttpClient client = new OkHttpClient().setProxy(getProxy(host));
OkHttpClient.Builder clientBuilder = baseClient.newBuilder();
clientBuilder.proxy(getProxy(host));

int cacheSize = GitHubSCMSource.getCacheSize();
if (cacheSize > 0) {
Expand All @@ -396,11 +398,11 @@ public static void checkApiUrlValidity(@Nonnull GitHub gitHub, @CheckForNull Sta
}
if (cacheDir != null) {
Cache cache = new Cache(cacheDir, cacheSize * 1024L * 1024L);
client.setCache(cache);
clientBuilder.cache(cache);
}
}

gb.withConnector(new OkHttpConnector(new OkUrlFactory(client)));
gb.withConnector(new OkHttpConnector(clientBuilder.build()));

if (username != null) {
gb.withPassword(username, password);
Expand Down

0 comments on commit 5bac543

Please sign in to comment.