aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/Utilities')
-rw-r--r--core/src/main/kotlin/Utilities/ServiceLocator.kt16
1 files changed, 14 insertions, 2 deletions
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<ServiceDescriptor> {
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()