blob: a8b1b187c5895c94a1c00c6550fb5974c6eb06c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package expect
import java.io.InputStream
import java.nio.file.Files
import java.nio.file.Path
import kotlin.streams.toList
data class ProcessResult(val code: Int, val out: String, val err: String? = null)
internal fun Path.dirsWithFormats(formats: List<String>): List<Pair<Path, String>> =
Files.list(this).toList().filter { Files.isDirectory(it) }.flatMap { p -> formats.map { p to it } }
internal fun Path.asString() = normalize().toString()
internal fun Path.deleteRecursively() = toFile().deleteRecursively()
internal fun Path.copyRecursively(target: Path) = toFile().copyRecursively(target.toFile())
internal fun Path.listRecursively(filter: (Path) -> Boolean): List<Path> = when {
Files.isDirectory(this) -> listOfNotNull(takeIf(filter)) + Files.list(this).toList().flatMap {
it.listRecursively(
filter
)
}
Files.isRegularFile(this) -> listOfNotNull(this.takeIf(filter))
else -> emptyList()
}
internal fun InputStream.bufferResult(): String = this.bufferedReader().lines().toList().joinToString("\n")
|