diff --git a/ktor-client/ktor-client-cio/jvmAndPosix/src/io/ktor/client/engine/cio/utils.kt b/ktor-client/ktor-client-cio/jvmAndPosix/src/io/ktor/client/engine/cio/utils.kt index 325ca90bd92..b2b92c93706 100644 --- a/ktor-client/ktor-client-cio/jvmAndPosix/src/io/ktor/client/engine/cio/utils.kt +++ b/ktor-client/ktor-client-cio/jvmAndPosix/src/io/ktor/client/engine/cio/utils.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client.engine.cio @@ -14,8 +14,6 @@ import io.ktor.http.content.* import io.ktor.util.date.* import io.ktor.utils.io.* import io.ktor.utils.io.CancellationException -import io.ktor.utils.io.core.* -import io.ktor.utils.io.errors.* import io.ktor.websocket.* import kotlinx.coroutines.* import kotlinx.io.IOException diff --git a/ktor-client/ktor-client-cio/jvmAndPosix/test/CIOEngineTest.kt b/ktor-client/ktor-client-cio/jvmAndPosix/test/CIOEngineTest.kt index f442d2f88df..8844cac9533 100644 --- a/ktor-client/ktor-client-cio/jvmAndPosix/test/CIOEngineTest.kt +++ b/ktor-client/ktor-client-cio/jvmAndPosix/test/CIOEngineTest.kt @@ -1,8 +1,10 @@ /* - * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ + +package io.ktor.client.engine.cio + import io.ktor.client.* -import io.ktor.client.engine.cio.* import io.ktor.client.plugins.sse.* import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* @@ -11,7 +13,6 @@ import io.ktor.http.* import io.ktor.network.selector.* import io.ktor.network.sockets.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* import io.ktor.websocket.* import kotlinx.coroutines.* import kotlinx.coroutines.flow.* diff --git a/ktor-client/ktor-client-cio/jvmAndPosix/test/ConnectionFactoryTest.kt b/ktor-client/ktor-client-cio/jvmAndPosix/test/ConnectionFactoryTest.kt index a4354f66eda..8c82620013f 100644 --- a/ktor-client/ktor-client-cio/jvmAndPosix/test/ConnectionFactoryTest.kt +++ b/ktor-client/ktor-client-cio/jvmAndPosix/test/ConnectionFactoryTest.kt @@ -1,10 +1,11 @@ /* - * Copyright 2014-2023 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ -import io.ktor.client.engine.cio.* + +package io.ktor.client.engine.cio + import io.ktor.network.selector.* import io.ktor.network.sockets.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.test.* diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt index 874ff130392..75aabe09998 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client @@ -1449,7 +1449,7 @@ public class HttpClient( @Suppress("UNCHECKED_CAST") val plugin = installedFeatures[key as AttributeKey] - if (plugin is Closeable) { + if (plugin is AutoCloseable) { plugin.close() } } diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt index 7bfadfaa3fd..14ca79b3887 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngineBase.kt @@ -1,11 +1,10 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client.engine import io.ktor.util.* -import io.ktor.utils.io.core.* import kotlinx.atomicfu.* import kotlinx.coroutines.* import kotlin.coroutines.* @@ -58,19 +57,4 @@ public abstract class HttpClientEngineBase(private val engineName: String) : Htt public class ClientEngineClosedException(override val cause: Throwable? = null) : IllegalStateException("Client already closed") -/** - * Closes [CoroutineDispatcher] if it's [CloseableCoroutineDispatcher] or [Closeable]. - */ -@OptIn(ExperimentalCoroutinesApi::class) -private fun CoroutineDispatcher.close() { - try { - when (this) { - is CloseableCoroutineDispatcher -> close() - is Closeable -> close() - } - } catch (ignore: Throwable) { - // Some closeable dispatchers like Dispatchers.IO can't be closed. - } -} - internal expect fun ioDispatcher(): CoroutineDispatcher diff --git a/ktor-client/ktor-client-core/jvm/src/io/ktor/client/plugins/cache/storage/FileCacheStorage.kt b/ktor-client/ktor-client-core/jvm/src/io/ktor/client/plugins/cache/storage/FileCacheStorage.kt index 02a90a6de93..b9b0660481d 100644 --- a/ktor-client/ktor-client-core/jvm/src/io/ktor/client/plugins/cache/storage/FileCacheStorage.kt +++ b/ktor-client/ktor-client-core/jvm/src/io/ktor/client/plugins/cache/storage/FileCacheStorage.kt @@ -10,7 +10,6 @@ import io.ktor.util.* import io.ktor.util.collections.* import io.ktor.util.date.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* import io.ktor.utils.io.jvm.javaio.* import kotlinx.coroutines.* import kotlinx.coroutines.sync.* diff --git a/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlNativeTests.kt b/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlNativeTests.kt index 6204db99a37..366ca4da5a7 100644 --- a/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlNativeTests.kt +++ b/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlNativeTests.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client.engine.curl.test @@ -9,9 +9,7 @@ import io.ktor.client.call.* import io.ktor.client.engine.curl.* import io.ktor.client.request.* import io.ktor.client.statement.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* -import kotlin.native.concurrent.* import kotlin.test.* class CurlNativeTests { diff --git a/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlProxyTest.kt b/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlProxyTest.kt index 73b64693d69..e0d8e2b350e 100644 --- a/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlProxyTest.kt +++ b/ktor-client/ktor-client-curl/desktop/test/io/ktor/client/engine/curl/test/CurlProxyTest.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client.engine.curl.test @@ -11,7 +11,6 @@ import io.ktor.client.engine.curl.* import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.test.* diff --git a/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/CommonClientTestUtils.kt b/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/CommonClientTestUtils.kt index f507e9d3114..444edf36ed3 100644 --- a/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/CommonClientTestUtils.kt +++ b/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/CommonClientTestUtils.kt @@ -7,7 +7,6 @@ package io.ktor.client.tests.utils import io.ktor.client.* import io.ktor.client.engine.* import io.ktor.test.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes diff --git a/ktor-client/ktor-client-winhttp/windows/src/io/ktor/client/engine/winhttp/internal/WinHttpResponseData.kt b/ktor-client/ktor-client-winhttp/windows/src/io/ktor/client/engine/winhttp/internal/WinHttpResponseData.kt index 0271f8fb464..93df7931549 100644 --- a/ktor-client/ktor-client-winhttp/windows/src/io/ktor/client/engine/winhttp/internal/WinHttpResponseData.kt +++ b/ktor-client/ktor-client-winhttp/windows/src/io/ktor/client/engine/winhttp/internal/WinHttpResponseData.kt @@ -1,16 +1,14 @@ /* - * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.client.engine.winhttp.internal -import io.ktor.client.plugins.sse.* import io.ktor.client.request.* import io.ktor.http.* import io.ktor.http.cio.* import io.ktor.util.date.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* import kotlin.coroutines.* internal class WinHttpResponseData( diff --git a/ktor-client/ktor-client-winhttp/windows/test/io/ktor/client/engine/winhttp/WinHttpProxyTest.kt b/ktor-client/ktor-client-winhttp/windows/test/io/ktor/client/engine/winhttp/WinHttpProxyTest.kt index bd977ceb70c..a14241ae849 100644 --- a/ktor-client/ktor-client-winhttp/windows/test/io/ktor/client/engine/winhttp/WinHttpProxyTest.kt +++ b/ktor-client/ktor-client-winhttp/windows/test/io/ktor/client/engine/winhttp/WinHttpProxyTest.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.client.engine.winhttp @@ -8,7 +8,6 @@ import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.engine.* import io.ktor.client.request.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.test.* diff --git a/ktor-io/api/ktor-io.klib.api b/ktor-io/api/ktor-io.klib.api index 55c7cd72c86..e691706152e 100644 --- a/ktor-io/api/ktor-io.klib.api +++ b/ktor-io/api/ktor-io.klib.api @@ -53,7 +53,7 @@ abstract interface <#A: kotlin/Any> io.ktor.utils.io.pool/ObjectPool : kotlin/Au open fun close() // io.ktor.utils.io.pool/ObjectPool.close|close(){}[0] } -abstract interface io.ktor.utils.io.core/Closeable { // io.ktor.utils.io.core/Closeable|null[0] +abstract interface io.ktor.utils.io.core/Closeable : kotlin/AutoCloseable { // io.ktor.utils.io.core/Closeable|null[0] abstract fun close() // io.ktor.utils.io.core/Closeable.close|close(){}[0] } diff --git a/ktor-io/common/src/io/ktor/utils/io/core/Closeable.kt b/ktor-io/common/src/io/ktor/utils/io/core/Closeable.kt index 90567a0231f..043fab49be2 100644 --- a/ktor-io/common/src/io/ktor/utils/io/core/Closeable.kt +++ b/ktor-io/common/src/io/ktor/utils/io/core/Closeable.kt @@ -4,25 +4,9 @@ package io.ktor.utils.io.core -public expect interface Closeable { - public fun close() -} +import kotlin.use as stdlibUse -public inline fun T.use(block: (T) -> R): R { - var closed = false - try { - return block(this) - } catch (cause: Throwable) { - closed = true - try { - this?.close() - } catch (closeException: Throwable) { - cause.addSuppressed(closeException) - } - throw cause - } finally { - if (!closed) { - this?.close() - } - } -} +public expect interface Closeable : AutoCloseable + +@Deprecated("Use stdlib implementation instead. Remove import of this function", ReplaceWith("stdlibUse(block)")) +public inline fun T.use(block: (T) -> R): R = stdlibUse(block) diff --git a/ktor-io/js/src/io/ktor/utils/io/core/Closeable.js.kt b/ktor-io/js/src/io/ktor/utils/io/core/Closeable.js.kt index 09561abbac7..63ae1eeb0f4 100644 --- a/ktor-io/js/src/io/ktor/utils/io/core/Closeable.js.kt +++ b/ktor-io/js/src/io/ktor/utils/io/core/Closeable.js.kt @@ -4,6 +4,6 @@ package io.ktor.utils.io.core -public actual interface Closeable { - public actual fun close() +public actual interface Closeable : AutoCloseable { + override fun close() } diff --git a/ktor-io/posix/src/io/ktor/utils/io/core/Closeable.posix.kt b/ktor-io/posix/src/io/ktor/utils/io/core/Closeable.posix.kt index 09561abbac7..63ae1eeb0f4 100644 --- a/ktor-io/posix/src/io/ktor/utils/io/core/Closeable.posix.kt +++ b/ktor-io/posix/src/io/ktor/utils/io/core/Closeable.posix.kt @@ -4,6 +4,6 @@ package io.ktor.utils.io.core -public actual interface Closeable { - public actual fun close() +public actual interface Closeable : AutoCloseable { + override fun close() } diff --git a/ktor-io/wasmJs/src/io/ktor/utils/io/core/Closeable.wasmJs.kt b/ktor-io/wasmJs/src/io/ktor/utils/io/core/Closeable.wasmJs.kt index 09561abbac7..63ae1eeb0f4 100644 --- a/ktor-io/wasmJs/src/io/ktor/utils/io/core/Closeable.wasmJs.kt +++ b/ktor-io/wasmJs/src/io/ktor/utils/io/core/Closeable.wasmJs.kt @@ -4,6 +4,6 @@ package io.ktor.utils.io.core -public actual interface Closeable { - public actual fun close() +public actual interface Closeable : AutoCloseable { + override fun close() } diff --git a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TCPSocketTest.kt b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TCPSocketTest.kt index bece892c452..71f9543899b 100644 --- a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TCPSocketTest.kt +++ b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TCPSocketTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.network.sockets.tests @@ -7,7 +7,6 @@ package io.ktor.network.sockets.tests import io.ktor.network.sockets.* import io.ktor.utils.io.* import io.ktor.utils.io.CancellationException -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlinx.io.* import kotlin.test.* diff --git a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TestUtils.kt b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TestUtils.kt index 3e7f36121bb..1a255234492 100644 --- a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TestUtils.kt +++ b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/TestUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.network.sockets.tests @@ -7,7 +7,6 @@ package io.ktor.network.sockets.tests import io.ktor.network.selector.* import io.ktor.test.dispatcher.* import io.ktor.util.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.time.* import kotlin.time.Duration.Companion.seconds diff --git a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt index 5c9d784b5d7..1c947038cb6 100644 --- a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt +++ b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.network.sockets.tests @@ -11,6 +11,7 @@ import kotlinx.coroutines.* import kotlinx.io.* import kotlin.random.* import kotlin.test.* +import kotlin.use class UDPSocketTest { diff --git a/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt b/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt index ce5a63d79c7..be2fe7b3e91 100644 --- a/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt +++ b/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.network.tls @@ -21,6 +21,7 @@ import javax.crypto.* import javax.crypto.spec.* import javax.security.auth.x500.* import kotlin.coroutines.* +import kotlin.use internal class TLSClientHandshake( rawInput: ByteReadChannel, diff --git a/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/Certificates.kt b/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/Certificates.kt index 5dbca80f59a..5c704122f01 100644 --- a/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/Certificates.kt +++ b/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/Certificates.kt @@ -21,6 +21,7 @@ import javax.security.auth.x500.* import kotlin.time.* import kotlin.time.Duration import kotlin.time.Duration.Companion.days +import kotlin.use internal val DEFAULT_PRINCIPAL = X500Principal("CN=localhost, OU=Kotlin, O=JetBrains, C=RU") private val DEFAULT_CA_PRINCIPAL = X500Principal("CN=localhostCA, OU=Kotlin, O=JetBrains, C=RU") diff --git a/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/builders.kt b/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/builders.kt index b8895edcb4c..ebd9ddf7694 100644 --- a/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/builders.kt +++ b/ktor-network/ktor-network-tls/ktor-network-tls-certificates/jvm/src/io/ktor/network/tls/certificates/builders.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.network.tls.certificates @@ -7,7 +7,6 @@ package io.ktor.network.tls.certificates import io.ktor.network.tls.* import io.ktor.network.tls.extensions.* import io.ktor.util.* -import io.ktor.utils.io.core.* import java.io.* import java.net.* import java.security.* diff --git a/ktor-server/ktor-server-cio/build.gradle.kts b/ktor-server/ktor-server-cio/build.gradle.kts index c7b84585d68..454778782a3 100644 --- a/ktor-server/ktor-server-cio/build.gradle.kts +++ b/ktor-server/ktor-server-cio/build.gradle.kts @@ -18,11 +18,11 @@ kotlin.sourceSets { api(project(":ktor-server:ktor-server-core")) api(project(":ktor-client:ktor-client-cio")) api(project(":ktor-server:ktor-server-test-suites")) + api(project(":ktor-server:ktor-server-test-base")) } } jvmTest { dependencies { - api(project(":ktor-server:ktor-server-test-base")) api(project(":ktor-server:ktor-server-core", configuration = "testOutput")) api(libs.logback.classic) implementation(libs.kotlinx.coroutines.debug) diff --git a/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/HttpServer.kt b/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/HttpServer.kt index f24df8a15fd..3c811d9a72d 100644 --- a/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/HttpServer.kt +++ b/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/HttpServer.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.server.cio.backend @@ -11,8 +11,6 @@ import io.ktor.server.engine.* import io.ktor.server.engine.internal.* import io.ktor.util.logging.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* -import io.ktor.utils.io.errors.* import kotlinx.coroutines.* import kotlinx.io.IOException import kotlin.time.Duration.Companion.seconds diff --git a/ktor-server/ktor-server-cio/jvmAndPosix/test/io/ktor/tests/server/cio/CIOEngineTest.kt b/ktor-server/ktor-server-cio/jvmAndPosix/test/io/ktor/tests/server/cio/CIOEngineTest.kt index c2072804580..da08b330b05 100644 --- a/ktor-server/ktor-server-cio/jvmAndPosix/test/io/ktor/tests/server/cio/CIOEngineTest.kt +++ b/ktor-server/ktor-server-cio/jvmAndPosix/test/io/ktor/tests/server/cio/CIOEngineTest.kt @@ -2,6 +2,7 @@ * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ +// ktlint-disable filename package io.ktor.tests.server.cio import io.ktor.client.statement.* @@ -15,7 +16,6 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.server.testing.suites.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* import kotlin.test.* class CIOHttpServerTest : HttpServerCommonTestSuite(CIO) { diff --git a/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt b/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt index f38ce7ea430..6f8012d4664 100644 --- a/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt +++ b/ktor-server/ktor-server-core/common/src/io/ktor/server/application/ApplicationPlugin.kt @@ -1,6 +1,6 @@ /* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ package io.ktor.server.application @@ -8,7 +8,6 @@ import io.ktor.server.routing.* import io.ktor.util.* import io.ktor.util.internal.* import io.ktor.util.pipeline.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* /** @@ -230,7 +229,7 @@ public fun , B : Any, F : Any> A.uninstall( public fun , F : Any> A.uninstallPlugin(key: AttributeKey) { val registry = attributes.getOrNull(pluginRegistryKey) ?: return val instance = registry.getOrNull(key) ?: return - if (instance is Closeable) { + if (instance is AutoCloseable) { instance.close() } registry.remove(key) diff --git a/ktor-server/ktor-server-plugins/ktor-server-auth/common/test/io/ktor/tests/auth/SessionAuthTest.kt b/ktor-server/ktor-server-plugins/ktor-server-auth/common/test/io/ktor/tests/auth/SessionAuthTest.kt index 0fcdefca394..c565add44a4 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-auth/common/test/io/ktor/tests/auth/SessionAuthTest.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-auth/common/test/io/ktor/tests/auth/SessionAuthTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.tests.auth @@ -14,7 +14,6 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.server.sessions.* import io.ktor.server.testing.* -import io.ktor.utils.io.core.* import kotlinx.serialization.* import kotlin.test.* diff --git a/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt b/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt index c688ed37db0..1c6d68b0d96 100644 --- a/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt +++ b/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt @@ -14,7 +14,6 @@ import io.ktor.server.engine.* import io.ktor.server.routing.* import io.ktor.server.testing.* import io.ktor.util.logging.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.coroutines.* import kotlin.time.Duration.Companion.seconds diff --git a/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt b/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt index 6e8967fe3ce..f888ea13575 100644 --- a/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt +++ b/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt @@ -17,7 +17,6 @@ import io.ktor.server.engine.* import io.ktor.server.routing.* import io.ktor.server.testing.* import io.ktor.util.logging.* -import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.coroutines.* import kotlin.time.Duration.Companion.seconds diff --git a/ktor-server/ktor-server-test-suites/common/src/io/ktor/server/testing/suites/HttpServerCommonTestSuite.kt b/ktor-server/ktor-server-test-suites/common/src/io/ktor/server/testing/suites/HttpServerCommonTestSuite.kt index 2ab284af42d..183cb89576b 100644 --- a/ktor-server/ktor-server-test-suites/common/src/io/ktor/server/testing/suites/HttpServerCommonTestSuite.kt +++ b/ktor-server/ktor-server-test-suites/common/src/io/ktor/server/testing/suites/HttpServerCommonTestSuite.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.server.testing.suites @@ -33,6 +33,7 @@ import kotlin.coroutines.AbstractCoroutineContextElement import kotlin.coroutines.CoroutineContext import kotlin.test.* import kotlin.time.Duration.Companion.minutes +import kotlin.use abstract class HttpServerCommonTestSuite( hostFactory: ApplicationEngineFactory diff --git a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerJvmTestSuite.kt b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerJvmTestSuite.kt index 01c2e74bf27..87953596721 100644 --- a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerJvmTestSuite.kt +++ b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerJvmTestSuite.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.server.testing.suites @@ -25,6 +25,7 @@ import kotlin.coroutines.* import kotlin.test.* import kotlin.text.toByteArray import kotlin.time.Duration.Companion.seconds +import kotlin.use abstract class HttpServerJvmTestSuite( hostFactory: ApplicationEngineFactory diff --git a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/SustainabilityTestSuite.kt b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/SustainabilityTestSuite.kt index aac0cab8d0e..c939d333416 100644 --- a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/SustainabilityTestSuite.kt +++ b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/SustainabilityTestSuite.kt @@ -35,6 +35,7 @@ import java.util.* import java.util.concurrent.* import java.util.concurrent.atomic.* import kotlin.test.* +import kotlin.use abstract class SustainabilityTestSuite( hostFactory: ApplicationEngineFactory diff --git a/ktor-server/ktor-server-test-suites/jvmAndPosix/src/io/ktor/server/testing/suites/WebSocketEngineSuite.kt b/ktor-server/ktor-server-test-suites/jvmAndPosix/src/io/ktor/server/testing/suites/WebSocketEngineSuite.kt index 30249e5b72e..f128bea5a70 100644 --- a/ktor-server/ktor-server-test-suites/jvmAndPosix/src/io/ktor/server/testing/suites/WebSocketEngineSuite.kt +++ b/ktor-server/ktor-server-test-suites/jvmAndPosix/src/io/ktor/server/testing/suites/WebSocketEngineSuite.kt @@ -26,6 +26,7 @@ import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +import kotlin.use @OptIn(InternalAPI::class) abstract class WebSocketEngineSuite( diff --git a/ktor-utils/jvm/src/io/ktor/util/cio/FileChannels.kt b/ktor-utils/jvm/src/io/ktor/util/cio/FileChannels.kt index e673f52f114..c6b72d89991 100644 --- a/ktor-utils/jvm/src/io/ktor/util/cio/FileChannels.kt +++ b/ktor-utils/jvm/src/io/ktor/util/cio/FileChannels.kt @@ -1,12 +1,10 @@ /* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.util.cio -import io.ktor.util.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* import io.ktor.utils.io.jvm.nio.* import kotlinx.coroutines.* import java.io.*