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

Perform CI code coverage in Java 11 #1304

Merged
merged 4 commits into from
Nov 20, 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
9 changes: 7 additions & 2 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ jobs:
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
uses: codecov/[email protected]
# JDK 11+
- name: Maven Install without Code Coverage (Java 11+)
if: (!startsWith(matrix.java, '8'))
- name: Maven Install without Code Coverage
if: matrix.os == 'windows' && !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"
89 changes: 46 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,36 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<configuration>
<!-- no need to get data about external code. It dramatically reduces performance of JaCoCo for nothing -->
<excludes>
<exclude>/org/kohsuke/github/extras/HttpClient*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>jacoco.surefire.argLine</propertyName>
<!-- no need to get data about external code. It dramatically reduces performance of JaCoCo for nothing -->
<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 -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>check</id>
<phase>test</phase>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
<rules>
<rule>
<element>BUNDLE</element>
Expand Down Expand Up @@ -231,6 +227,27 @@
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.20</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
<executions>
<execution>
<id>ensure-java-1.8-class-library</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -296,28 +313,6 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.20</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<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>
<id>ensure-java-1.8-class-library</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.infradna.tool</groupId>
Expand Down Expand Up @@ -592,22 +587,24 @@
<executions>
<execution>
<id>okhttp-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttp</argLine>
</configuration>
</execution>
<execution>
<id>slow-or-flaky-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classesDirectory>${project.basedir}/target/github-api-${project.version}.jar</classesDirectory>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
<!-- There are some tests that take longer or are a little
flaky. Run them here. -->
Expand Down Expand Up @@ -677,7 +674,7 @@
<rules>
<requireFilesExist>
<files>
<file>${project.build.directory}/jacoco.exec</file>
<file>${project.build.directory}/jacoco-it.exec</file>
</files>
</requireFilesExist>
</rules>
Expand Down Expand Up @@ -747,12 +744,18 @@
<id>multirelease</id>
<activation>
<jdk>[11,)</jdk>
<property>
<name>!test</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<ignores>
java.net.http.*
</ignores>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
Expand Down Expand Up @@ -804,7 +807,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>java11-jar-test</id>
<id>java11-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,4 @@ public int statusCode() {
public Map<String, List<String>> allHeaders() {
return headers;
}

/**
* Unwraps a {@link GitHubConnectorResponse} from a {@link HttpURLConnection} adapter.
*
* Only works on the internal {@link GitHubConnectorResponseHttpUrlConnectionAdapter}.
*
* @param connection
* the connection to unwrap.
* @return an unwrapped response from an adapter.
* @throws UnsupportedOperationException
* if the connection is not an adapter.
* @deprecated Only preset for testing and interaction with deprecated HttpURLConnection components.
*/
@Deprecated
public final static GitHubConnectorResponse fromHttpURLConnectionAdapter(HttpURLConnection connection) {
if (connection instanceof GitHubConnectorResponseHttpUrlConnectionAdapter) {
return ((GitHubConnectorResponseHttpUrlConnectionAdapter) connection).connectorResponse();
} else {
throw new UnsupportedOperationException(
"Cannot unwrap GitHubConnectorResponse from " + connection.getClass().getName());
}
}
}
44 changes: 24 additions & 20 deletions src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.kohsuke.github.connector.GitHubConnectorResponse;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -60,13 +59,6 @@ public void testHandler_Fail() throws Exception {
@Override
public void onError(IOException e, HttpURLConnection uc) throws IOException {

GitHubConnectorResponse connectorResponse = null;
try {
connectorResponse = GitHubConnectorResponse.fromHttpURLConnectionAdapter(uc);
} catch (UnsupportedOperationException ex) {
assertThat(ex.getMessage(), startsWith("Cannot unwrap GitHubConnectorResponse"));
}

// Verify
assertThat(uc.getDate(), Matchers.greaterThanOrEqualTo(new Date().getTime() - 10000));
assertThat(uc.getExpiration(), equalTo(0L));
Expand All @@ -90,20 +82,34 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
// getting an input stream in an error case should throw
IOException ioEx = Assert.assertThrows(IOException.class, () -> uc.getInputStream());

InputStream errorStream = uc.getErrorStream();
assertThat(errorStream, notNullValue());
String error = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
assertThat(error, containsString("Must have push access to repository"));

if (connectorResponse != null) {
String connectorBody = IOUtils.toString(connectorResponse.bodyStream(),
StandardCharsets.UTF_8);
assertThat(connectorBody, containsString("Must have push access to repository"));
try (InputStream errorStream = uc.getErrorStream()) {
assertThat(errorStream, notNullValue());
String errorString = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
assertThat(errorString, containsString("Must have push access to repository"));
}

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

// calling again on a GitHubConnectorResponse should yield the same value
if (uc.toString().contains("GitHubConnectorResponseHttpUrlConnectionAdapter")) {
try (InputStream errorStream = uc.getErrorStream()) {
assertThat(errorStream, notNullValue());
String errorString = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
assertThat(errorString, containsString("Must have push access to repository"));
}
} else {
try (InputStream errorStream = uc.getErrorStream()) {
assertThat(errorStream, notNullValue());
String errorString = IOUtils.toString(errorStream, StandardCharsets.UTF_8);
fail();
assertThat(errorString, containsString("Must have push access to repository"));
} catch (IOException ex) {
assertThat(ex, notNullValue());
assertThat(ex.getMessage(), containsString("stream is closed"));
}
}

assertThat(uc.getHeaderFields(), instanceOf(Map.class));
assertThat(uc.getHeaderFields().size(), Matchers.greaterThan(25));
assertThat(uc.getHeaderField("Status"), equalTo("403 Forbidden"));
Expand All @@ -130,9 +136,7 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
Assert.assertThrows(IllegalStateException.class, () -> uc.setRequestProperty("bogus", "thing"));
Assert.assertThrows(IllegalStateException.class, () -> uc.setUseCaches(true));

if (connectorResponse != null) {
assertThat(uc.toString(),
containsString("GitHubConnectorResponseHttpUrlConnectionAdapter"));
if (uc.toString().contains("GitHubConnectorResponseHttpUrlConnectionAdapter")) {

Assert.assertThrows(UnsupportedOperationException.class,
() -> uc.getAllowUserInteraction());
Expand Down