1
0
mirror of https://github.com/square/okhttp.git synced 2025-07-31 05:04:26 +03:00

Switch back to the kotlin JVM plugin (#8149)

* Switch back to the kotlin JVM plugin

This does a ton of file moves from jvmMain to main, and jvmTest to test.

* Don't use AnimalSniffer on okcurl

* Use assertk more (#8150)
This commit is contained in:
Jesse Wilson
2023-12-20 18:27:07 -05:00
committed by GitHub
parent 6b7b611308
commit c056530682
397 changed files with 260 additions and 325 deletions

View File

@ -80,7 +80,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: check -PandroidBuild=true -PgraalBuild=true -x test -x jvmTest
arguments: check -PandroidBuild=true -PgraalBuild=true -x test -x test
testopenjdk11:
permissions:
@ -108,7 +108,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=11
arguments: test -Dtest.java.version=11
- name: Publish Test Report
if: github.repository == 'square/okhttp' && github.ref == 'refs/heads/master'
@ -142,7 +142,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=11
arguments: test -Dtest.java.version=11
testopenjdk8:
runs-on: ubuntu-latest
@ -169,7 +169,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=8
arguments: test -Dtest.java.version=8
testopenjdk8alpn:
runs-on: ubuntu-latest
@ -202,7 +202,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=8 -Dokhttp.platform=jdk8alpn -Dalpn.boot.version=8.1.13.v20181017 -Dorg.gradle.java.installations.paths=/opt/hostedtoolcache/Java_Adopt_jdk/8.0.242-8.1/x64
arguments: test -Dtest.java.version=8 -Dokhttp.platform=jdk8alpn -Dalpn.boot.version=8.1.13.v20181017 -Dorg.gradle.java.installations.paths=/opt/hostedtoolcache/Java_Adopt_jdk/8.0.242-8.1/x64
testopenjsse:
runs-on: ubuntu-latest
@ -229,7 +229,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=8 -Dokhttp.platform=openjsse
arguments: test -Dtest.java.version=8 -Dokhttp.platform=openjsse
testconscrypt:
runs-on: ubuntu-latest
@ -256,7 +256,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=conscrypt
arguments: test -Dokhttp.platform=conscrypt
testbouncycastle:
runs-on: ubuntu-latest
@ -283,7 +283,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=bouncycastle
arguments: test -Dokhttp.platform=bouncycastle
testcorretto:
runs-on: ubuntu-latest
@ -311,7 +311,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=corretto
arguments: test -Dokhttp.platform=corretto
testopenjdk17:
runs-on: ubuntu-latest
@ -339,7 +339,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=17
arguments: test -Dtest.java.version=17
testopenjdk19:
runs-on: ubuntu-latest
@ -373,7 +373,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=19
arguments: test -Dtest.java.version=19
testwindows:
runs-on: windows-latest
@ -401,7 +401,7 @@ jobs:
- name: Test
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest
arguments: test
testgraal:
runs-on: ubuntu-latest
@ -532,7 +532,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=loom -Dtest.java.version=20
arguments: test -Dokhttp.platform=loom -Dtest.java.version=20
testandroidregression:

View File

@ -167,7 +167,7 @@ limitations under the License.
[conscrypt]: https://github.com/google/conscrypt/
[get_example]: https://raw.github.com/square/okhttp/master/samples/guide/src/main/java/okhttp3/guide/GetExample.java
[kotlin]: https://kotlinlang.org/
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro
[okhttp_312x]: https://github.com/square/okhttp/tree/okhttp_3.12.x
[okhttp]: https://square.github.io/okhttp/
[okio]: https://github.com/square/okio

View File

@ -63,6 +63,7 @@ dependencies {
exclude("org.conscrypt", "conscrypt-openjdk-uber")
exclude("software.amazon.cryptools", "AmazonCorrettoCryptoProvider")
}
androidTestImplementation(libs.assertk)
androidTestImplementation(libs.bouncycastle.bcprov)
androidTestImplementation(libs.bouncycastle.bctls)
androidTestImplementation(libs.conscrypt.android)

View File

@ -17,12 +17,17 @@ package okhttp.android.test.alpn;
import android.os.Build
import android.util.Log
import java.net.InetSocketAddress
import java.net.Proxy
import assertk.assertThat
import assertk.assertions.isEqualTo
import javax.net.ssl.SSLSocket
import javax.net.ssl.SSLSocketFactory
import okhttp3.*
import org.assertj.core.api.Assertions.assertThat
import okhttp3.Call
import okhttp3.Connection
import okhttp3.ConnectionSpec
import okhttp3.DelegatingSSLSocketFactory
import okhttp3.EventListener
import okhttp3.OkHttpClient
import okhttp3.Request
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

View File

@ -16,15 +16,16 @@
package okhttp.android.test.letsencrypt;
import android.os.Build
import assertk.assertThat
import assertk.assertions.isEqualTo
import java.security.cert.X509Certificate
import okhttp3.OkHttpClient
import okhttp3.Protocol
import okhttp3.Request
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.decodeCertificatePem
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import java.security.cert.X509Certificate
/**
* Test for new Let's Encrypt Root Certificate.

View File

@ -17,6 +17,9 @@ package okhttp.android.test.sni;
import android.os.Build
import android.util.Log
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
import java.security.cert.X509Certificate
import javax.net.ssl.SNIHostName
import javax.net.ssl.SNIServerName
@ -28,7 +31,6 @@ import okhttp3.OkHttpClient
import okhttp3.Protocol
import okhttp3.Request
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

View File

@ -2,15 +2,10 @@
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import groovy.util.Node
import groovy.util.NodeList
import java.net.URL
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
@ -179,16 +174,9 @@ subprojects {
}
// https://publicobject.com/2023/04/16/read-a-project-file-in-a-kotlin-multiplatform-test/
tasks.withType<KotlinJvmTest>().configureEach {
tasks.withType<Test>().configureEach {
environment("OKHTTP_ROOT", rootDir)
}
tasks.withType<KotlinNativeTest>().configureEach {
environment("SIMCTL_CHILD_OKHTTP_ROOT", rootDir)
environment("OKHTTP_ROOT", rootDir)
}
tasks.withType<KotlinJsTest>().configureEach {
environment("OKHTTP_ROOT", rootDir.toString())
}
if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
@ -265,31 +253,6 @@ subprojects {
}
}
}
// Configure the kotlinMultiplatform artifact to depend on the JVM artifact in pom.xml only.
// This hack allows Maven users to continue using our original OkHttp artifact names (like
// com.squareup.okhttp3:okhttp:5.x.y) even though we changed that artifact from JVM-only
// to Kotlin Multiplatform. Note that module.json doesn't need this hack.
val mavenPublications = publishingExtension.publications.withType<MavenPublication>()
mavenPublications.configureEach {
if (name != "jvm") return@configureEach
val jvmPublication = this
val kmpPublication = mavenPublications.getByName("kotlinMultiplatform")
kmpPublication.pom.withXml {
val root = asNode()
val dependencies = (root["dependencies"] as NodeList).firstOrNull() as Node?
?: root.appendNode("dependencies")
for (child in dependencies.children().toList()) {
dependencies.remove(child as Node)
}
dependencies.appendNode("dependency").apply {
appendNode("groupId", jvmPublication.groupId)
appendNode("artifactId", jvmPublication.artifactId)
appendNode("version", jvmPublication.version)
appendNode("scope", "compile")
}
}
}
}
}
@ -304,13 +267,6 @@ subprojects {
ignoredPackages += "okhttp3.tls.internal"
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
val jvmTest by tasks.creating {
description = "Get 'gradlew jvmTest' to run the tests of JVM-only modules"
dependsOn("test")
}
}
}
tasks.wrapper {

View File

@ -26,12 +26,6 @@ import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName
fun Project.applyOsgi(vararg bndProperties: String) {
// Configure OSGi for the JVM platform on kotlin-multiplatform.
plugins.withId("org.jetbrains.kotlin.multiplatform") {
applyOsgi("jvmJar", "jvmOsgiApi", bndProperties)
}
// Configure OSGi for kotlin-jvm.
plugins.withId("org.jetbrains.kotlin.jvm") {
applyOsgi("jar", "osgiApi", bndProperties)
}

View File

@ -9,5 +9,5 @@ interpreted by R8 automatically.
If you, however, don't use R8 you have to apply the rules from [this file][okhttp3_pro]. You might
also need rules from [Okio][okio] which is a dependency of this library.
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro
[okio]: https://square.github.io/okio/

View File

@ -19,6 +19,7 @@ dependencies {
api(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}
mavenPublishing {

View File

@ -15,9 +15,10 @@
*/
package mockwebserver3.junit4
import assertk.assertThat
import assertk.assertions.isTrue
import java.net.ConnectException
import java.util.concurrent.atomic.AtomicBoolean
import org.assertj.core.api.Assertions.assertThat
import org.junit.Assert.fail
import org.junit.Test
import org.junit.runner.Description
@ -34,7 +35,7 @@ class MockWebServerRuleTest {
}
}, Description.EMPTY)
statement.evaluate()
assertThat(called.get()).isTrue
assertThat(called.get()).isTrue()
try {
rule.server.url("/").toUrl().openConnection().connect()
fail()

View File

@ -30,6 +30,7 @@ dependencies {
testImplementation(libs.kotlin.junit5)
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}
mavenPublishing {

View File

@ -15,11 +15,14 @@
*/
package mockwebserver3.junit5.internal
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isSameAs
import assertk.assertions.isTrue
import mockwebserver3.MockResponse
import mockwebserver3.MockWebServer
import okhttp3.OkHttpClientTestRule
import okhttp3.Request
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

View File

@ -15,8 +15,11 @@
*/
package mockwebserver3.junit5.internal
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEqualTo
import assertk.assertions.isTrue
import mockwebserver3.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

View File

@ -15,10 +15,10 @@
*/
package mockwebserver3.junit5.internal
import assertk.assertThat
import assertk.assertions.isTrue
import mockwebserver3.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(MockWebServerExtension::class)

View File

@ -22,6 +22,7 @@ dependencies {
testRuntimeOnly(projects.mockwebserver3Junit5)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}
mavenPublishing {

View File

@ -15,11 +15,12 @@
*/
package mockwebserver3
import assertk.assertThat
import assertk.assertions.isEqualTo
import java.io.IOException
import java.net.HttpURLConnection
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicInteger
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout

View File

@ -15,6 +15,11 @@
*/
package mockwebserver3
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isTrue
import okhttp3.Dns
import okhttp3.Headers.Companion.headersOf
import okhttp3.HttpUrl.Companion.toHttpUrl
@ -24,7 +29,6 @@ import okhttp3.testing.PlatformRule
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okhttp3.tls.internal.TlsUtil.localhost
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension

View File

@ -15,6 +15,17 @@
*/
package mockwebserver3
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.containsExactly
import assertk.assertions.isBetween
import assertk.assertions.isCloseTo
import assertk.assertions.isEqualTo
import assertk.assertions.isGreaterThan
import assertk.assertions.isGreaterThanOrEqualTo
import assertk.assertions.isNotEqualTo
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import java.io.BufferedReader
import java.io.Closeable
import java.io.IOException
@ -42,8 +53,6 @@ import okhttp3.testing.PlatformRule
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okio.Buffer
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.data.Offset
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.BeforeEach
@ -371,7 +380,7 @@ class MockWebServerTest {
i++
}
// Halfway +/- 0.5%
assertThat(i.toFloat()).isCloseTo(512f, Offset.offset(5f))
assertThat(i.toFloat()).isCloseTo(512f, 5f)
}
@Test
@ -425,12 +434,12 @@ class MockWebServerTest {
@Test
fun hostnameImplicitlyStarts() {
assertThat(server.hostName).isNotNull
assertThat(server.hostName).isNotNull()
}
@Test
fun toProxyAddressImplicitlyStarts() {
assertThat(server.toProxyAddress()).isNotNull
assertThat(server.toProxyAddress()).isNotNull()
}
@Test
@ -491,7 +500,7 @@ class MockWebServerTest {
refusedConnection.responseCode
fail<Any?>("Second connection should be refused")
} catch (e: ConnectException) {
assertThat(e.message).contains("refused")
assertThat(e.message!!).contains("refused")
}
}
@ -579,9 +588,9 @@ class MockWebServerTest {
val request = server.takeRequest()
assertThat(request.requestUrl!!.scheme).isEqualTo("https")
val handshake = request.handshake
assertThat(handshake!!.tlsVersion).isNotNull
assertThat(handshake.cipherSuite).isNotNull
assertThat(handshake.localPrincipal).isNotNull
assertThat(handshake!!.tlsVersion).isNotNull()
assertThat(handshake.cipherSuite).isNotNull()
assertThat(handshake.localPrincipal).isNotNull()
assertThat(handshake.localCertificates.size).isEqualTo(1)
assertThat(handshake.peerPrincipal).isNull()
assertThat(handshake.peerCertificates.size).isEqualTo(0)
@ -628,11 +637,11 @@ class MockWebServerTest {
val request = server.takeRequest()
assertThat(request.requestUrl!!.scheme).isEqualTo("https")
val handshake = request.handshake
assertThat(handshake!!.tlsVersion).isNotNull
assertThat(handshake.cipherSuite).isNotNull
assertThat(handshake.localPrincipal).isNotNull
assertThat(handshake!!.tlsVersion).isNotNull()
assertThat(handshake.cipherSuite).isNotNull()
assertThat(handshake.localPrincipal).isNotNull()
assertThat(handshake.localCertificates.size).isEqualTo(1)
assertThat(handshake.peerPrincipal).isNotNull
assertThat(handshake.peerPrincipal).isNotNull()
assertThat(handshake.peerCertificates.size).isEqualTo(1)
}

View File

@ -16,13 +16,14 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package mockwebserver3
import assertk.assertThat
import assertk.assertions.isEqualTo
import java.net.InetAddress
import java.net.Socket
import okhttp3.Headers
import okhttp3.Headers.Companion.headersOf
import okhttp3.internal.EMPTY_HEADERS
import okio.Buffer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout

View File

@ -1,9 +1,9 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.KotlinJvm
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
kotlin("multiplatform")
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
id("com.palantir.graal")
@ -11,55 +11,35 @@ plugins {
}
val copyResourcesTemplates = tasks.register<Copy>("copyResourcesTemplates") {
from("src/jvmMain/resources-templates")
from("src/main/resources-templates")
into("$buildDir/generated/resources-templates")
expand("projectVersion" to "${project.version}")
filteringCharset = Charsets.UTF_8.toString()
}
kotlin {
jvm()
sourceSets {
val jvmMain by getting {
val main by getting {
resources.srcDir(copyResourcesTemplates.get().outputs)
dependencies {
api(libs.kotlin.stdlib)
}
dependencies {
}
}
dependencies {
api(libs.kotlin.stdlib)
api(projects.okhttp)
api(projects.loggingInterceptor)
api(libs.squareup.okio)
implementation(libs.clikt)
api(libs.guava.jre)
}
}
val jvmTest by getting {
dependencies {
api(libs.kotlin.stdlib)
implementation(projects.okhttpTestingSupport)
api(libs.squareup.okio)
api(libs.assertk)
implementation(kotlin("test"))
}
}
testImplementation(projects.okhttpTestingSupport)
testApi(libs.assertk)
testImplementation(kotlin("test"))
}
// Workaround for https://github.com/palantir/gradle-graal/issues/129
// Add a second configuration to populate
// runtimeClasspath vs jvmRuntimeClasspath
val main by register("main") {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(projects.okhttp)
implementation(projects.loggingInterceptor)
implementation(libs.squareup.okio)
implementation(libs.clikt)
implementation(libs.guava.jre)
}
}
}
animalsniffer {
isIgnoreFailures = true
}
tasks.jar {
@ -89,18 +69,6 @@ graal {
}
}
// Workaround for https://github.com/palantir/gradle-graal/issues/129
// Copy the jvmJar output into the normal jar location
val copyJvmJar = tasks.register<Copy>("copyJvmJar") {
val sourceFile = project.tasks.getByName("jvmJar").outputs.files.singleFile
val destinationFile = project.tasks.getByName("jar").outputs.files.singleFile
from(sourceFile)
into(destinationFile.parentFile)
rename (sourceFile.name, destinationFile.name)
}
tasks.getByName("copyJvmJar").dependsOn(tasks.getByName("jvmJar"))
tasks.getByName("nativeImage").dependsOn(copyJvmJar)
mavenPublishing {
configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty()))
configure(KotlinJvm(javadocJar = JavadocJar.Empty()))
}

