Skip to content

Commit e403ce4

Browse files
authored
Merge pull request hub4j#1304 from bitwiseman/task/codecoverage11
Task/codecoverage11
2 parents d46bca7 + 027d19a commit e403ce4

File tree

4 files changed

+77
-87
lines changed

4 files changed

+77
-87
lines changed

.github/workflows/maven-build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ jobs:
9494
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
9595
uses: codecov/[email protected]
9696
# JDK 11+
97-
- name: Maven Install without Code Coverage (Java 11+)
98-
if: (!startsWith(matrix.java, '8'))
97+
- name: Maven Install without Code Coverage
98+
if: matrix.os == 'windows' && !startsWith(matrix.java, '8')
9999
env:
100100
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
101101
run: mvn -B clean install --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
102+
- name: Maven Install with Code Coverage
103+
if: matrix.os != 'windows' && !startsWith(matrix.java, '8')
104+
env:
105+
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
106+
run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"

pom.xml

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,36 @@
103103
<groupId>org.jacoco</groupId>
104104
<artifactId>jacoco-maven-plugin</artifactId>
105105
<version>0.8.7</version>
106+
<configuration>
107+
<!-- no need to get data about external code. It dramatically reduces performance of JaCoCo for nothing -->
108+
<excludes>
109+
<exclude>/org/kohsuke/github/extras/HttpClient*</exclude>
110+
</excludes>
111+
</configuration>
106112
<executions>
107113
<execution>
108114
<goals>
109-
<goal>prepare-agent</goal>
115+
<goal>prepare-agent-integration</goal>
110116
</goals>
111117
<configuration>
112118
<propertyName>jacoco.surefire.argLine</propertyName>
113-
<!-- no need to get data about external code. It dramatically reduces performance of JaCoCo for nothing -->
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>
123119
</configuration>
124120
</execution>
125121
<!-- attached to Maven test phase -->
126122
<execution>
127123
<id>report</id>
128-
<phase>test</phase>
129124
<goals>
130-
<goal>report</goal>
125+
<goal>report-integration</goal>
131126
</goals>
132127
</execution>
133128
<execution>
134129
<id>check</id>
135-
<phase>test</phase>
130+
<phase>verify</phase>
136131
<goals>
137132
<goal>check</goal>
138133
</goals>
139134
<configuration>
135+
<dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
140136
<rules>
141137
<rule>
142138
<element>BUNDLE</element>
@@ -231,6 +227,27 @@
231227
<autoReleaseAfterClose>true</autoReleaseAfterClose>
232228
</configuration>
233229
</plugin>
230+
<plugin>
231+
<groupId>org.codehaus.mojo</groupId>
232+
<artifactId>animal-sniffer-maven-plugin</artifactId>
233+
<version>1.20</version>
234+
<configuration>
235+
<signature>
236+
<groupId>org.codehaus.mojo.signature</groupId>
237+
<artifactId>java18</artifactId>
238+
<version>1.0</version>
239+
</signature>
240+
</configuration>
241+
<executions>
242+
<execution>
243+
<id>ensure-java-1.8-class-library</id>
244+
<phase>test</phase>
245+
<goals>
246+
<goal>check</goal>
247+
</goals>
248+
</execution>
249+
</executions>
250+
</plugin>
234251
</plugins>
235252
</pluginManagement>
236253
<plugins>
@@ -296,28 +313,6 @@
296313
<plugin>
297314
<groupId>org.codehaus.mojo</groupId>
298315
<artifactId>animal-sniffer-maven-plugin</artifactId>
299-
<version>1.20</version>
300-
<configuration>
301-
<signature>
302-
<groupId>org.codehaus.mojo.signature</groupId>
303-
<artifactId>java18</artifactId>
304-
<version>1.0</version>
305-
</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>
311-
</configuration>
312-
<executions>
313-
<execution>
314-
<id>ensure-java-1.8-class-library</id>
315-
<phase>test</phase>
316-
<goals>
317-
<goal>check</goal>
318-
</goals>
319-
</execution>
320-
</executions>
321316
</plugin>
322317
<plugin>
323318
<groupId>com.infradna.tool</groupId>
@@ -592,22 +587,24 @@
592587
<executions>
593588
<execution>
594589
<id>okhttp-test</id>
595-
<phase>test</phase>
590+
<phase>integration-test</phase>
596591
<goals>
597592
<goal>test</goal>
598593
</goals>
599594
<configuration>
595+
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
600596
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
601597
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttp</argLine>
602598
</configuration>
603599
</execution>
604600
<execution>
605601
<id>slow-or-flaky-test</id>
606-
<phase>test</phase>
602+
<phase>integration-test</phase>
607603
<goals>
608604
<goal>test</goal>
609605
</goals>
610606
<configuration>
607+
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
611608
<rerunFailingTestsCount>2</rerunFailingTestsCount>
612609
<!-- There are some tests that take longer or are a little
613610
flaky. Run them here. -->
@@ -677,7 +674,7 @@
677674
<rules>
678675
<requireFilesExist>
679676
<files>
680-
<file>${project.build.directory}/jacoco.exec</file>
677+
<file>${project.build.directory}/jacoco-it.exec</file>
681678
</files>
682679
</requireFilesExist>
683680
</rules>
@@ -747,12 +744,18 @@
747744
<id>multirelease</id>
748745
<activation>
749746
<jdk>[11,)</jdk>
750-
<property>
751-
<name>!test</name>
752-
</property>
753747
</activation>
754748
<build>
755749
<plugins>
750+
<plugin>
751+
<groupId>org.codehaus.mojo</groupId>
752+
<artifactId>animal-sniffer-maven-plugin</artifactId>
753+
<configuration>
754+
<ignores>
755+
java.net.http.*
756+
</ignores>
757+
</configuration>
758+
</plugin>
756759
<plugin>
757760
<artifactId>maven-compiler-plugin</artifactId>
758761
<version>3.8.1</version>
@@ -804,7 +807,7 @@
804807
<artifactId>maven-surefire-plugin</artifactId>
805808
<executions>
806809
<execution>
807-
<id>java11-jar-test</id>
810+
<id>java11-test</id>
808811
<phase>integration-test</phase>
809812
<goals>
810813
<goal>test</goal>

