aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/shared
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main/kotlin/resolvers/shared')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt45
1 files changed, 26 insertions, 19 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt
index bf59e2ff..819f5f09 100644
--- a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt
+++ b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt
@@ -16,27 +16,34 @@ data class PackageList(
return null
val packageListStream = url.readContent()
- val (params, packages) =
- packageListStream
- .bufferedReader()
- .useLines { lines -> lines.partition { it.startsWith(PackageListService.DOKKA_PARAM_PREFIX) } }
-
- val paramsMap = params.asSequence()
- .map { it.removePrefix("${PackageListService.DOKKA_PARAM_PREFIX}.").split(":", limit = 2) }
- .groupBy({ (key, _) -> key }, { (_, value) -> value })
-
- val format = paramsMap["format"]?.singleOrNull()?.let { RecognizedLinkFormat.fromString(it) } ?: when {
- jdkVersion < 8 -> RecognizedLinkFormat.Javadoc1 // Covers JDK 1 - 7
- jdkVersion < 10 -> RecognizedLinkFormat.Javadoc8 // Covers JDK 8 - 9
- else -> RecognizedLinkFormat.Javadoc10 // Covers JDK 10+
- }
-
- val locations = paramsMap["location"].orEmpty()
- .map { it.split("\u001f", limit = 2) }
- .map { (key, value) -> key to value }
- .toMap()
+
+
+ val (params, packages) = packageListStream
+ .bufferedReader()
+ .useLines { lines -> lines.partition { it.startsWith(PackageListService.DOKKA_PARAM_PREFIX) } }
+
+ val paramsMap = splitParams(params)
+ val format = linkFormat(paramsMap["format"]?.singleOrNull(), jdkVersion)
+ val locations = splitLocations(paramsMap["location"].orEmpty())
return PackageList(format, packages.toSet(), locations, url)
}
+
+
+ private fun splitParams(params: List<String>) = params.asSequence()
+ .map { it.removePrefix("${PackageListService.DOKKA_PARAM_PREFIX}.").split(":", limit = 2) }
+ .groupBy({ (key, _) -> key }, { (_, value) -> value })
+
+ private fun splitLocations(locations: List<String>) = locations.map { it.split("\u001f", limit = 2) }
+ .map { (key, value) -> key to value }
+ .toMap()
+
+ private fun linkFormat(formatName: String?, jdkVersion: Int) =
+ formatName?.let { RecognizedLinkFormat.fromString(it) }
+ ?: when {
+ jdkVersion < 8 -> RecognizedLinkFormat.Javadoc1 // Covers JDK 1 - 7
+ jdkVersion < 10 -> RecognizedLinkFormat.Javadoc8 // Covers JDK 8 - 9
+ else -> RecognizedLinkFormat.Javadoc10 // Covers JDK 10+
+ }
}
}