aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAlex Saveau <asaveau@google.com>2020-07-09 04:34:43 +0000
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-09 10:40:43 +0200
commit555d0dee056c0f3591a2622d61af6491ccdbce70 (patch)
treeccb49170cf417f3c382844dbc664c2742bb5b616 /plugins
parent5a84b2332eb71cc2e4eaf3af2adde54bd590a720 (diff)
downloaddokka-555d0dee056c0f3591a2622d61af6491ccdbce70.tar.gz
dokka-555d0dee056c0f3591a2622d61af6491ccdbce70.tar.bz2
dokka-555d0dee056c0f3591a2622d61af6491ccdbce70.zip
Fix concurrency issue managing package request cache
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt15
1 files changed, 8 insertions, 7 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt
index ab633fdc..4204006e 100644
--- a/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt
+++ b/plugins/base/src/main/kotlin/resolvers/local/BaseLocationProvider.kt
@@ -7,15 +7,19 @@ import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.query
-import java.lang.IllegalStateException
import java.net.HttpURLConnection
import java.net.URL
import java.net.URLConnection
+import java.util.concurrent.locks.ReentrantReadWriteLock
+import kotlin.concurrent.read
+import kotlin.concurrent.write
abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) : LocationProvider {
protected val externalLocationProviderFactories =
dokkaContext.plugin<DokkaBase>().query { externalLocationProviderFactory }
+ private val cache: MutableMap<URL, DefaultLocationProvider.LocationInfo> = mutableMapOf()
+ private val lock = ReentrantReadWriteLock()
protected fun getExternalLocation(
dri: DRI,
@@ -31,7 +35,7 @@ abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) :
val toResolve: MutableMap<Int, MutableList<DokkaConfiguration.ExternalDocumentationLink>> = mutableMapOf()
for ((jdk, links) in jdkToExternalDocumentationLinks) {
for (link in links) {
- val info = cache[link.packageListUrl]
+ val info = lock.read { cache[link.packageListUrl] }
if (info == null) {
toResolve.getOrPut(jdk) { mutableListOf() }.add(link)
} else if (info.packages.contains(dri.packageName)) {
@@ -55,9 +59,6 @@ abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) :
return ""
}
- private val cache: MutableMap<URL, DefaultLocationProvider.LocationInfo> = mutableMapOf()
-
-
private fun getLink(dri: DRI, locationInfo: DefaultLocationProvider.LocationInfo): String =
locationInfo.locations[dri.packageName + "." + dri.classNames]
?: // Not sure if it can be here, previously it shadowed only kotlin/dokka related sources, here it shadows both dokka/javadoc, cause I cannot distinguish what LocationProvider has been hypothetically chosen
@@ -68,7 +69,7 @@ abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) :
else
throw IllegalStateException("Have not found any convenient ExternalLocationProvider for $dri DRI!")
- private fun loadPackageList(jdk: Int, url: URL): DefaultLocationProvider.LocationInfo {
+ private fun loadPackageList(jdk: Int, url: URL): DefaultLocationProvider.LocationInfo = lock.write {
val packageListStream = url.doOpenConnectionToReadContent().getInputStream()
val (params, packages) =
packageListStream
@@ -138,4 +139,4 @@ abstract class BaseLocationProvider(protected val dokkaContext: DokkaContext) :
const val DOKKA_PARAM_PREFIX = "\$dokka."
}
-} \ No newline at end of file
+}