From 0c33c3c53517a33521ba1176a929867f2f60ebec Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 2 Nov 2016 14:19:14 +0300 Subject: Fix for GH #99 : Dokka crash on startup if dokka-fatjar located in path with spaces --- core/src/main/kotlin/Utilities/ServiceLocator.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/main/kotlin/Utilities/ServiceLocator.kt b/core/src/main/kotlin/Utilities/ServiceLocator.kt index 6c29d1cd..71bfd21b 100644 --- a/core/src/main/kotlin/Utilities/ServiceLocator.kt +++ b/core/src/main/kotlin/Utilities/ServiceLocator.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.Utilities import java.io.File +import java.net.URISyntaxException +import java.net.URL import java.util.* import java.util.jar.JarFile import java.util.zip.ZipEntry @@ -40,14 +42,24 @@ object ServiceLocator { return ServiceDescriptor(implementationName, category, properties["description"]?.toString(), className) } + fun URL.toFile(): File { + assert(protocol == "file") + + return try { + File(toURI()) + } catch (e: URISyntaxException) { //Try to handle broken URLs, with unescaped spaces + File(path) + } + } + fun allServices(category: String): List { val entries = this.javaClass.classLoader.getResources("dokka/$category")?.toList() ?: emptyList() return entries.flatMap { when (it.protocol) { - "file" -> File(it.file).listFiles()?.filter { it.extension == "properties" }?.map { lookupDescriptor(category, it.nameWithoutExtension) } ?: emptyList() + "file" -> it.toFile().listFiles()?.filter { it.extension == "properties" }?.map { lookupDescriptor(category, it.nameWithoutExtension) } ?: emptyList() "jar" -> { - val file = JarFile(it.file.removePrefix("file:").substringBefore("!")) + val file = JarFile(URL(it.file.substringBefore("!")).toFile()) try { val jarPath = it.file.substringAfterLast("!").removePrefix("/") file.entries() -- cgit