mirror of
https://github.com/apple/pkl.git
synced 2026-04-17 05:59:46 +02:00
Add support for Windows (#492)
This adds support for Windows. The in-language path separator is still `/`, to ensure Pkl programs are cross-platform. Log lines are written using CRLF endings on Windows. Modules that are combined with `--module-output-separator` uses LF endings to ensure consistent rendering across platforms. `jpkl` does not work on Windows as a direct executable. However, it can work with `java -jar jpkl`. Additional details: * Adjust git settings for Windows * Add native executable for pkl cli * Add jdk17 windows Gradle check in CI * Adjust CI test reports to be staged within Gradle rather than by shell script. * Fix: encode more characters that are not safe Windows paths * Skip running tests involving symbolic links on Windows (these require administrator privileges to run). * Introduce custom implementation of `IoUtils.relativize` * Allow Gradle to initialize ExecutableJar `Property` values * Add Gradle flag to enable remote JVM debugging Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
This commit is contained in:
@@ -71,3 +71,13 @@ fun Path.deleteRecursively() {
|
||||
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 */
|
||||
fun Path.toNormalizedPathString(): String {
|
||||
if (isWindows) {
|
||||
return toString().replace("\\", "/")
|
||||
}
|
||||
return toString()
|
||||
}
|
||||
|
||||
@@ -15,15 +15,24 @@
|
||||
*/
|
||||
package org.pkl.commons
|
||||
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
import java.util.regex.Pattern
|
||||
|
||||
fun String.toPath(): Path = Path.of(this)
|
||||
|
||||
private val uriLike = Pattern.compile("\\w+:[^\\\\].*")
|
||||
|
||||
private val windowsPathLike = Pattern.compile("\\w:\\\\.*")
|
||||
|
||||
/** Copy of org.pkl.core.util.IoUtils.toUri */
|
||||
fun String.toUri(): URI =
|
||||
if (contains(":")) {
|
||||
URI(this)
|
||||
} else {
|
||||
URI(null, null, this, null)
|
||||
fun String.toUri(): URI {
|
||||
if (uriLike.matcher(this).matches()) {
|
||||
return URI(this)
|
||||
}
|
||||
if (windowsPathLike.matcher(this).matches()) {
|
||||
return File(this).toURI()
|
||||
}
|
||||
return URI(null, null, this, null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user