diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-08-14 14:05:27 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-19 13:34:10 +0200 |
commit | 28d6598bc749612f75a5c1a4210eb4b0f5aa1f6e (patch) | |
tree | 204ed9515b974a11a6df99050a6790ad9d4f25bd /plugins/base/src/main/kotlin/resolvers/shared | |
parent | ac679cb145e2fbcd74bbf39d83dfbae2afeaeaad (diff) | |
download | dokka-28d6598bc749612f75a5c1a4210eb4b0f5aa1f6e.tar.gz dokka-28d6598bc749612f75a5c1a4210eb4b0f5aa1f6e.tar.bz2 dokka-28d6598bc749612f75a5c1a4210eb4b0f5aa1f6e.zip |
Split `PackageList.load()` into several methods
Diffstat (limited to 'plugins/base/src/main/kotlin/resolvers/shared')
-rw-r--r-- | plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt | 45 |
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+ + } } } |