Update Kotlin to 2.0 (#900)

- update Kotlin from 1.7.10 to 2.0.21
  - Kotlin 1.6 dependencies in Gradle lock files are expected because kotlinc,
    which is also used by some tests, internally uses some 1.6 dependencies
    for backwards compatibility reasons.
- update kotlinx-html and kotlinx-serialization
- adapt Kotlin code where necessary
- use Kotlin stdlib Path APIs where possible
- fix IntelliJ Kotlin inspection warnings
- reformat code with `./gradlew spotlessApply`
  - ktfmt adds lots of trailing commas
- Add workaround to fix IntelliJ "unresolved reference" errors
This commit is contained in:
odenix
2025-01-23 14:41:59 -08:00
committed by GitHub
parent cdd6d52642
commit 258eda8630
87 changed files with 1042 additions and 1004 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import javax.net.ssl.SSLSession
class FakeHttpResponse<T : Any> : HttpResponse<T> {
companion object {
@Suppress("unused")
fun <T : Any> withBody(block: FakeHttpResponse<T>.() -> Unit): FakeHttpResponse<T> =
FakeHttpResponse<T>().apply(block)

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ import org.pkl.commons.toNormalizedPathString
abstract class InputOutputTestEngine :
HierarchicalTestEngine<InputOutputTestEngine.ExecutionContext>() {
protected val rootProjectDir = FileTestUtils.rootProjectDir
protected val rootProjectDir: Path = FileTestUtils.rootProjectDir
protected abstract val testClass: KClass<*>
@@ -67,7 +67,7 @@ abstract class InputOutputTestEngine :
override fun discover(
discoveryRequest: EngineDiscoveryRequest,
uniqueId: UniqueId
uniqueId: UniqueId,
): TestDescriptor {
val packageSelectors = discoveryRequest.getSelectorsByType(PackageSelector::class.java)
val classSelectors = discoveryRequest.getSelectorsByType(ClassSelector::class.java)
@@ -103,7 +103,7 @@ abstract class InputOutputTestEngine :
private fun doDiscover(
dirNode: InputDirNode,
uniqueIdSelectors: List<UniqueIdSelector>
uniqueIdSelectors: List<UniqueIdSelector>,
): TestDescriptor {
dirNode.inputDir.useDirectoryEntries { children ->
for (child in children) {
@@ -128,7 +128,7 @@ abstract class InputOutputTestEngine :
dirNode.addChild(
doDiscover(
InputDirNode(childId, child, DirectorySource.from(child.toFile())),
uniqueIdSelectors
uniqueIdSelectors,
)
)
}
@@ -137,12 +137,13 @@ abstract class InputOutputTestEngine :
return dirNode
}
override fun createExecutionContext(request: ExecutionRequest) = ExecutionContext()
override fun createExecutionContext(request: ExecutionRequest): ExecutionContext =
ExecutionContext()
private open inner class InputDirNode(
uniqueId: UniqueId,
val inputDir: Path,
source: TestSource
source: TestSource,
) :
AbstractTestDescriptor(uniqueId, inputDir.fileName.toString(), source), Node<ExecutionContext> {
override fun getType() = Type.CONTAINER
@@ -152,7 +153,7 @@ abstract class InputOutputTestEngine :
AbstractTestDescriptor(
uniqueId,
inputFile.fileName.toString(),
FileSource.from(inputFile.toFile())
FileSource.from(inputFile.toFile()),
),
Node<ExecutionContext> {
@@ -160,7 +161,7 @@ abstract class InputOutputTestEngine :
override fun execute(
context: ExecutionContext,
dynamicTestExecutor: DynamicTestExecutor
dynamicTestExecutor: DynamicTestExecutor,
): ExecutionContext {
val (success, actualOutput) = generateOutputFor(inputFile)

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +22,7 @@ import java.security.KeyStore
import java.util.concurrent.Executors
import javax.net.ssl.KeyManagerFactory
import javax.net.ssl.SSLContext
import kotlin.io.path.inputStream
import kotlin.io.path.isRegularFile
import org.pkl.commons.createParentDirectories
import org.pkl.commons.deleteRecursively
import kotlin.io.path.*
/**
* A test HTTP server that serves the Pkl packages defined under
@@ -44,6 +41,7 @@ import org.pkl.commons.deleteRecursively
* 4. Use port `0` in your test. `HttpClient` will replace this port with the server port.
* 4. [Close][close] the server, for example in [AfterAll][org.junit.jupiter.api.AfterAll].
*/
@OptIn(ExperimentalPathApi::class)
class PackageServer : AutoCloseable {
companion object {
const val BIRDS_SHA = "6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e"

View File

@@ -0,0 +1,24 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.commons.test
import kotlin.reflect.KClass
object ReflectionUtils {
// https://youtrack.jetbrains.com/issue/KT-14743/Reflection-Access-enum-values-and-valueOf-via-KClass#focus=Comments-27-1745309.0-0
@Suppress("UNCHECKED_CAST")
fun KClass<*>.enumValues(): Array<Enum<*>> = java.enumConstants as Array<Enum<*>>
}