mirror of
https://github.com/apple/pkl.git
synced 2026-03-23 17:41:10 +01:00
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:
@@ -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.
|
||||
@@ -20,10 +20,6 @@ import java.nio.charset.Charset
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.FileAttribute
|
||||
import java.util.stream.Stream
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.isSymbolicLink
|
||||
|
||||
// not stored to avoid build-time initialization by native-image
|
||||
val currentWorkingDir: Path
|
||||
@@ -40,38 +36,21 @@ fun Path.walk(maxDepth: Int = Int.MAX_VALUE, vararg options: FileVisitOption): S
|
||||
fun Path.createTempFile(
|
||||
prefix: String? = null,
|
||||
suffix: String? = null,
|
||||
vararg attributes: FileAttribute<*>
|
||||
vararg attributes: FileAttribute<*>,
|
||||
): Path = Files.createTempFile(this, prefix, suffix, *attributes)
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun Path.createParentDirectories(vararg attributes: FileAttribute<*>): Path = apply {
|
||||
// Files.createDirectories will throw a FileAlreadyExistsException
|
||||
// if the file exists and is not a directory and symlinks are never
|
||||
// directories
|
||||
if (parent?.isSymbolicLink() != true) {
|
||||
parent?.createDirectories(*attributes)
|
||||
}
|
||||
}
|
||||
|
||||
/** [Files.writeString] seems more efficient than [kotlin.io.path.writeText]. */
|
||||
@Throws(IOException::class)
|
||||
fun Path.writeString(
|
||||
text: String,
|
||||
charset: Charset = Charsets.UTF_8,
|
||||
vararg options: OpenOption
|
||||
vararg options: OpenOption,
|
||||
): Path = Files.writeString(this, text, charset, *options)
|
||||
|
||||
/** [Files.readString] seems more efficient than [kotlin.io.path.readText]. */
|
||||
@Throws(IOException::class)
|
||||
fun Path.readString(charset: Charset = Charsets.UTF_8): String = Files.readString(this, charset)
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun Path.deleteRecursively() {
|
||||
if (exists()) {
|
||||
walk().use { paths -> paths.sorted(Comparator.reverseOrder()).forEach { it.deleteIfExists() } }
|
||||
}
|
||||
}
|
||||
|
||||
private val isWindows by lazy { System.getProperty("os.name").contains("Windows") }
|
||||
|
||||
/** Copy implementation from IoUtils.toNormalizedPathString */
|
||||
|
||||
@@ -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.
|
||||
@@ -18,7 +18,6 @@ package org.pkl.commons
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
fun String.toPath(): Path = Path.of(this)
|
||||
|
||||
Reference in New Issue
Block a user