mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Introducing doc contributors.
This commit is contained in:
parent
d90e2550ea
commit
ad72434b39
7 changed files with 44 additions and 16 deletions
8
src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt
Normal file
8
src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt
Normal file
|
@ -0,0 +1,8 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.TaskResult
|
||||
|
||||
interface IDocContributor : IAffinity {
|
||||
fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult
|
||||
}
|
||||
|
|
@ -6,8 +6,10 @@ import com.beust.kobalt.api.Project
|
|||
|
||||
class ActorUtils {
|
||||
companion object {
|
||||
fun <T : IAffinity> selectAffinityActor(project: Project, context: KobaltContext,
|
||||
actors: List<T>) : T?
|
||||
/**
|
||||
* Return the plug-in actor with the highest affinity.
|
||||
*/
|
||||
fun <T : IAffinity> selectAffinityActor(project: Project, context: KobaltContext, actors: List<T>) : T?
|
||||
= actors.maxBy { it.affinity(project, context) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,8 +144,16 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@Task(name = JavaPlugin.TASK_JAVADOC, description = "Run Javadoc")
|
||||
fun taskJavadoc(project: Project) = doJavadoc(project, createCompilerActionInfo(project, context))
|
||||
@Task(name = "doc", description = "Generate the documentation for the project")
|
||||
fun taskJavadoc(project: Project) : TaskResult {
|
||||
val docGenerator = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.docContributors)
|
||||
if (docGenerator != null) {
|
||||
return docGenerator.generateDoc(project, context, createCompilerActionInfo(project, context))
|
||||
} else {
|
||||
warn("Couldn't find any doc contributor for project ${project.name}")
|
||||
return TaskResult()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCompilerActionInfo(project: Project, context: KobaltContext) : CompilerActionInfo {
|
||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
||||
|
@ -172,7 +180,5 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
})
|
||||
return result
|
||||
}
|
||||
|
||||
abstract fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,9 @@ class KobaltPluginXml {
|
|||
|
||||
@XmlElement(name = "compiler-contributors") @JvmField
|
||||
var compilerContributors: ClassNameXml? = null
|
||||
|
||||
@XmlElement(name = "doc-contributors") @JvmField
|
||||
var docContributors: ClassNameXml? = null
|
||||
}
|
||||
|
||||
class ContributorXml {
|
||||
|
@ -104,6 +107,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
val testRunnerContributors = arrayListOf<IRunnerContributor>()
|
||||
val classpathInterceptors = arrayListOf<IClasspathInterceptor>()
|
||||
val compilerContributors = arrayListOf<ICompilerContributor>()
|
||||
val docContributors = arrayListOf<IDocContributor>()
|
||||
|
||||
// Future contributors:
|
||||
// source files
|
||||
|
@ -189,6 +193,9 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
xml.compilerContributors?.className?.forEach {
|
||||
compilerContributors.add(factory.instanceOf(forName(it)) as ICompilerContributor)
|
||||
}
|
||||
xml.docContributors?.className?.forEach {
|
||||
docContributors.add(factory.instanceOf(forName(it)) as IDocContributor)
|
||||
}
|
||||
}
|
||||
|
||||
fun addPluginInfo(pluginInfo: PluginInfo) {
|
||||
|
|
|
@ -28,11 +28,10 @@ class JavaPlugin @Inject constructor(
|
|||
val javaCompiler: JavaCompiler,
|
||||
override val jvmCompiler: JvmCompiler)
|
||||
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors, jvmCompiler),
|
||||
ICompilerContributor {
|
||||
ICompilerContributor, IDocContributor {
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Java"
|
||||
const val TASK_COMPILE = "compile"
|
||||
const val TASK_JAVADOC = "javadoc"
|
||||
const val TASK_COMPILE_TEST = "compileTest"
|
||||
}
|
||||
|
||||
|
@ -51,10 +50,15 @@ class JavaPlugin @Inject constructor(
|
|||
return dirs
|
||||
}
|
||||
|
||||
override fun doJavadoc(project: Project, cai: CompilerActionInfo) : TaskResult {
|
||||
// IDocContributor
|
||||
|
||||
override fun affinity(project: Project, context: KobaltContext) =
|
||||
if (project.sourceSuffix == ".java") 1 else 0
|
||||
|
||||
override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
if (cai.sourceFiles.size > 0) {
|
||||
javaCompiler.javadoc(project, context, cai.copy(compilerArgs = compilerArgsFor(project)))
|
||||
if (info.sourceFiles.size > 0) {
|
||||
javaCompiler.javadoc(project, context, info.copy(compilerArgs = compilerArgsFor(project)))
|
||||
} else {
|
||||
warn("Couldn't find any source files to run Javadoc on")
|
||||
TaskResult()
|
||||
|
@ -81,9 +85,6 @@ class JavaPlugin @Inject constructor(
|
|||
|
||||
// ICompilerContributor
|
||||
|
||||
override fun affinity(project: Project, context: KobaltContext) =
|
||||
if (project.sourceSuffix == ".java") 1 else 0
|
||||
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
if (info.sourceFiles.size > 0) {
|
||||
|
|
|
@ -30,7 +30,7 @@ class KotlinPlugin @Inject constructor(
|
|||
override val executors: KobaltExecutors,
|
||||
override val jvmCompiler: JvmCompiler)
|
||||
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors, jvmCompiler),
|
||||
IClasspathContributor, ICompilerContributor {
|
||||
IClasspathContributor, ICompilerContributor, IDocContributor {
|
||||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Kotlin"
|
||||
|
@ -42,7 +42,7 @@ class KotlinPlugin @Inject constructor(
|
|||
|
||||
override fun accept(project: Project) = project is KotlinProject
|
||||
|
||||
override fun doJavadoc(project: Project, cai: CompilerActionInfo): TaskResult {
|
||||
override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val configs = dokkaConfigurations[project.name]
|
||||
val classpath = context.dependencyManager.calculateDependencies(project, context)
|
||||
val buildDir = project.buildDirectory
|
||||
|
|
|
@ -51,4 +51,8 @@
|
|||
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||
</compiler-contributors>
|
||||
<doc-contributors>
|
||||
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||
</doc-contributors>
|
||||
</kobalt-plugin>
|
Loading…
Add table
Add a link
Reference in a new issue