Skip to content

Commit

Permalink
Switch back to the kotlin JVM plugin (#8149)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
squarejesse authored Dec 20, 2023
1 parent 6b7b611 commit c056530
Show file tree
Hide file tree
Showing 397 changed files with 257 additions and 322 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -401,7 +401,7 @@ jobs:
- name: Test
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest
arguments: test

testgraal:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions android-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
46 changes: 1 addition & 45 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
}
}
}
}
}

Expand All @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/artifacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/features/r8_proguard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions mockwebserver-junit4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
api(libs.junit)

testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions mockwebserver-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
testImplementation(libs.kotlin.junit5)
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions mockwebserver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testRuntimeOnly(projects.mockwebserver3Junit5)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c056530

Please sign in to comment.