View File

@ -56,6 +56,7 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.junit.ktx)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
testImplementation(projects.okhttpTls)
testImplementation(libs.androidx.test.runner)
testImplementation(libs.robolectric)
@ -64,6 +65,7 @@ dependencies {
androidTestImplementation(projects.okhttpTls)
androidTestImplementation(libs.assertj.core)
androidTestImplementation(libs.assertk)
androidTestImplementation(projects.mockwebserver3Junit4)
androidTestImplementation(libs.androidx.test.runner)
}

View File

@ -20,11 +20,16 @@ import android.content.Context
import android.net.ConnectivityManager
import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import assertk.assertThat
import assertk.assertions.hasMessage
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import assertk.assertions.isNull
import java.net.InetAddress
import java.net.UnknownHostException
import java.util.concurrent.CountDownLatch
import mockwebserver3.MockResponse
import mockwebserver3.MockWebServer
import mockwebserver3.junit4.MockWebServerRule
import okhttp3.AsyncDns
import okhttp3.HttpUrl.Companion.toHttpUrl
@ -33,9 +38,7 @@ import okhttp3.Request
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okio.IOException
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
import org.junit.Assume
import org.junit.Assume.assumeTrue
import org.junit.AssumptionViolatedException
import org.junit.Before
@ -115,7 +118,7 @@ class AndroidAsyncDnsTest {
val (allAddresses, exception) = dnsQuery("localhost")
assertThat(exception).isNull()
assertThat(allAddresses).isNotEmpty
assertThat(allAddresses).isNotEmpty()
}
private fun dnsQuery(hostname: String): Pair<List<InetAddress>, Exception?> {
@ -148,7 +151,7 @@ class AndroidAsyncDnsTest {
val (allAddresses, exception) = dnsQuery("google.com")
assertThat(exception).isNull()
assertThat(allAddresses).isNotEmpty
assertThat(allAddresses).isNotEmpty()
}
@Test

View File

@ -19,22 +19,24 @@ package okhttp3.android
import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import okhttp3.CacheControl
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import java.net.InetAddress
import java.net.UnknownHostException
import okhttp3.Cache
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import org.assertj.core.api.Assertions.assertThat
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
import org.junit.AssumptionViolatedException
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.net.InetAddress
import java.net.UnknownHostException
import okhttp3.Cache
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
@RunWith(RobolectricTestRunner::class)
@Config(

View File

@ -23,6 +23,7 @@ dependencies {
testImplementation(libs.conscrypt.openjdk)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}
mavenPublishing {

View File

@ -15,6 +15,11 @@
*/
package okhttp3.brotli
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasMessage
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import java.io.IOException
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Protocol
@ -26,7 +31,6 @@ import okio.ByteString
import okio.ByteString.Companion.EMPTY
import okio.ByteString.Companion.decodeHex
import okio.ByteString.Companion.encodeUtf8
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.fail

View File

@ -1,48 +1,33 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.KotlinJvm
plugins {
kotlin("multiplatform")
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
id("binary-compatibility-validator")
}
kotlin {
jvm {
withJava()
}
sourceSets {
getByName("jvmMain") {
dependencies {
api(projects.okhttp)
implementation(libs.kotlinx.coroutines.core)
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
}
}
getByName("jvmTest") {
dependencies {
implementation(libs.kotlin.test.common)
implementation(libs.kotlin.test.annotations)
api(libs.assertk)
implementation(projects.okhttpTestingSupport)
implementation(libs.kotlinx.coroutines.test)
implementation(projects.mockwebserver3Junit5)
}
}
}
}
project.applyOsgi(
"Export-Package: okhttp3.coroutines",
"Automatic-Module-Name: okhttp3.coroutines",
"Bundle-SymbolicName: com.squareup.okhttp3.coroutines"
)
mavenPublishing {
configure(
KotlinMultiplatform(javadocJar = JavadocJar.Empty())
)
dependencies {
api(projects.okhttp)
implementation(libs.kotlinx.coroutines.core)
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
testImplementation(libs.kotlin.test.common)
testImplementation(libs.kotlin.test.annotations)
testApi(libs.assertk)
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(projects.mockwebserver3Junit5)
}
mavenPublishing {
configure(KotlinJvm(javadocJar = JavadocJar.Empty()))
}

View File

@ -25,6 +25,7 @@ dependencies {
testImplementation(projects.okhttpTestingSupport)
testImplementation(projects.okhttpTls)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}
mavenPublishing {

View File

@ -15,9 +15,11 @@
*/
package okhttp3.logging
import assertk.assertThat
import assertk.assertions.isFalse
import assertk.assertions.isTrue
import okhttp3.logging.internal.isProbablyUtf8
import okio.Buffer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
class IsProbablyUtf8Test {

View File

@ -1,27 +1,23 @@
plugins {
kotlin("multiplatform")
kotlin("jvm")
id("ru.vyarus.animalsniffer")
}
kotlin {
jvm {
withJava()
}
sourceSets {
val jvmMain by getting {
dependencies {
dependencies {
api(libs.squareup.okio)
api(projects.okhttp)
api(projects.okhttpTls)
api(libs.assertj.core)
api(libs.assertk)
api(libs.bouncycastle.bcprov)
implementation(libs.bouncycastle.bcpkix)
implementation(libs.bouncycastle.bctls)
api(libs.conscrypt.openjdk)
api(libs.openjsse)
api(libs.amazonCorretto)
api(variantOf(libs.amazonCorretto) {
classifier("linux-x86_64")
})
api(libs.hamcrestLibrary)
api(libs.junit.jupiter.api)
@ -31,17 +27,7 @@ kotlin {
compileOnly(libs.findbugs.jsr305)
compileOnly(libs.robolectric.android)
}
}
}
}
val jvmMainApi by configurations.getting
dependencies {
jvmMainApi(variantOf(libs.amazonCorretto) {
classifier("linux-x86_64")
})
}
animalsniffer {

View File

@ -15,10 +15,11 @@
*/
package okhttp3
import assertk.assertThat
import assertk.assertions.containsExactly
import java.net.InetAddress
import java.net.UnknownHostException
import okio.Buffer
import org.assertj.core.api.Assertions.assertThat
class FakeDns : Dns {
private val hostAddresses: MutableMap<String, List<InetAddress>> = mutableMapOf()

View File

@ -15,15 +15,17 @@
*/
package okhttp3
import assertk.assertThat
import assertk.assertions.isCloseTo
import assertk.assertions.isFalse
import assertk.assertions.isInstanceOf
import assertk.assertions.matchesPredicate
import java.util.Deque
import java.util.concurrent.ConcurrentLinkedDeque
import java.util.concurrent.TimeUnit
import okhttp3.ConnectionEvent.NoNewExchanges
import okhttp3.internal.connection.RealConnection
import okhttp3.internal.platform.Platform
import okio.IOException
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.data.Offset
import org.junit.jupiter.api.Assertions
open class RecordingConnectionListener(
@ -88,7 +90,7 @@ open class RecordingConnectionListener(
TimeUnit.NANOSECONDS.toMillis(actualElapsedNs)
.toDouble()
)
.isCloseTo(elapsedMs.toDouble(), Offset.offset(100.0))
.isCloseTo(elapsedMs.toDouble(), 100.0)
}
return result
@ -104,13 +106,11 @@ open class RecordingConnectionListener(
private fun logEvent(e: ConnectionEvent) {
if (e.connection != null) {
assertThat(Thread.holdsLock(e.connection))
.overridingErrorMessage("Called with lock $${e.connection}")
assertThat(Thread.holdsLock(e.connection), "Called with lock $${e.connection}")
.isFalse()
}
for (lock in forbiddenLocks) {
assertThat(Thread.holdsLock(lock))
.overridingErrorMessage("Called with lock $lock")
assertThat(Thread.holdsLock(lock), "Called with lock $lock")
.isFalse()
}
@ -153,7 +153,9 @@ open class RecordingConnectionListener(
override fun connectionReleased(connection: Connection, call: Call) {
if (eventSequence.find { it is ConnectionEvent.ConnectStart && it.connection == connection } != null && connection is RealConnection) {
if (connection.noNewExchanges) {
assertThat(eventSequence).anyMatch { it is NoNewExchanges && it.connection == connection }
assertThat(eventSequence).matchesPredicate { deque ->
deque.any { it is NoNewExchanges && it.connection == connection }
}
}
}

View File

@ -15,9 +15,10 @@
*/
package okhttp3
import assertk.assertThat
import assertk.assertions.containsExactly
import java.util.ArrayDeque
import java.util.Deque
import org.assertj.core.api.Assertions.assertThat
class RecordingCookieJar : CookieJar {
private val requestCookies: Deque<List<Cookie>> = ArrayDeque()

View File

@ -15,6 +15,11 @@
*/
package okhttp3
import assertk.assertThat
import assertk.assertions.isCloseTo
import assertk.assertions.isFalse
import assertk.assertions.isInstanceOf
import assertk.assertions.matchesPredicate
import java.io.IOException
import java.net.InetAddress
import java.net.InetSocketAddress
@ -51,11 +56,7 @@ import okhttp3.CallEvent.ResponseHeadersStart
import okhttp3.CallEvent.SatisfactionFailure
import okhttp3.CallEvent.SecureConnectEnd
import okhttp3.CallEvent.SecureConnectStart
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.data.Offset
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.fail
open class RecordingEventListener(
/**
@ -119,7 +120,7 @@ open class RecordingEventListener(
TimeUnit.NANOSECONDS.toMillis(actualElapsedNs)
.toDouble()
)
.isCloseTo(elapsedMs.toDouble(), Offset.offset(100.0))
.isCloseTo(elapsedMs.toDouble(), 100.0)
}
return result
@ -135,9 +136,7 @@ open class RecordingEventListener(
private fun logEvent(e: CallEvent) {
for (lock in forbiddenLocks) {
assertThat(Thread.holdsLock(lock))
.overridingErrorMessage(lock.toString())
.isFalse()
assertThat(Thread.holdsLock(lock), lock.toString()).isFalse()
}
if (enforceOrder) {
@ -149,7 +148,7 @@ open class RecordingEventListener(
private fun checkForStartEvent(e: CallEvent) {
if (eventSequence.isEmpty()) {
assertThat(e).isInstanceOfAny(CallStart::class.java, Canceled::class.java)
assertThat(e).matchesPredicate { it is CallStart || it is Canceled }
} else {
eventSequence.forEach loop@ {
when (e.closes(it)) {

View File

@ -15,8 +15,8 @@
*/
package okhttp3.internal.concurrent
import okhttp3.OkHttpClient
import org.assertj.core.api.Assertions.assertThat
import assertk.assertThat
import assertk.assertions.isEmpty
import java.io.Closeable
import java.util.AbstractQueue
import java.util.concurrent.BlockingQueue
@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.logging.Logger
import kotlin.concurrent.withLock
import okhttp3.OkHttpClient
/**
* Runs a [TaskRunner] in a controlled environment so that everything is sequential and

View File

@ -16,6 +16,8 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package okhttp3.internal.http
import assertk.assertThat
import assertk.assertions.containsExactly
import java.io.IOException
import java.net.InetSocketAddress
import java.net.Proxy
@ -23,7 +25,6 @@ import java.net.ProxySelector
import java.net.SocketAddress
import java.net.URI
import okhttp3.internal.format
import org.assertj.core.api.Assertions.assertThat
class RecordingProxySelector : ProxySelector() {
@JvmField val proxies = mutableListOf<Proxy>()

View File

@ -1,8 +1,8 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.KotlinJvm
plugins {
kotlin("multiplatform")
kotlin("jvm")
kotlin("plugin.serialization")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
@ -11,7 +11,7 @@ plugins {
// Build & use okhttp3/internal/-InternalVersion.kt
val copyKotlinTemplates = tasks.register<Copy>("copyKotlinTemplates") {
from("src/jvmMain/kotlinTemplates")
from("src/main/kotlinTemplates")
into("$buildDir/generated/sources/kotlinTemplates")
expand("projectVersion" to project.version)
filteringCharset = Charsets.UTF_8.toString()
@ -30,67 +30,10 @@ val generateIdnaMappingTable by tasks.creating(JavaExec::class.java) {
}
kotlin {
jvm {
withJava()
}
sourceSets {
getByName("jvmMain") {
getByName("main") {
kotlin.srcDir(copyKotlinTemplates.get().outputs)
kotlin.srcDir(generateIdnaMappingTable.outputs)
dependencies {
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
// These compileOnly dependencies must also be listed in the OSGi configuration above.
compileOnly(libs.robolectric.android)
compileOnly(libs.bouncycastle.bcprov)
compileOnly(libs.bouncycastle.bctls)
compileOnly(libs.conscrypt.openjdk)
compileOnly(libs.openjsse)
compileOnly(libs.findbugs.jsr305)
compileOnly(libs.animalsniffer.annotations)
// graal build support
compileOnly(libs.nativeImageSvm)
}
}
getByName("jvmTest") {
dependencies {
implementation(projects.okhttpTestingSupport)
implementation(libs.assertk)
implementation(libs.kotlin.test.annotations)
implementation(libs.kotlin.test.common)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)
implementation(projects.okhttpJavaNetCookiejar)
implementation(projects.okhttpTls)
implementation(projects.okhttpUrlconnection)
implementation(projects.mockwebserver3)
implementation(projects.mockwebserver3Junit4)
implementation(projects.mockwebserver3Junit5)
implementation(projects.mockwebserver)
implementation(projects.loggingInterceptor)
implementation(projects.okhttpBrotli)
implementation(projects.okhttpDnsoverhttps)
implementation(projects.okhttpIdnaMappingTable)
implementation(projects.okhttpSse)
implementation(projects.okhttpCoroutines)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.squareup.moshi)
implementation(libs.squareup.moshi.kotlin)
implementation(libs.squareup.okio.fakefilesystem)
implementation(libs.conscrypt.openjdk)
implementation(libs.junit)
implementation(libs.junit.jupiter.api)
implementation(libs.junit.jupiter.params)
implementation(libs.kotlin.test.junit)
implementation(libs.assertj.core)
implementation(libs.openjsse)
implementation(libs.aqute.resolve)
compileOnly(libs.findbugs.jsr305)
}
}
}
}
@ -145,17 +88,66 @@ val osgiTestDeploy: Configuration by configurations.creating
val copyOsgiTestDeployment by tasks.creating(Copy::class.java) {
from(osgiTestDeploy)
into("$buildDir/resources/jvmTest/okhttp3/osgi/deployments")
into("$buildDir/resources/test/okhttp3/osgi/deployments")
}
tasks.getByName("jvmTest") {
tasks.getByName("test") {
dependsOn(copyOsgiTestDeployment)
}
dependencies {
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
// These compileOnly dependencies must also be listed in the OSGi configuration above.
compileOnly(libs.robolectric.android)
compileOnly(libs.bouncycastle.bcprov)
compileOnly(libs.bouncycastle.bctls)
compileOnly(libs.conscrypt.openjdk)
compileOnly(libs.openjsse)
compileOnly(libs.findbugs.jsr305)
compileOnly(libs.animalsniffer.annotations)
// graal build support
compileOnly(libs.nativeImageSvm)
testCompileOnly(libs.bouncycastle.bctls)
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.assertk)
testImplementation(libs.kotlin.test.annotations)
testImplementation(libs.kotlin.test.common)
testImplementation(libs.kotlinx.serialization.core)
testImplementation(libs.kotlinx.serialization.json)
testImplementation(projects.okhttpJavaNetCookiejar)
testImplementation(projects.okhttpTls)
testImplementation(projects.okhttpUrlconnection)
testImplementation(projects.mockwebserver3)
testImplementation(projects.mockwebserver3Junit4)
testImplementation(projects.mockwebserver3Junit5)
testImplementation(projects.mockwebserver)
testImplementation(projects.loggingInterceptor)
testImplementation(projects.okhttpBrotli)
testImplementation(projects.okhttpDnsoverhttps)
testImplementation(projects.okhttpIdnaMappingTable)
testImplementation(projects.okhttpSse)
testImplementation(projects.okhttpCoroutines)
testImplementation(libs.kotlinx.coroutines.core)
testImplementation(libs.squareup.moshi)
testImplementation(libs.squareup.moshi.kotlin)
testImplementation(libs.squareup.okio.fakefilesystem)
testImplementation(libs.conscrypt.openjdk)
testImplementation(libs.junit)
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.openjsse)
testImplementation(libs.aqute.resolve)
testCompileOnly(libs.findbugs.jsr305)
osgiTestDeploy(libs.eclipseOsgi)
osgiTestDeploy(libs.kotlin.stdlib.osgi)
}
mavenPublishing {
configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty()))
configure(KotlinJvm(javadocJar = JavadocJar.Empty()))
}

Some files were not shown because too many files have changed in this diff Show More