aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt11
-rw-r--r--core/src/main/kotlin/renderers/Renderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt30
-rw-r--r--plugins/base/src/main/kotlin/renderers/FileWriter.kt28
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt15
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt30
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt8
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt5
8 files changed, 52 insertions, 79 deletions
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index 0a797769..053b4cb6 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -3,10 +3,6 @@ package org.jetbrains.dokka
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiManager
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.runBlocking
import org.jetbrains.dokka.analysis.AnalysisEnvironment
import org.jetbrains.dokka.analysis.DokkaResolutionFacade
import org.jetbrains.dokka.model.DModule
@@ -113,12 +109,7 @@ class DokkaGenerator(
context: DokkaContext
) {
val renderer = context.single(CoreExtensions.renderer)
- runBlocking {
- val scope = this
- with(renderer) {
- scope.render(transformedPages).join()
- }
- }
+ renderer.render(transformedPages)
}
private fun createEnvironmentAndFacade(pass: DokkaConfiguration.PassConfiguration): EnvironmentAndFacade =
diff --git a/core/src/main/kotlin/renderers/Renderer.kt b/core/src/main/kotlin/renderers/Renderer.kt
index 9d054503..10235f21 100644
--- a/core/src/main/kotlin/renderers/Renderer.kt
+++ b/core/src/main/kotlin/renderers/Renderer.kt
@@ -1,9 +1,7 @@
package org.jetbrains.dokka.renderers
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Job
import org.jetbrains.dokka.pages.RootPageNode
interface Renderer {
- fun CoroutineScope.render(root: RootPageNode): Job
+ fun render(root: RootPageNode)
} \ No newline at end of file
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")
+ }
}
}
diff --git a/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt b/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt
index da89a352..43eccae6 100644
--- a/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt
@@ -1,9 +1,7 @@
package renderers.html
-import kotlinx.coroutines.runBlocking
import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
import org.jetbrains.dokka.pages.TextStyle
-import org.jsoup.Jsoup
import org.junit.jupiter.api.Test
import renderers.*
@@ -19,12 +17,7 @@ class GroupWrappingTest: RenderingOnlyTestBase() {
text("c")
}
- runBlocking {
- val scope = this
- with(HtmlRenderer(context)) {
- scope.render(page)
- }
- }
+ HtmlRenderer(context).render(page)
renderedContent.match("abc")
}
@@ -39,12 +32,7 @@ class GroupWrappingTest: RenderingOnlyTestBase() {
text("c")
}
- runBlocking {
- val scope = this
- with(HtmlRenderer(context)) {
- scope.render(page)
- }
- }
+ HtmlRenderer(context).render(page)
renderedContent.match(P("ab"), "c")
}
@@ -59,12 +47,7 @@ class GroupWrappingTest: RenderingOnlyTestBase() {
text("c")
}
- runBlocking {
- val scope = this
- with(HtmlRenderer(context)) {
- scope.render(page)
- }
- }
+ HtmlRenderer(context).render(page)
renderedContent.match(Div("ab"), "c")
}
@@ -84,12 +67,7 @@ class GroupWrappingTest: RenderingOnlyTestBase() {
}
}
- runBlocking {
- val scope = this
- with(HtmlRenderer(context)) {
- scope.render(page)
- }
- }
+ HtmlRenderer(context).render(page)
renderedContent.match(Div("a", Div(Div("bc")), "d"))
}
diff --git a/plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt b/plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt
index 3e603955..cf1ac0a9 100644
--- a/plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt
@@ -1,6 +1,5 @@
package renderers.html
-import kotlinx.coroutines.runBlocking
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
import org.jetbrains.dokka.pages.PlatformData
@@ -100,12 +99,7 @@ class PlatformDependentHintTest : RenderingOnlyTestBase() {
}
}
- runBlocking {
- val scope = this
- with(HtmlRenderer(context)) {
- scope.render(page)
- }
- }
+ HtmlRenderer(context).render(page)
println(renderedContent)
renderedContent.match(Div(Div("ab")))
}
diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
index 185dacac..c65f3673 100644
--- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt
+++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
@@ -1,6 +1,5 @@
package org.jetbrains.dokka.gfm
-import kotlinx.coroutines.*
import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.DefaultRenderer
@@ -204,11 +203,11 @@ open class CommonmarkRenderer(
override suspend fun renderPage(page: PageNode) {
val path by lazy { locationProvider.resolve(page, skipExtension = true) }
when (page) {
- is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> runBlocking { buildPageContent(c, p) } }, ".md")
+ is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> buildPageContent(c, p) }, ".md")
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@CommonmarkRenderer, page), ".md")
+ is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this, page), ".md")
RenderingStrategy.DoNothing -> Unit
}
else -> throw AssertionError(