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

Add HttpClientGitHubConnector and multirelease jar implementation #1300

Merged
merged 7 commits into from
Nov 19, 2021
Merged
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
17 changes: 6 additions & 11 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 11 ]
java: [ 8, 11 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK
Expand Down Expand Up @@ -90,17 +90,12 @@ jobs:
- name: Maven Install with Code Coverage
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
run: mvn -B clean install -D enable-ci --file pom.xml
- name: Codecov Report
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
uses: codecov/codecov-action@v2.1.0
# JDK 11+
- name: Maven Install without Code Coverage
if: matrix.os == 'windows' && !startsWith(matrix.java, '8')
- name: Maven Install without Code Coverage (Java 11+)
if: (!startsWith(matrix.java, '8'))
env:
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
run: mvn -B clean install --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
- name: Maven Install with Code Coverage
if: matrix.os != 'windows' && !startsWith(matrix.java, '8')
env:
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
- name: Codecov Report
if: matrix.os != 'windows' && startsWith(matrix.java, '11')
uses: codecov/codecov-action@v2.1.0
110 changes: 97 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@
<configuration>
<propertyName>jacoco.surefire.argLine</propertyName>
<!-- no need to get data about external code. It dramatically reduces performance of JaCoCo for nothing -->
<include>org.kohsuke.*</include>
<includes>
<include>org.kohsuke.*</include>
<include>org/kohsuke/*</include>
</includes>
<excludes>
<exclude>org/kohsuke/github/extras/HttpClientGitHubConnector*</exclude>
<exclude>org/kohsuke/github/extras/HttpClientGitHubConnector*.*</exclude>
<exclude>META-INF/versions/11/org/kohsuke/github/extras/HttpClientGitHubConnector*.*</exclude>
</excludes>
</configuration>
</execution>
<!-- attached to Maven test phase -->
Expand Down Expand Up @@ -153,14 +161,17 @@
</limit>
</limits>
<excludes>
<!-- Java 11 multi-release overlay problems -->
<exclude>org.kohsuke.github.extras.HttpClientGitHubConnector.**</exclude>
<exclude>org.kohsuke.github.extras.HttpClientGitHubConnector</exclude>

<!-- Code implemented externally -->
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory.**</exclude>
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory</exclude>

<!-- Sample only -->
<exclude>org.kohsuke.github.example.*</exclude>


<!-- Deprecated -->
<exclude>org.kohsuke.github.extras.OkHttpConnector</exclude>
<exclude>org.kohsuke.github.extras.OkHttp3Connector</exclude>
Expand Down Expand Up @@ -292,6 +303,11 @@
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
<ignores>
<!-- This is not idea, but we need to allow java.net.http.* in java11 module -->
<!-- Also, we still have a Java 8 CI build that protects against misuse -->
java.net.http.*
</ignores>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -585,17 +601,6 @@
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttp</argLine>
</configuration>
</execution>
<execution>
<id>okhttpconnector-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttpconnector</argLine>
</configuration>
</execution>
<execution>
<id>slow-or-flaky-test</id>
<phase>test</phase>
Expand Down Expand Up @@ -738,6 +743,85 @@
</plugins>
</build>
</profile>
<profile>
<id>multirelease</id>
<activation>
<jdk>[11,)</jdk>
<property>
<name>!test</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>compile-java-11</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>11</release>
<source>11</source>
<target>11</target>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>multirelease-test</id>
<activation>
<jdk>[11,)</jdk>
<property>
<name>!test</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>java11-jar-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
<useSystemClassLoader>false</useSystemClassLoader>
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=httpclient</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
<reporting>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.kohsuke.github.extras;

import org.kohsuke.github.connector.GitHubConnector;
import org.kohsuke.github.connector.GitHubConnectorRequest;
import org.kohsuke.github.connector.GitHubConnectorResponse;

import java.io.IOException;

/**
* {@link GitHubConnector} wrapper that sets timeout
*
* @author Liam Newman
*/
public class HttpClientGitHubConnector implements GitHubConnector {

/**
* Instantiates a new Impatient http connector.
*/
public HttpClientGitHubConnector() {
throw new UnsupportedOperationException("java.net.http.HttpClient is only supported in Java 11+.");
}

@Override
public GitHubConnectorResponse send(GitHubConnectorRequest connectorRequest) throws IOException {
throw new UnsupportedOperationException("java.net.http.HttpClient is only supported in Java 11+.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -106,7 +105,7 @@ private List<ConnectionSpec> TlsConnectionSpecs() {
*
* Implementation specific to {@link okhttp3.Response}.
*/
static class OkHttpGitHubConnectorResponse extends GitHubConnectorResponse {
private static class OkHttpGitHubConnectorResponse extends GitHubConnectorResponse {

private boolean bodyBytesRead = false;
private byte[] bodyBytes = null;
Expand All @@ -122,6 +121,7 @@ static class OkHttpGitHubConnectorResponse extends GitHubConnectorResponse {
/**
* {@inheritDoc}
*/
@Override
public InputStream bodyStream() throws IOException {
readBodyBytes();
InputStream stream = bodyBytes == null ? null : new ByteArrayInputStream(bodyBytes);
Expand Down Expand Up @@ -150,7 +150,6 @@ private void readBodyBytes() throws IOException {
*
* @param stream
* the stream to possibly wrap
*
*/
private InputStream wrapStream(InputStream stream) throws IOException {
String encoding = header("Content-Encoding");
Expand All @@ -166,7 +165,5 @@ private InputStream wrapStream(InputStream stream) throws IOException {
public void close() throws IOException {
response.close();
}

private static final Logger LOGGER = Logger.getLogger(OkHttpGitHubConnector.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import okhttp3.OkHttpClient;
import org.kohsuke.github.HttpConnector;
import org.kohsuke.github.connector.GitHubConnector;
import org.kohsuke.github.extras.HttpClientGitHubConnector;
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;
import org.kohsuke.github.extras.okhttp3.OkHttpGitHubConnector;

Expand Down Expand Up @@ -42,9 +43,16 @@ static GitHubConnector create(String defaultConnectorProperty) {
return new OkHttpGitHubConnector(new OkHttpClient.Builder().build());
} else if (defaultConnectorProperty.equalsIgnoreCase("okhttpconnector")) {
return new GitHubConnectorHttpConnectorAdapter(new OkHttpConnector(new OkHttpClient.Builder().build()));
} else if (defaultConnectorProperty.equalsIgnoreCase("urlconnection")
|| defaultConnectorProperty.equalsIgnoreCase("default")) {
} else if (defaultConnectorProperty.equalsIgnoreCase("urlconnection")) {
return new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
} else if (defaultConnectorProperty.equalsIgnoreCase("httpclient")) {
return new HttpClientGitHubConnector();
} else if (defaultConnectorProperty.equalsIgnoreCase("default")) {
// try {
// return new HttpClientGitHubConnector();
// } catch (UnsupportedOperationException | LinkageError e) {
return new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
// }
} else {
throw new IllegalStateException(
"Property 'test.github.connector' must reference a valid built-in connector - okhttp, okhttpconnector, urlconnection, or default.");
Expand Down
Loading