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