Skip to content

Commit d46bca7

Browse files
authored
Merge pull request hub4j#1300 from bitwiseman/task/multirelease
Add HttpClientGitHubConnector and multirelease jar implementation
2 parents aad8b9a + 5699e58 commit d46bca7

File tree

9 files changed

+319
-37
lines changed

9 files changed

+319
-37
lines changed

.github/workflows/maven-build.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
strategy:
4747
fail-fast: false
4848
matrix:
49-
java: [ 11 ]
49+
java: [ 8, 11 ]
5050
steps:
5151
- uses: actions/checkout@v2
5252
- name: Set up JDK
@@ -90,17 +90,12 @@ jobs:
9090
- name: Maven Install with Code Coverage
9191
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
9292
run: mvn -B clean install -D enable-ci --file pom.xml
93+
- name: Codecov Report
94+
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
95+
uses: codecov/[email protected]
9396
# JDK 11+
94-
- name: Maven Install without Code Coverage
95-
if: matrix.os == 'windows' && !startsWith(matrix.java, '8')
97+
- name: Maven Install without Code Coverage (Java 11+)
98+
if: (!startsWith(matrix.java, '8'))
9699
env:
97100
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
98101
run: mvn -B clean install --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
99-
- name: Maven Install with Code Coverage
100-
if: matrix.os != 'windows' && !startsWith(matrix.java, '8')
101-
env:
102-
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
103-
run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
104-
- name: Codecov Report
105-
if: matrix.os != 'windows' && startsWith(matrix.java, '11')
106-
uses: codecov/[email protected]

pom.xml

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@
111111
<configuration>
112112
<propertyName>jacoco.surefire.argLine</propertyName>
113113
<!-- no need to get data about external code. It dramatically reduces performance of JaCoCo for nothing -->
114-
<include>org.kohsuke.*</include>
114+
<includes>
115+
<include>org.kohsuke.*</include>
116+
<include>org/kohsuke/*</include>
117+
</includes>
118+
<excludes>
119+
<exclude>org/kohsuke/github/extras/HttpClientGitHubConnector*</exclude>
120+
<exclude>org/kohsuke/github/extras/HttpClientGitHubConnector*.*</exclude>
121+
<exclude>META-INF/versions/11/org/kohsuke/github/extras/HttpClientGitHubConnector*.*</exclude>
122+
</excludes>
115123
</configuration>
116124
</execution>
117125
<!-- attached to Maven test phase -->
@@ -153,14 +161,17 @@
153161
</limit>
154162
</limits>
155163
<excludes>
164+
<!-- Java 11 multi-release overlay problems -->
165+
<exclude>org.kohsuke.github.extras.HttpClientGitHubConnector.**</exclude>
166+
<exclude>org.kohsuke.github.extras.HttpClientGitHubConnector</exclude>
167+
156168
<!-- Code implemented externally -->
157169
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory.**</exclude>
158170
<exclude>org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory</exclude>
159171

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

163-
164175
<!-- Deprecated -->
165176
<exclude>org.kohsuke.github.extras.OkHttpConnector</exclude>
166177
<exclude>org.kohsuke.github.extras.OkHttp3Connector</exclude>
@@ -292,6 +303,11 @@
292303
<artifactId>java18</artifactId>
293304
<version>1.0</version>
294305
</signature>
306+
<ignores>
307+
<!-- This is not idea, but we need to allow java.net.http.* in java11 module -->
308+
<!-- Also, we still have a Java 8 CI build that protects against misuse -->
309+
java.net.http.*
310+
</ignores>
295311
</configuration>
296312
<executions>
297313
<execution>
@@ -585,17 +601,6 @@
585601
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttp</argLine>
586602
</configuration>
587603
</execution>
588-
<execution>
589-
<id>okhttpconnector-test</id>
590-
<phase>test</phase>
591-
<goals>
592-
<goal>test</goal>
593-
</goals>
594-
<configuration>
595-
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
596-
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttpconnector</argLine>
597-
</configuration>
598-
</execution>
599604
<execution>
600605
<id>slow-or-flaky-test</id>
601606
<phase>test</phase>
@@ -738,6 +743,85 @@
738743
</plugins>
739744
</build>
740745
</profile>
746+
<profile>
747+
<id>multirelease</id>
748+
<activation>
749+
<jdk>[11,)</jdk>
750+
<property>
751+
<name>!test</name>
752+
</property>
753+
</activation>
754+
<build>
755+
<plugins>
756+
<plugin>
757+
<artifactId>maven-compiler-plugin</artifactId>
758+
<version>3.8.1</version>
759+
<executions>
760+
<execution>
761+
<id>compile-java-11</id>
762+
<phase>compile</phase>
763+
<goals>
764+
<goal>compile</goal>
765+
</goals>
766+
<configuration>
767+
<release>11</release>
768+
<source>11</source>
769+
<target>11</target>
770+
<compileSourceRoots>
771+
<compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
772+
</compileSourceRoots>
773+
<multiReleaseOutput>true</multiReleaseOutput>
774+
</configuration>
775+
</execution>
776+
</executions>
777+
</plugin>
778+
<plugin>
779+
<groupId>org.apache.maven.plugins</groupId>
780+
<artifactId>maven-jar-plugin</artifactId>
781+
<version>3.2.0</version>
782+
<configuration>
783+
<archive>
784+
<manifestEntries>
785+
<Multi-Release>true</Multi-Release>
786+
</manifestEntries>
787+
</archive>
788+
</configuration>
789+
</plugin>
790+
</plugins>
791+
</build>
792+
</profile>
793+
<profile>
794+
<id>multirelease-test</id>
795+
<activation>
796+
<jdk>[11,)</jdk>
797+
<property>
798+
<name>!test</name>
799+
</property>
800+
</activation>
801+
<build>
802+
<plugins>
803+
<plugin>
804+
<artifactId>maven-surefire-plugin</artifactId>
805+
<executions>
806+
<execution>
807+
<id>java11-jar-test</id>
808+
<phase>integration-test</phase>
809+
<goals>
810+
<goal>test</goal>
811+
</goals>
812+
<configuration>
813+
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
814+
<useSystemClassLoader>false</useSystemClassLoader>
815+
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
816+
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=httpclient</argLine>
817+
</configuration>
818+
</execution>
819+
</executions>
820+
</plugin>
821+
</plugins>
822+
</build>
823+
</profile>
824+
741825
</profiles>
742826
<reporting>
743827
<plugins>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.kohsuke.github.extras;
2+
3+
import org.kohsuke.github.connector.GitHubConnector;
4+
import org.kohsuke.github.connector.GitHubConnectorRequest;
5+
import org.kohsuke.github.connector.GitHubConnectorResponse;
6+
7+
import java.io.IOException;
8+
9+
/**
10+
* {@link GitHubConnector} wrapper that sets timeout
11+
*
12+
* @author Liam Newman
13+
*/
14+
public class HttpClientGitHubConnector implements GitHubConnector {
15+
16+
/**
17+
* Instantiates a new Impatient http connector.
18+
*/
19+
public HttpClientGitHubConnector() {
20+
throw new UnsupportedOperationException("java.net.http.HttpClient is only supported in Java 11+.");
21+
}
22+
23+
@Override
24+
public GitHubConnectorResponse send(GitHubConnectorRequest connectorRequest) throws IOException {
25+
throw new UnsupportedOperationException("java.net.http.HttpClient is only supported in Java 11+.");
26+
}
27+
}

