From 182ee52be2969a51181edbcab3a865ca89b807ad Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 4 Jul 2016 11:09:13 -0700 Subject: [PATCH] IIncrementalTaskContributor. --- .../main/kotlin/com/beust/kobalt/Plugins.kt | 19 +++++++++++++ .../kobalt/api/IIncrementalTaskContributor.kt | 28 +++++++++++++++++++ .../com/beust/kobalt/api/KobaltContext.kt | 2 ++ .../beust/kobalt/internal/KobaltPluginXml.kt | 5 +++- .../com/beust/kobalt/app/BuildFileCompiler.kt | 5 +++- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalTaskContributor.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt index 29e902e1..e794ae8d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -3,6 +3,7 @@ package com.beust.kobalt import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.IncrementalTask import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.internal.IncrementalManager import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.TaskManager import com.beust.kobalt.maven.DependencyManager @@ -28,6 +29,7 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider + it.incrementalTasksFor(project, context).forEach { + // Convert the closure (Project) -> IncrementalTaskInfo to (Project) -> TaskResult + // and create a DynamicTask out of it + val closure = + incrementalManager.toIncrementalTaskClosure(it.name, it.incrementalClosure, Variant()) + val task = DynamicTask(it.plugin, it.name, it.doc, it.group, it.project, it.dependsOn, + it.reverseDependsOn, it.runBefore, it.runAfter, it.alwaysRunAfter, + closure) + taskManager.dynamicTasks.add(task) + } + } + } + // Now that we have collected all static and dynamic tasks, turn them all into plug-in tasks taskManager.computePluginTasks(projects) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalTaskContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalTaskContributor.kt new file mode 100644 index 00000000..1decac22 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalTaskContributor.kt @@ -0,0 +1,28 @@ +package com.beust.kobalt.api + +import com.beust.kobalt.IncrementalTaskInfo + +/** + * Plug-ins that need to add incremental dynamic tasks (tasks that are not methods annotated with @Task) need + * to implement this interface. + */ +interface IIncrementalTaskContributor : IContributor { + fun incrementalTasksFor(project: Project, context: KobaltContext) : List +} + +class IncrementalDynamicTask(val context: KobaltContext, + val plugin: IPlugin, + val name: String, + val doc: String, + val group: String, + val project: Project, + val dependsOn: List = listOf(), + val reverseDependsOn: List = listOf(), + val runBefore: List = listOf(), + val runAfter: List = listOf(), + val alwaysRunAfter: List = listOf(), + val incrementalClosure: (Project) -> IncrementalTaskInfo) { + override fun toString() = "[IncrementalDynamicTask $name dependsOn=$dependsOn reverseDependsOn=$reverseDependsOn]" +} + + diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt index 4fd75cc8..b55e03fb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt @@ -3,6 +3,7 @@ package com.beust.kobalt.api import com.beust.kobalt.Args import com.beust.kobalt.Plugins import com.beust.kobalt.Variant +import com.beust.kobalt.internal.IncrementalManager import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.maven.DependencyManager @@ -35,6 +36,7 @@ class KobaltContext(val args: Args) { lateinit var dependencyManager: DependencyManager lateinit var executors: KobaltExecutors lateinit var settings: KobaltSettings + lateinit var incrementalManager: IncrementalManager } class InternalContext { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index 1156e93e..03f4f620 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -94,6 +94,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, val buildConfigContributors = arrayListOf() val mavenIdInterceptors = arrayListOf() val jvmFlagContributors = arrayListOf() + val incrementalTaskContributors = arrayListOf() // Note: intentionally repeating them here even though they are defined by our base class so // that this class always contains the full list of contributors and interceptors @@ -208,6 +209,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, if (this is ITestJvmFlagContributor) testJvmFlagContributors.add(this) if (this is ITestJvmFlagInterceptor) testJvmFlagInterceptors.add(this) if (this is IJvmFlagContributor) jvmFlagContributors.add(this) + if (this is IIncrementalTaskContributor) incrementalTaskContributors.add(this) } } } @@ -219,7 +221,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, runnerContributors, testRunnerContributors, classpathInterceptors, compilerContributors, docContributors, sourceDirContributors, testSourceDirContributors, buildConfigFieldContributors, - taskContributors, assemblyContributors, + taskContributors, incrementalTaskContributors, assemblyContributors, incrementalAssemblyContributors, testJvmFlagInterceptors, jvmFlagContributors ).forEach { @@ -252,6 +254,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, sourceDirContributors.addAll(pluginInfo.sourceDirContributors) buildConfigFieldContributors.addAll(pluginInfo.buildConfigFieldContributors) taskContributors.addAll(pluginInfo.taskContributors) + incrementalTaskContributors.addAll(pluginInfo.incrementalTaskContributors) testSourceDirContributors.addAll(pluginInfo.testSourceDirContributors) mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors) buildConfigContributors.addAll(pluginInfo.buildConfigContributors) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 7bd3ab41..b093c0c1 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -8,6 +8,7 @@ import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.PluginProperties import com.beust.kobalt.api.Project +import com.beust.kobalt.internal.IncrementalManager import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile @@ -31,7 +32,8 @@ import javax.inject.Inject public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFiles: List, @Assisted val pluginInfo: PluginInfo, val files: KFiles, val plugins: Plugins, val dependencyManager: DependencyManager, val pluginProperties: PluginProperties, - val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings) { + val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings, + val incrementalManagerFactory: IncrementalManager.IFactory) { interface IFactory { fun create(@Assisted("buildFiles") buildFiles: List, pluginInfo: PluginInfo) : BuildFileCompiler @@ -50,6 +52,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b context.dependencyManager = dependencyManager context.executors = executors context.settings = settings + context.incrementalManager = incrementalManagerFactory.create() Kobalt.context = context //