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

Remove expect/actuals #8147

Merged
merged 5 commits into from
Dec 19, 2023
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
12 changes: 1 addition & 11 deletions okcurl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@ kotlin {
jvm()

sourceSets {
commonMain {
val jvmMain by getting {
resources.srcDir(copyResourcesTemplates.get().outputs)
dependencies {
api(libs.kotlin.stdlib)
}
}

commonTest {
dependencies {
api(libs.kotlin.stdlib)
implementation(kotlin("test"))
}
}

val jvmMain by getting {
dependencies {
api(libs.kotlin.stdlib)
api(projects.okhttp)
Expand Down
46 changes: 0 additions & 46 deletions okcurl/src/commonMain/kotlin/okhttp3/curl/Main.kt

This file was deleted.

26 changes: 13 additions & 13 deletions okcurl/src/jvmMain/kotlin/okhttp3/curl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ import okhttp3.internal.platform.Platform
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.LoggingEventListener

actual class Main : CliktCommand(name = NAME, help = "A curl for the next-generation web.") {
actual val method: String? by option("-X", "--request", help="Specify request command to use")
class Main : CliktCommand(name = NAME, help = "A curl for the next-generation web.") {
val method: String? by option("-X", "--request", help="Specify request command to use")

actual val data: String? by option("-d", "--data", help="HTTP POST data")
val data: String? by option("-d", "--data", help="HTTP POST data")

actual val headers: List<String>? by option("-H", "--header", help="Custom header to pass to server").multiple()
val headers: List<String>? by option("-H", "--header", help="Custom header to pass to server").multiple()

actual val userAgent: String by option("-A", "--user-agent", help="User-Agent to send to server").default(NAME + "/" + versionString())
val userAgent: String by option("-A", "--user-agent", help="User-Agent to send to server").default(NAME + "/" + versionString())

val connectTimeout: Int by option("--connect-timeout", help="Maximum time allowed for connection (seconds)").int().default(DEFAULT_TIMEOUT)

Expand All @@ -58,29 +58,29 @@ actual class Main : CliktCommand(name = NAME, help = "A curl for the next-genera

val allowInsecure: Boolean by option("-k", "--insecure", help="Allow connections to SSL sites without certs").flag()

actual val showHeaders: Boolean by option("-i", "--include", help="Include protocol headers in the output").flag()
val showHeaders: Boolean by option("-i", "--include", help="Include protocol headers in the output").flag()

val showHttp2Frames: Boolean by option("--frames", help="Log HTTP/2 frames to STDERR").flag()

actual val referer: String? by option("-e", "--referer", help="Referer URL")
val referer: String? by option("-e", "--referer", help="Referer URL")

val verbose: Boolean by option("-v", "--verbose", help="Makes $NAME verbose during the operation").flag()

val sslDebug: Boolean by option(help="Output SSL Debug").flag()

actual val url: String? by argument(name = "url", help="Remote resource URL")
val url: String? by argument(name = "url", help="Remote resource URL")

actual var client: Call.Factory? = null
var client: Call.Factory? = null

actual override fun run() {
override fun run() {
LoggingUtil.configureLogging(debug = verbose, showHttp2Frames = showHttp2Frames, sslDebug = sslDebug)

commonRun()
}

actual fun createRequest(): Request = commonCreateRequest()
fun createRequest(): Request = commonCreateRequest()

actual fun createClient(): Call.Factory {
fun createClient(): Call.Factory {
val builder = OkHttpClient.Builder()
builder.followSslRedirects(followRedirects)
if (connectTimeout != DEFAULT_TIMEOUT) {
Expand All @@ -105,7 +105,7 @@ actual class Main : CliktCommand(name = NAME, help = "A curl for the next-genera
return builder.build()
}

actual fun close() {
fun close() {
val okHttpClient = client as OkHttpClient
okHttpClient.connectionPool.evictAll() // Close any persistent connections.
okHttpClient.dispatcher.executorService.shutdownNow()
Expand Down
19 changes: 4 additions & 15 deletions okhttp-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,19 @@ kotlin {
}

sourceSets {
commonMain {
getByName("jvmMain") {
dependencies {
api(libs.squareup.okio)
api(projects.okhttp)
implementation(libs.kotlinx.coroutines.core)
}
}
val commonTest by getting {
dependencies {
implementation(libs.kotlin.test.common)
implementation(libs.kotlin.test.annotations)
api(libs.assertk)
}
}

getByName("jvmMain") {
dependencies {
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
}
}
getByName("jvmTest") {
dependencies {
dependsOn(commonTest)
implementation(libs.kotlin.test.common)
implementation(libs.kotlin.test.annotations)
api(libs.assertk)
implementation(projects.okhttpTestingSupport)
implementation(libs.kotlinx.coroutines.test)
implementation(projects.mockwebserver3Junit5)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import okio.IOException
import kotlin.coroutines.resumeWithException

@OptIn(ExperimentalCoroutinesApi::class)
actual suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation ->
suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation ->
continuation.invokeOnCancellation {
this.cancel()
}
Expand Down
11 changes: 5 additions & 6 deletions okhttp-coroutines/src/jvmTest/kotlin/okhttp3/SuspendCallTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ package okhttp3
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isTrue
import java.io.IOException
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.TimeoutCancellationException
Expand All @@ -30,17 +33,13 @@ import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import mockwebserver3.MockResponse
import mockwebserver3.MockWebServer
import mockwebserver3.SocketPolicy
import mockwebserver3.SocketPolicy.DisconnectAfterRequest
import mockwebserver3.junit5.internal.MockWebServerExtension
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.RegisterExtension
import org.junit.jupiter.api.fail
import java.io.IOException
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.seconds
import mockwebserver3.SocketPolicy.DisconnectAfterRequest
import org.junit.jupiter.api.BeforeEach

@ExtendWith(MockWebServerExtension::class)
class SuspendCallTest {
Expand Down

This file was deleted.

6 changes: 1 addition & 5 deletions okhttp-testing-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ kotlin {
}

sourceSets {
val commonMain by getting {
dependencies {
api(libs.squareup.okio)
}
}
val jvmMain by getting {
dependencies {
api(libs.squareup.okio)
api(projects.okhttp)
api(projects.okhttpTls)
api(libs.assertj.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@
package okhttp3

import okio.Buffer
import okio.FileSystem
import okio.Path
import okio.Path.Companion.toPath

val okHttpRoot: Path
get() = getEnv("OKHTTP_ROOT")!!.toPath()

expect val SYSTEM_FILE_SYSTEM: FileSystem

expect fun getEnv(name: String): String?

expect val isJvm: Boolean

fun String(vararg codePoints: Int): String {
val buffer = Buffer()
for (codePoint in codePoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ object TestUtil {
}
}

actual fun getEnv(name: String) = System.getenv(name)
fun getEnv(name: String) = System.getenv(name)

actual val SYSTEM_FILE_SYSTEM = FileSystem.SYSTEM
val SYSTEM_FILE_SYSTEM = FileSystem.SYSTEM

actual val isJvm = true
val isJvm = true
31 changes: 8 additions & 23 deletions okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.android.build.gradle.tasks.JavaDocJarTask
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

plugins {
kotlin("multiplatform")
Expand All @@ -16,7 +11,7 @@ plugins {

// Build & use okhttp3/internal/-InternalVersion.kt
val copyKotlinTemplates = tasks.register<Copy>("copyKotlinTemplates") {
from("src/commonMain/kotlinTemplates")
from("src/jvmMain/kotlinTemplates")
into("$buildDir/generated/sources/kotlinTemplates")
expand("projectVersion" to project.version)
filteringCharset = Charsets.UTF_8.toString()
Expand All @@ -40,25 +35,10 @@ kotlin {
}

sourceSets {
commonMain {
getByName("jvmMain") {
kotlin.srcDir(copyKotlinTemplates.get().outputs)
kotlin.srcDir(generateIdnaMappingTable.outputs)
dependencies {
api(libs.squareup.okio)
}
}
val commonTest by getting {
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)
}
}

getByName("jvmMain") {
dependencies {
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
Expand All @@ -78,7 +58,12 @@ kotlin {
}
getByName("jvmTest") {
dependencies {
dependsOn(commonTest)
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)
Expand Down
22 changes: 0 additions & 22 deletions okhttp/src/commonMain/kotlin/okhttp3/-CommonPlatform.kt

This file was deleted.

Loading