mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Invoke Dokka in the same JVM.
This commit is contained in:
parent
b2dd509d4f
commit
efc32b4aa4
1 changed files with 55 additions and 40 deletions
|
@ -1,20 +1,19 @@
|
||||||
package com.beust.kobalt.plugin.dokka
|
package com.beust.kobalt.plugin.dokka
|
||||||
|
|
||||||
import com.beust.kobalt.JavaInfo
|
|
||||||
import com.beust.kobalt.SystemProperties
|
|
||||||
import com.beust.kobalt.TaskResult
|
import com.beust.kobalt.TaskResult
|
||||||
import com.beust.kobalt.api.ConfigPlugin
|
import com.beust.kobalt.api.ConfigPlugin
|
||||||
import com.beust.kobalt.api.JarFinder
|
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
|
||||||
import com.beust.kobalt.maven.DepFactory
|
import com.beust.kobalt.maven.DepFactory
|
||||||
import com.beust.kobalt.misc.RunCommand
|
import com.beust.kobalt.misc.KobaltLogger
|
||||||
import com.beust.kobalt.misc.error
|
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import java.io.File
|
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
||||||
|
import org.jetbrains.dokka.DokkaGenerator
|
||||||
|
import org.jetbrains.dokka.DokkaLogger
|
||||||
|
import org.jetbrains.dokka.SourceLinkDefinition
|
||||||
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -24,36 +23,39 @@ class DokkaPlugin @Inject constructor(val depFactory: DepFactory) : ConfigPlugin
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PLUGIN_NAME = "dokka"
|
const val PLUGIN_NAME = "dokka"
|
||||||
const val DOKKA_ID = "org.jetbrains.dokka:dokka-fatjar:0.9.1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Probably no point in running this task if "assemble" hasn't completed.
|
* Probably no point in running this task if "assemble" hasn't completed.
|
||||||
*/
|
*/
|
||||||
@Task(name = "dokka", description = "Run dokka",
|
@Task(name = "dokka", description = "Run dokka", runAfter = arrayOf(PackagingPlugin.TASK_ASSEMBLE))
|
||||||
runBefore = arrayOf("compile")
|
|
||||||
// runAfter = arrayOf(PackagingPlugin.TASK_ASSEMBLE)
|
|
||||||
)
|
|
||||||
fun taskDokka(project: Project) : TaskResult {
|
fun taskDokka(project: Project) : TaskResult {
|
||||||
val javaExecutable = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
|
|
||||||
val config = configurationFor(project)
|
val config = configurationFor(project)
|
||||||
val classpath = context.dependencyManager.calculateDependencies(project, context)
|
val classpath = context.dependencyManager.calculateDependencies(project, context)
|
||||||
val buildDir = project.projectProperties.getString(JvmCompilerPlugin.BUILD_DIR)
|
val buildDir = project.buildDirectory!!
|
||||||
val classpathString = (classpath.map { it.jarFile.get().absolutePath } +
|
val classpathList = (classpath.map { it.jarFile.get().absolutePath } + listOf(buildDir))
|
||||||
listOf(buildDir))
|
|
||||||
.joinToString(File.pathSeparator)
|
|
||||||
val dokkaJar = JarFinder.byId(DOKKA_ID)
|
|
||||||
var success = true
|
var success = true
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
val args : List<String> = listOf(
|
if (! config.skip) {
|
||||||
"-classpath", classpathString,
|
val outputDir = buildDir + "/" +
|
||||||
"-jar", dokkaJar.absolutePath,
|
if (config.outputDir.isBlank()) "doc" else config.outputDir
|
||||||
*(project.sourceDirectories.toTypedArray())) +
|
|
||||||
config.args
|
val gen = DokkaGenerator(
|
||||||
RunCommand(javaExecutable.absolutePath).run(args, errorCallback = { output: List<String> ->
|
KobaltDokkaLogger { success = false },
|
||||||
error("Error running dokka:\n " + output.joinToString("\n"))
|
classpathList,
|
||||||
success = false
|
project.sourceDirectories.toList(),
|
||||||
})
|
config.samplesDirs,
|
||||||
|
config.includeDirs,
|
||||||
|
config.moduleName,
|
||||||
|
outputDir,
|
||||||
|
config.outputFormat,
|
||||||
|
config.sourceLinks.map { SourceLinkDefinition(it.dir, it.url, it.urlSuffix) }
|
||||||
|
)
|
||||||
|
gen.generate()
|
||||||
|
log(2, "Documentation generated in $outputDir")
|
||||||
|
} else {
|
||||||
|
log(2, "skip is true, not generating the documentation")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log(2, "No dokka configuration found for project ${project.name}, skipping it")
|
log(2, "No dokka configuration found for project ${project.name}, skipping it")
|
||||||
}
|
}
|
||||||
|
@ -61,27 +63,40 @@ class DokkaPlugin @Inject constructor(val depFactory: DepFactory) : ConfigPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DokkaConfig() {
|
class KobaltDokkaLogger(val onErrorCallback: () -> Unit = {}) : DokkaLogger {
|
||||||
val args = arrayListOf<String>()
|
override fun error(message: String) {
|
||||||
fun args(vararg options: String) {
|
KobaltLogger.logger.error("Dokka", message)
|
||||||
args.addAll(options)
|
onErrorCallback()
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkMapping: LinkMappingConfig? = null
|
override fun info(message: String) {
|
||||||
|
KobaltLogger.logger.log(2, message)
|
||||||
|
}
|
||||||
|
|
||||||
@Directive
|
override fun warn(message: String) {
|
||||||
fun linkMapping(init: LinkMappingConfig.() -> Unit) {
|
KobaltLogger.logger.warn("Dokka", message)
|
||||||
linkMapping = LinkMappingConfig().let {
|
|
||||||
it.init()
|
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkMappingConfig {
|
class SourceLinkMapItem {
|
||||||
var dir: String = ""
|
var dir: String = ""
|
||||||
var url: String = ""
|
var url: String = ""
|
||||||
var suffix: String? = null
|
var urlSuffix: String? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class DokkaConfig(
|
||||||
|
var samplesDirs: List<String> = emptyList(),
|
||||||
|
var includeDirs: List<String> = emptyList(),
|
||||||
|
var outputDir: String = "",
|
||||||
|
var outputFormat: String = "html",
|
||||||
|
var sourceLinks : ArrayList<SourceLinkMapItem> = arrayListOf<SourceLinkMapItem>(),
|
||||||
|
var moduleName: String = "",
|
||||||
|
var skip: Boolean = false) {
|
||||||
|
|
||||||
|
fun sourceLinks(init: SourceLinkMapItem.() -> Unit) {
|
||||||
|
val s: SourceLinkMapItem = SourceLinkMapItem().apply { init() }
|
||||||
|
sourceLinks.add(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue