commonMain.co.touchlab.skie.plugin.util.JarUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin-impl-jvm Show documentation
Show all versions of gradle-plugin-impl-jvm Show documentation
Internal implementation for SKIE Gradle plugin.
package co.touchlab.skie.plugin.util
import java.io.File
import java.net.URI
import java.nio.file.FileSystem
import java.nio.file.FileSystemNotFoundException
import java.nio.file.FileSystems
fun File.writeToZip(write: (FileSystem) -> Unit) {
val fileUri = this.toURI()
// Solves an issues with spaces in the path
val uri = URI("jar:file", fileUri.userInfo, fileUri.host, fileUri.port, fileUri.path, fileUri.query, fileUri.fragment)
val fileSystem = try {
FileSystems.getFileSystem(uri)
} catch (_: FileSystemNotFoundException) {
FileSystems.newFileSystem(uri, mapOf("create" to true))
}
fileSystem.use(write)
}