diff --git a/src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt b/src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt new file mode 100644 index 00000000..df28f9c5 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt @@ -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 +} + diff --git a/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt b/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt index 5772a428..396ae3d4 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt @@ -6,8 +6,10 @@ import com.beust.kobalt.api.Project class ActorUtils { companion object { - fun selectAffinityActor(project: Project, context: KobaltContext, - actors: List) : T? + /** + * Return the plug-in actor with the highest affinity. + */ + fun selectAffinityActor(project: Project, context: KobaltContext, actors: List) : T? = actors.maxBy { it.affinity(project, context) } } } diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 53177cc7..d0e34e90 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -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 } diff --git a/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index b1037c3a..db2d412a 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -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() val classpathInterceptors = arrayListOf() val compilerContributors = arrayListOf() + val docContributors = arrayListOf() // 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) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt index 8811a1d4..180fbe50 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt @@ -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) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index e43b3ae3..ef423608 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -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 diff --git a/src/main/resources/META-INF/kobalt-plugin.xml b/src/main/resources/META-INF/kobalt-plugin.xml index 2c347056..b7d695cd 100644 --- a/src/main/resources/META-INF/kobalt-plugin.xml +++ b/src/main/resources/META-INF/kobalt-plugin.xml @@ -51,4 +51,8 @@ com.beust.kobalt.plugin.java.JavaPlugin com.beust.kobalt.plugin.kotlin.KotlinPlugin + + com.beust.kobalt.plugin.java.JavaPlugin + com.beust.kobalt.plugin.kotlin.KotlinPlugin + \ No newline at end of file