diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-04-08 16:23:19 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-04-22 13:10:48 +0200 |
commit | 5a72f4a7e63d96f98072bf3989373592c2b906c2 (patch) | |
tree | 202f5f86cd8e3b50cd93bf1b8c2bdc02788fed92 /plugins/base/src/main | |
parent | 089113e352ecd49216602bb1a02fbfada6a40788 (diff) | |
download | dokka-5a72f4a7e63d96f98072bf3989373592c2b906c2.tar.gz dokka-5a72f4a7e63d96f98072bf3989373592c2b906c2.tar.bz2 dokka-5a72f4a7e63d96f98072bf3989373592c2b906c2.zip |
Apply requested changes
Diffstat (limited to 'plugins/base/src/main')
3 files changed, 43 insertions, 30 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 4178e427..1b187984 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka.base.renderers -import com.sun.jna.platform.win32.COM.Dispatch import kotlinx.coroutines.* import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.local.LocationProvider @@ -120,11 +119,11 @@ abstract class DefaultRenderer<T>( open suspend fun renderPage(page: PageNode) { val path by lazy { locationProvider.resolve(page, skipExtension = true) } when (page) { - is ContentPage -> outputWriter.write(path, runBlocking { buildPage(page) { c, p -> buildPageContent(c, p) } }, ".html") + is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> buildPageContent(c, p) }, ".html") is RendererSpecificPage -> when (val strategy = page.strategy) { is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, path) is RenderingStrategy.Write -> outputWriter.write(path, strategy.text, "") - is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this@DefaultRenderer, page), ".html") + is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this, page), ".html") RenderingStrategy.DoNothing -> Unit } else -> throw AssertionError( @@ -133,23 +132,28 @@ abstract class DefaultRenderer<T>( } } - private suspend fun CoroutineScope.renderPages(root: PageNode) { + private suspend fun renderPages(root: PageNode) { coroutineScope { - launch(Dispatchers.IO) { renderPage(root) }.join() + renderPage(root) + root.children.forEach { - renderPages(it) + launch { renderPages(it) } } } } // reimplement this as preprocessor - open suspend fun renderPackageList(root: ContentPage) = + open fun renderPackageList(root: ContentPage) = getPackageNamesAndPlatforms(root) .keys .joinToString("\n") - .also { outputWriter.write("${root.name}/package-list", it, "") } + .also { + runBlocking { + outputWriter.write("${root.name}/package-list", it, "") + } + } - open suspend fun getPackageNamesAndPlatforms(root: PageNode): Map<String, List<PlatformData>> = + open fun getPackageNamesAndPlatforms(root: PageNode): Map<String, List<PlatformData>> = root.children .map { getPackageNamesAndPlatforms(it) } .fold(emptyMap<String, List<PlatformData>>()) { e, acc -> acc + e } + @@ -159,16 +163,16 @@ abstract class DefaultRenderer<T>( emptyMap() } - protected fun renderImpl(coroutineScope: CoroutineScope, root: RootPageNode): Job = coroutineScope.launch(Dispatchers.Default) { + override fun render(root: RootPageNode) { val newRoot = preprocessors.fold(root) { acc, t -> t(acc) } locationProvider = context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(newRoot) - renderPages(newRoot) + runBlocking { + renderPages(newRoot) + } } - - override fun CoroutineScope.render(root: RootPageNode) = renderImpl(this, root) } fun ContentPage.platforms() = this.content.platforms.toList()
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/FileWriter.kt b/plugins/base/src/main/kotlin/renderers/FileWriter.kt index 07d25eb6..fff16e48 100644 --- a/plugins/base/src/main/kotlin/renderers/FileWriter.kt +++ b/plugins/base/src/main/kotlin/renderers/FileWriter.kt @@ -1,5 +1,7 @@ package org.jetbrains.dokka.base.renderers +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.jetbrains.dokka.plugability.DokkaContext import java.io.File import java.io.IOException @@ -20,8 +22,10 @@ class FileWriter(val context: DokkaContext): OutputWriter { try { val dir = Paths.get(root, path.dropLastWhile { it != '/' }).toFile() - dir.mkdirsOrFail() - Files.write(Paths.get(root, "$path$ext"), text.lines()) + withContext(Dispatchers.IO) { + dir.mkdirsOrFail() + Files.write(Paths.get(root, "$path$ext"), text.lines()) + } } catch (e: Throwable) { context.logger.error("Failed to write $this. ${e.message}") e.printStackTrace() @@ -36,13 +40,15 @@ class FileWriter(val context: DokkaContext): OutputWriter { } - private fun copyFromDirectory(pathFrom: String, pathTo: String) { + private suspend fun copyFromDirectory(pathFrom: String, pathTo: String) { val dest = Paths.get(root, pathTo).toFile() val uri = javaClass.getResource(pathFrom).toURI() - File(uri).copyRecursively(dest, true) + withContext(Dispatchers.IO) { + File(uri).copyRecursively(dest, true) + } } - private fun copyFromJar(pathFrom: String, pathTo: String) { + private suspend fun copyFromJar(pathFrom: String, pathTo: String) { val rebase = fun(path: String) = "$pathTo/${path.removePrefix(pathFrom)}" val dest = Paths.get(root, pathTo).toFile() @@ -53,12 +59,16 @@ class FileWriter(val context: DokkaContext): OutputWriter { for (file in Files.walk(path).iterator()) { if (Files.isDirectory(file)) { val dirPath = file.toAbsolutePath().toString() - Paths.get(root, rebase(dirPath)).toFile().mkdirsOrFail() + withContext(Dispatchers.IO) { + Paths.get(root, rebase(dirPath)).toFile().mkdirsOrFail() + } } else { val filePath = file.toAbsolutePath().toString() - Paths.get(root, rebase(filePath)).toFile().writeBytes( - javaClass.getResourceAsStream(filePath).readBytes() - ) + withContext(Dispatchers.IO) { + Paths.get(root, rebase(filePath)).toFile().writeBytes( + javaClass.getResourceAsStream(filePath).readBytes() + ) + } } } } diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index a32cb715..796d6483 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -1,9 +1,6 @@ package org.jetbrains.dokka.base.renderers.html -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import kotlinx.html.* import kotlinx.html.stream.createHTML import org.jetbrains.dokka.base.DokkaBase @@ -286,10 +283,12 @@ open class HtmlRenderer( text(textNode.text) } - override fun CoroutineScope.render(root: RootPageNode): Job { - super.renderImpl(this, root) - return launch(Dispatchers.IO) { - outputWriter.write("scripts/pages", "var pages = [\n${pageList.joinToString(",\n")}\n]", ".js") + override fun render(root: RootPageNode) { + super.render(root) + runBlocking { + launch(Dispatchers.IO) { + outputWriter.write("scripts/pages", "var pages = [\n${pageList.joinToString(",\n")}\n]", ".js") + } } } |