From 0b1d67b53354fdb0a8fdd89dc4f7f90e9f9388dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Gidiere?= Date: Sun, 5 Nov 2023 20:51:28 -0700 Subject: [PATCH] Actually fix issue --- .../src/main/kotlin/DistributionConfig.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/buildSrc/src/main/kotlin/DistributionConfig.kt b/buildSrc/src/main/kotlin/DistributionConfig.kt index 16276f500..f871b1cbb 100644 --- a/buildSrc/src/main/kotlin/DistributionConfig.kt +++ b/buildSrc/src/main/kotlin/DistributionConfig.kt @@ -3,6 +3,7 @@ import java.io.File import java.io.FileWriter import java.net.URI import java.net.URL +import java.nio.file.FileSystemNotFoundException import java.nio.file.FileSystems import java.nio.file.Files import java.nio.file.StandardCopyOption @@ -46,29 +47,28 @@ fun Project.configureDistribution() { // https://github.com/johnrengelman/shadow/issues/111 val dest = URI.create("jar:" + tasks.named("shadowJar").get().archiveFile.get().asFile.toURI()) - val preExistingProvider = try { + val provider = try { FileSystems.getFileSystem(dest) - } catch (e: Exception) { + } catch (e: FileSystemNotFoundException) { null - }; - val provider = if (preExistingProvider == null) { - preExistingProvider - } else { - FileSystems.newFileSystem(dest, mapOf("create" to "false"), null) - }; + } ?: FileSystems.newFileSystem(dest, mapOf("create" to "false"), null); provider?.use { fs -> forSubProjects(":common:addons") { - val jar = getJarTask() - - println("Packaging addon ${jar.archiveFileName.get()} to $dest. size: ${jar.archiveFile.get().asFile.length() / 1024}KB") - - val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else "" - val addonPath = fs.getPath("/addons/$boot${jar.archiveFileName.get()}") - - if (!Files.exists(addonPath)) { - Files.createDirectories(addonPath.parent) - Files.createFile(addonPath) - Files.copy(jar.archiveFile.get().asFile.toPath(), addonPath, StandardCopyOption.REPLACE_EXISTING) + if (fs.isOpen) { + val jar = getJarTask() + + if (jar.archiveFile.get().asFile.exists()) { + println("Packaging addon ${jar.archiveFileName.get()} to $dest. size: ${jar.archiveFile.get().asFile.length() / 1024}KB") + + val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else "" + val addonPath = fs.getPath("/addons/$boot${jar.archiveFileName.get()}") + + if (!Files.exists(addonPath)) { + Files.createDirectories(addonPath.parent) + Files.createFile(addonPath) + Files.copy(jar.archiveFile.get().asFile.toPath(), addonPath, StandardCopyOption.REPLACE_EXISTING) + } + } } }