src/main/java/org/kohsuke/github/extras/okhttp3/OkHttpGitHubConnector.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.concurrent.TimeUnit;
17-
import java.util.logging.Logger;
1817
import java.util.zip.GZIPInputStream;
1918

2019
import javax.annotation.Nonnull;
@@ -106,7 +105,7 @@ private List<ConnectionSpec> TlsConnectionSpecs() {
106105
*
107106
* Implementation specific to {@link okhttp3.Response}.
108107
*/
109-
static class OkHttpGitHubConnectorResponse extends GitHubConnectorResponse {
108+
private static class OkHttpGitHubConnectorResponse extends GitHubConnectorResponse {
110109

111110
private boolean bodyBytesRead = false;
112111
private byte[] bodyBytes = null;
@@ -122,6 +121,7 @@ static class OkHttpGitHubConnectorResponse extends GitHubConnectorResponse {
122121
/**
123122
* {@inheritDoc}
124123
*/
124+
@Override
125125
public InputStream bodyStream() throws IOException {
126126
readBodyBytes();
127127
InputStream stream = bodyBytes == null ? null : new ByteArrayInputStream(bodyBytes);
@@ -150,7 +150,6 @@ private void readBodyBytes() throws IOException {
150150
*
151151
* @param stream
152152
* the stream to possibly wrap
153-
*
154153
*/
155154
private InputStream wrapStream(InputStream stream) throws IOException {
156155
String encoding = header("Content-Encoding");
@@ -166,7 +165,5 @@ private InputStream wrapStream(InputStream stream) throws IOException {
166165
public void close() throws IOException {
167166
response.close();
168167
}
169-
170-
private static final Logger LOGGER = Logger.getLogger(OkHttpGitHubConnector.class.getName());
171168
}
172169
}

src/main/java/org/kohsuke/github/internal/DefaultGitHubConnector.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import okhttp3.OkHttpClient;
44
import org.kohsuke.github.HttpConnector;
55
import org.kohsuke.github.connector.GitHubConnector;
6+
import org.kohsuke.github.extras.HttpClientGitHubConnector;
67
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;
78
import org.kohsuke.github.extras.okhttp3.OkHttpGitHubConnector;
89

@@ -42,9 +43,16 @@ static GitHubConnector create(String defaultConnectorProperty) {
4243
return new OkHttpGitHubConnector(new OkHttpClient.Builder().build());
4344
} else if (defaultConnectorProperty.equalsIgnoreCase("okhttpconnector")) {
4445
return new GitHubConnectorHttpConnectorAdapter(new OkHttpConnector(new OkHttpClient.Builder().build()));
45-
} else if (defaultConnectorProperty.equalsIgnoreCase("urlconnection")
46-
|| defaultConnectorProperty.equalsIgnoreCase("default")) {
46+
} else if (defaultConnectorProperty.equalsIgnoreCase("urlconnection")) {
4747
return new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
48+
} else if (defaultConnectorProperty.equalsIgnoreCase("httpclient")) {
49+
return new HttpClientGitHubConnector();
50+
} else if (defaultConnectorProperty.equalsIgnoreCase("default")) {
51+
// try {
52+
// return new HttpClientGitHubConnector();
53+
// } catch (UnsupportedOperationException | LinkageError e) {
54+
return new GitHubConnectorHttpConnectorAdapter(HttpConnector.DEFAULT);
55+
// }
4856
} else {
4957
throw new IllegalStateException(
5058
"Property 'test.github.connector' must reference a valid built-in connector - okhttp, okhttpconnector, urlconnection, or default.");

0 commit comments

Comments
 (0)