mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Remove DokkaPlugin, fold it into KotlinPlugin.
This commit is contained in:
parent
73d73af0a7
commit
d90e2550ea
4 changed files with 84 additions and 114 deletions
|
@ -3,11 +3,8 @@ import com.beust.kobalt.*
|
|||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.plugin.application.application
|
||||
import com.beust.kobalt.plugin.dokka.*
|
||||
import com.beust.kobalt.plugin.java.javaCompiler
|
||||
import com.beust.kobalt.plugin.java.javaProject
|
||||
import com.beust.kobalt.plugin.kotlin.kotlinCompiler
|
||||
import com.beust.kobalt.plugin.kotlin.kotlinProject
|
||||
import com.beust.kobalt.plugin.java.*
|
||||
import com.beust.kobalt.plugin.kotlin.*
|
||||
import com.beust.kobalt.plugin.packaging.assemble
|
||||
import com.beust.kobalt.plugin.publish.github
|
||||
import com.beust.kobalt.plugin.publish.jcenter
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
package com.beust.kobalt.plugin.dokka
|
||||
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.ConfigsPlugin
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.misc.KobaltLogger
|
||||
import com.beust.kobalt.misc.log
|
||||
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.Singleton
|
||||
|
||||
@Singleton
|
||||
class DokkaPlugin : ConfigsPlugin<DokkaConfig>() {
|
||||
override val name = PLUGIN_NAME
|
||||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Dokka"
|
||||
}
|
||||
|
||||
/**
|
||||
* Probably no point in running this task if "assemble" hasn't completed so we're running after.
|
||||
*/
|
||||
@Task(name = "dokka", description = "Run dokka", runAfter = arrayOf(PackagingPlugin.TASK_ASSEMBLE))
|
||||
fun taskDokka(project: Project) : TaskResult {
|
||||
val configs = configurationFor(project)
|
||||
val classpath = context.dependencyManager.calculateDependencies(project, context)
|
||||
val buildDir = project.buildDirectory!!
|
||||
val classpathList = classpath.map { it.jarFile.get().absolutePath } + listOf(buildDir)
|
||||
var success = true
|
||||
configs.forEach { config ->
|
||||
if (!config.skip) {
|
||||
val outputDir = buildDir + "/" +
|
||||
if (config.outputDir.isBlank()) "doc" else config.outputDir
|
||||
|
||||
val gen = DokkaGenerator(
|
||||
KobaltDokkaLogger { success = false },
|
||||
classpathList,
|
||||
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")
|
||||
}
|
||||
}
|
||||
return TaskResult(success)
|
||||
}
|
||||
}
|
||||
|
||||
class KobaltDokkaLogger(val onErrorCallback: () -> Unit = {}) : DokkaLogger {
|
||||
override fun error(message: String) {
|
||||
KobaltLogger.logger.error("Dokka", message)
|
||||
onErrorCallback()
|
||||
}
|
||||
|
||||
override fun info(message: String) {
|
||||
KobaltLogger.logger.log(2, message)
|
||||
}
|
||||
|
||||
override fun warn(message: String) {
|
||||
KobaltLogger.logger.warn("Dokka", message)
|
||||
}
|
||||
}
|
||||
|
||||
class SourceLinkMapItem {
|
||||
var dir: String = ""
|
||||
var url: String = ""
|
||||
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)
|
||||
= sourceLinks.add(SourceLinkMapItem().apply { init() })
|
||||
}
|
||||
|
||||
@Directive
|
||||
public fun Project.dokka(init: DokkaConfig.() -> Unit) = let { project ->
|
||||
with(DokkaConfig()) {
|
||||
init()
|
||||
(Kobalt.findPlugin(DokkaPlugin.PLUGIN_NAME) as DokkaPlugin).addConfiguration(project, this)
|
||||
}
|
||||
}
|
||||
|
|
@ -11,10 +11,13 @@ import com.beust.kobalt.maven.DependencyManager
|
|||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import org.jetbrains.dokka.DokkaGenerator
|
||||
import org.jetbrains.dokka.DokkaLogger
|
||||
import org.jetbrains.dokka.SourceLinkDefinition
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -40,8 +43,34 @@ class KotlinPlugin @Inject constructor(
|
|||
override fun accept(project: Project) = project is KotlinProject
|
||||
|
||||
override fun doJavadoc(project: Project, cai: CompilerActionInfo): TaskResult {
|
||||
warn("javadoc task not implemented for Kotlin, call the dokka task instead")
|
||||
return TaskResult()
|
||||
val configs = dokkaConfigurations[project.name]
|
||||
val classpath = context.dependencyManager.calculateDependencies(project, context)
|
||||
val buildDir = project.buildDirectory
|
||||
val classpathList = classpath.map { it.jarFile.get().absolutePath } + listOf(buildDir)
|
||||
var success = true
|
||||
configs.forEach { config ->
|
||||
if (!config.skip) {
|
||||
val outputDir = buildDir + "/" +
|
||||
if (config.outputDir.isBlank()) "doc" else config.outputDir
|
||||
|
||||
val gen = DokkaGenerator(
|
||||
KobaltDokkaLogger { success = false },
|
||||
classpathList,
|
||||
project.sourceDirectories.filter { File(it).exists() }.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")
|
||||
}
|
||||
}
|
||||
return TaskResult(success)
|
||||
}
|
||||
|
||||
@Task(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf(TASK_COMPILE))
|
||||
|
@ -112,6 +141,12 @@ class KotlinPlugin @Inject constructor(
|
|||
lp(project, "Compilation " + if (result.success) "succeeded" else "failed")
|
||||
return result
|
||||
}
|
||||
|
||||
private val dokkaConfigurations = ArrayListMultimap.create<String, DokkaConfig>()
|
||||
|
||||
fun addDokkaConfiguration(project: Project, dokkaConfig: DokkaConfig) {
|
||||
dokkaConfigurations.put(project.name, dokkaConfig)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,3 +170,45 @@ class KotlinCompilerConfig(val project: Project) {
|
|||
fun Project.kotlinCompiler(init: KotlinCompilerConfig.() -> Unit) = let {
|
||||
KotlinCompilerConfig(it).init()
|
||||
}
|
||||
|
||||
class KobaltDokkaLogger(val onErrorCallback: () -> Unit = {}) : DokkaLogger {
|
||||
override fun error(message: String) {
|
||||
KobaltLogger.logger.error("Dokka", message)
|
||||
onErrorCallback()
|
||||
}
|
||||
|
||||
override fun info(message: String) {
|
||||
KobaltLogger.logger.log(2, message)
|
||||
}
|
||||
|
||||
override fun warn(message: String) {
|
||||
KobaltLogger.logger.warn("Dokka", message)
|
||||
}
|
||||
}
|
||||
|
||||
class SourceLinkMapItem {
|
||||
var dir: String = ""
|
||||
var url: String = ""
|
||||
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)
|
||||
= sourceLinks.add(SourceLinkMapItem().apply { init() })
|
||||
}
|
||||
|
||||
@Directive
|
||||
public fun Project.dokka(init: DokkaConfig.() -> Unit) = let { project ->
|
||||
with(DokkaConfig()) {
|
||||
init()
|
||||
(Kobalt.findPlugin(KotlinPlugin.PLUGIN_NAME) as KotlinPlugin).addDokkaConfiguration(project, this)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<class-name>com.beust.kobalt.plugin.packaging.PackagingPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.publish.PublishPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.apt.AptPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.dokka.DokkaPlugin</class-name>
|
||||
</plugins>
|
||||
<classpath-contributors>
|
||||
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue