From 39631054c58df5841ea268b7002b820ec55f6e0a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 3 Dec 2015 16:22:11 +0100 Subject: restructure Dokka build to use Gradle for everything except for the Maven plugin --- .../src/main/kotlin/Generation/ConsoleGenerator.kt | 42 ++++++++++++++++ core/src/main/kotlin/Generation/FileGenerator.kt | 57 ++++++++++++++++++++++ core/src/main/kotlin/Generation/Generator.kt | 19 ++++++++ 3 files changed, 118 insertions(+) create mode 100644 core/src/main/kotlin/Generation/ConsoleGenerator.kt create mode 100644 core/src/main/kotlin/Generation/FileGenerator.kt create mode 100644 core/src/main/kotlin/Generation/Generator.kt (limited to 'core/src/main/kotlin/Generation') diff --git a/core/src/main/kotlin/Generation/ConsoleGenerator.kt b/core/src/main/kotlin/Generation/ConsoleGenerator.kt new file mode 100644 index 00000000..803a16e4 --- /dev/null +++ b/core/src/main/kotlin/Generation/ConsoleGenerator.kt @@ -0,0 +1,42 @@ +package org.jetbrains.dokka + +public class ConsoleGenerator(val signatureGenerator: LanguageService, val locationService: LocationService) { + val IndentStep = " " + + public fun generate(node: DocumentationNode, indent: String = "") { + println("@${locationService.location(node).path}") + generateHeader(node, indent) + //generateDetails(node, indent) + generateMembers(node, indent) + generateLinks(node, indent) + } + + public fun generateHeader(node: DocumentationNode, indent: String = "") { + println(indent + signatureGenerator.render(node)) + val docString = node.content.toString() + if (!docString.isEmpty()) + println("$indent\"${docString.replace("\n", "\n$indent")}\"") + println() + } + + public fun generateMembers(node: DocumentationNode, indent: String = "") { + val items = node.members.sortedBy { it.name } + for (child in items) + generate(child, indent + IndentStep) + } + + public fun generateDetails(node: DocumentationNode, indent: String = "") { + val items = node.details + for (child in items) + generate(child, indent + " ") + } + + public fun generateLinks(node: DocumentationNode, indent: String = "") { + val items = node.links + if (items.isEmpty()) + return + println("$indent Links") + for (child in items) + generate(child, indent + " ") + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/Generation/FileGenerator.kt b/core/src/main/kotlin/Generation/FileGenerator.kt new file mode 100644 index 00000000..a762bae3 --- /dev/null +++ b/core/src/main/kotlin/Generation/FileGenerator.kt @@ -0,0 +1,57 @@ +package org.jetbrains.dokka + +import com.google.inject.Inject +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.io.OutputStreamWriter + +public class FileGenerator @Inject constructor(val locationService: FileLocationService) : Generator { + + @set:Inject(optional = true) var outlineService: OutlineFormatService? = null + @set:Inject(optional = true) lateinit var formatService: FormatService + + override fun buildPages(nodes: Iterable) { + val specificLocationService = locationService.withExtension(formatService.extension) + + for ((location, items) in nodes.groupBy { specificLocationService.location(it) }) { + val file = location.file + file.parentFile?.mkdirsOrFail() + try { + FileOutputStream(file).use { + OutputStreamWriter(it, Charsets.UTF_8).use { + it.write(formatService.format(location, items)) + } + } + } catch (e: Throwable) { + println(e) + } + buildPages(items.flatMap { it.members }) + } + } + + override fun buildOutlines(nodes: Iterable) { + val outlineService = this.outlineService ?: return + for ((location, items) in nodes.groupBy { locationService.location(it) }) { + val file = outlineService.getOutlineFileName(location) + file.parentFile?.mkdirsOrFail() + FileOutputStream(file).use { + OutputStreamWriter(it, Charsets.UTF_8).use { + it.write(outlineService.formatOutline(location, items)) + } + } + } + } + + override fun buildSupportFiles() { + FileOutputStream(locationService.location(listOf("style.css"), false).file).use { + javaClass.getResourceAsStream("/dokka/styles/style.css").copyTo(it) + } + } +} + +private fun File.mkdirsOrFail() { + if (!mkdirs() && !exists()) { + throw IOException("Failed to create directory $this") + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/Generation/Generator.kt b/core/src/main/kotlin/Generation/Generator.kt new file mode 100644 index 00000000..ac10a6a5 --- /dev/null +++ b/core/src/main/kotlin/Generation/Generator.kt @@ -0,0 +1,19 @@ +package org.jetbrains.dokka + +public interface Generator { + fun buildPages(nodes: Iterable) + fun buildOutlines(nodes: Iterable) + fun buildSupportFiles() +} + +fun Generator.buildAll(nodes: Iterable) { + buildPages(nodes) + buildOutlines(nodes) + buildSupportFiles() +} + +fun Generator.buildPage(node: DocumentationNode): Unit = buildPages(listOf(node)) + +fun Generator.buildOutline(node: DocumentationNode): Unit = buildOutlines(listOf(node)) + +fun Generator.buildAll(node: DocumentationNode): Unit = buildAll(listOf(node)) -- cgit