src/main/java/org/kohsuke/github/connector/GitHubConnectorResponse.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,4 @@ public int statusCode() {
112112
public Map<String, List<String>> allHeaders() {
113113
return headers;
114114
}
115-
116-
/**
117-
* Unwraps a {@link GitHubConnectorResponse} from a {@link HttpURLConnection} adapter.
118-
*
119-
* Only works on the internal {@link GitHubConnectorResponseHttpUrlConnectionAdapter}.
120-
*
121-
* @param connection
122-
* the connection to unwrap.
123-
* @return an unwrapped response from an adapter.
124-
* @throws UnsupportedOperationException
125-
* if the connection is not an adapter.
126-
* @deprecated Only preset for testing and interaction with deprecated HttpURLConnection components.
127-
*/
128-
@Deprecated
129-
public final static GitHubConnectorResponse fromHttpURLConnectionAdapter(HttpURLConnection connection) {
130-
if (connection instanceof GitHubConnectorResponseHttpUrlConnectionAdapter) {
131-
return ((GitHubConnectorResponseHttpUrlConnectionAdapter) connection).connectorResponse();
132-
} else {
133-
throw new UnsupportedOperationException(
134-
"Cannot unwrap GitHubConnectorResponse from " + connection.getClass().getName());
135-
}
136-
}
137115
}

src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.hamcrest.Matchers;
66
import org.junit.Assert;
77
import org.junit.Test;
8-
import org.kohsuke.github.connector.GitHubConnectorResponse;
98

109
import java.io.IOException;
1110
import java.io.InputStream;
@@ -60,13 +59,6 @@ public void testHandler_Fail() throws Exception {
6059
@Override
6160
public void onError(IOException e, HttpURLConnection uc) throws IOException {
6261

63-
GitHubConnectorResponse connectorResponse = null;
64-
try {
65-
connectorResponse = GitHubConnectorResponse.fromHttpURLConnectionAdapter(uc);
66-
} catch (UnsupportedOperationException ex) {
67-
assertThat(ex.getMessage(), startsWith("Cannot unwrap GitHubConnectorResponse"));
68-
}
69-
7062
// Verify
7163
assertThat(uc.getDate(), Matchers.greaterThanOrEqualTo(new Date().getTime() - 10000));
7264
assertThat(uc.getExpiration(), equalTo(0L));
@@ -90,20 +82,34 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
9082
// getting an input stream in an error case should throw
9183
IOException ioEx = Assert.assertThrows(IOException.class, () -> uc.getInputStream());
9284

93-
InputStream errorStream = uc.getErrorStream();
94-
assertThat(errorStream, notNullValue());
95-
String error = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
96-
assertThat(error, containsString("Must have push access to repository"));
97-
98-
if (connectorResponse != null) {
99-
String connectorBody = IOUtils.toString(connectorResponse.bodyStream(),
100-
StandardCharsets.UTF_8);
101-
assertThat(connectorBody, containsString("Must have push access to repository"));
85+
try (InputStream errorStream = uc.getErrorStream()) {
86+
assertThat(errorStream, notNullValue());
87+
String errorString = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
88+
assertThat(errorString, containsString("Must have push access to repository"));
10289
}
10390

10491
// calling again should still error
10592
ioEx = Assert.assertThrows(IOException.class, () -> uc.getInputStream());
10693

94+
// calling again on a GitHubConnectorResponse should yield the same value
95+
if (uc.toString().contains("GitHubConnectorResponseHttpUrlConnectionAdapter")) {
96+
try (InputStream errorStream = uc.getErrorStream()) {
97+
assertThat(errorStream, notNullValue());
98+
String errorString = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
99+
assertThat(errorString, containsString("Must have push access to repository"));
100+
}
101+
} else {
102+
try (InputStream errorStream = uc.getErrorStream()) {
103+
assertThat(errorStream, notNullValue());
104+
String errorString = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
105+
fail();
106+
assertThat(errorString, containsString("Must have push access to repository"));
107+
} catch (IOException ex) {
108+
assertThat(ex, notNullValue());
109+
assertThat(ex.getMessage(), containsString("stream is closed"));
110+
}
111+
}
112+
107113
assertThat(uc.getHeaderFields(), instanceOf(Map.class));
108114
assertThat(uc.getHeaderFields().size(), Matchers.greaterThan(25));
109115
assertThat(uc.getHeaderField("Status"), equalTo("403 Forbidden"));
@@ -130,9 +136,7 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
130136
Assert.assertThrows(IllegalStateException.class, () -> uc.setRequestProperty("bogus", "thing"));
131137
Assert.assertThrows(IllegalStateException.class, () -> uc.setUseCaches(true));
132138

133-
if (connectorResponse != null) {
134-
assertThat(uc.toString(),
135-
containsString("GitHubConnectorResponseHttpUrlConnectionAdapter"));
139+
if (uc.toString().contains("GitHubConnectorResponseHttpUrlConnectionAdapter")) {
136140

137141
Assert.assertThrows(UnsupportedOperationException.class,
138142
() -> uc.getAllowUserInteraction());

0 commit comments

Comments
 (0)