1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

IIncrementalTaskContributor.

This commit is contained in:
Cedric Beust 2016-07-04 11:09:13 -07:00
parent 40d251e08d
commit 182ee52be2
5 changed files with 57 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package com.beust.kobalt
import com.beust.kobalt.api.* import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.IncrementalTask import com.beust.kobalt.api.annotation.IncrementalTask
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.IncrementalManager
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.TaskManager import com.beust.kobalt.internal.TaskManager
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
@ -28,6 +29,7 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
val localRepo: LocalRepo, val localRepo: LocalRepo,
val executors: KobaltExecutors, val executors: KobaltExecutors,
val pluginInfo: PluginInfo, val pluginInfo: PluginInfo,
val incrementalManagerFactory: IncrementalManager.IFactory,
val taskManager: TaskManager) { val taskManager: TaskManager) {
companion object { companion object {
@ -84,6 +86,23 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
} }
} }
// ... and from the incremental task contributors
val incrementalManager = incrementalManagerFactory.create()
context.pluginInfo.incrementalTaskContributors.forEach {
projects.forEach { project ->
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 // Now that we have collected all static and dynamic tasks, turn them all into plug-in tasks
taskManager.computePluginTasks(projects) taskManager.computePluginTasks(projects)
} }

View file

@ -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<IncrementalDynamicTask>
}
class IncrementalDynamicTask(val context: KobaltContext,
val plugin: IPlugin,
val name: String,
val doc: String,
val group: String,
val project: Project,
val dependsOn: List<String> = listOf<String>(),
val reverseDependsOn: List<String> = listOf<String>(),
val runBefore: List<String> = listOf<String>(),
val runAfter: List<String> = listOf<String>(),
val alwaysRunAfter: List<String> = listOf<String>(),
val incrementalClosure: (Project) -> IncrementalTaskInfo) {
override fun toString() = "[IncrementalDynamicTask $name dependsOn=$dependsOn reverseDependsOn=$reverseDependsOn]"
}

View file

@ -3,6 +3,7 @@ package com.beust.kobalt.api
import com.beust.kobalt.Args import com.beust.kobalt.Args
import com.beust.kobalt.Plugins import com.beust.kobalt.Plugins
import com.beust.kobalt.Variant import com.beust.kobalt.Variant
import com.beust.kobalt.internal.IncrementalManager
import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
@ -35,6 +36,7 @@ class KobaltContext(val args: Args) {
lateinit var dependencyManager: DependencyManager lateinit var dependencyManager: DependencyManager
lateinit var executors: KobaltExecutors lateinit var executors: KobaltExecutors
lateinit var settings: KobaltSettings lateinit var settings: KobaltSettings
lateinit var incrementalManager: IncrementalManager
} }
class InternalContext { class InternalContext {

View file

@ -94,6 +94,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
val buildConfigContributors = arrayListOf<IBuildConfigContributor>() val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>() val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
val jvmFlagContributors = arrayListOf<IJvmFlagContributor>() val jvmFlagContributors = arrayListOf<IJvmFlagContributor>()
val incrementalTaskContributors = arrayListOf<IIncrementalTaskContributor>()
// Note: intentionally repeating them here even though they are defined by our base class so // 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 // 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 ITestJvmFlagContributor) testJvmFlagContributors.add(this)
if (this is ITestJvmFlagInterceptor) testJvmFlagInterceptors.add(this) if (this is ITestJvmFlagInterceptor) testJvmFlagInterceptors.add(this)
if (this is IJvmFlagContributor) jvmFlagContributors.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, runnerContributors, testRunnerContributors, classpathInterceptors,
compilerContributors, docContributors, sourceDirContributors, compilerContributors, docContributors, sourceDirContributors,
testSourceDirContributors, buildConfigFieldContributors, testSourceDirContributors, buildConfigFieldContributors,
taskContributors, assemblyContributors, taskContributors, incrementalTaskContributors, assemblyContributors,
incrementalAssemblyContributors, testJvmFlagInterceptors, incrementalAssemblyContributors, testJvmFlagInterceptors,
jvmFlagContributors jvmFlagContributors
).forEach { ).forEach {
@ -252,6 +254,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
sourceDirContributors.addAll(pluginInfo.sourceDirContributors) sourceDirContributors.addAll(pluginInfo.sourceDirContributors)
buildConfigFieldContributors.addAll(pluginInfo.buildConfigFieldContributors) buildConfigFieldContributors.addAll(pluginInfo.buildConfigFieldContributors)
taskContributors.addAll(pluginInfo.taskContributors) taskContributors.addAll(pluginInfo.taskContributors)
incrementalTaskContributors.addAll(pluginInfo.incrementalTaskContributors)
testSourceDirContributors.addAll(pluginInfo.testSourceDirContributors) testSourceDirContributors.addAll(pluginInfo.testSourceDirContributors)
mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors) mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors)
buildConfigContributors.addAll(pluginInfo.buildConfigContributors) buildConfigContributors.addAll(pluginInfo.buildConfigContributors)

View file

@ -8,6 +8,7 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.PluginProperties import com.beust.kobalt.api.PluginProperties
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.internal.IncrementalManager
import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.build.BuildFile 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<BuildFile>, public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFiles: List<BuildFile>,
@Assisted val pluginInfo: PluginInfo, val files: KFiles, val plugins: Plugins, @Assisted val pluginInfo: PluginInfo, val files: KFiles, val plugins: Plugins,
val dependencyManager: DependencyManager, val pluginProperties: PluginProperties, 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 { interface IFactory {
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler
@ -50,6 +52,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
context.dependencyManager = dependencyManager context.dependencyManager = dependencyManager
context.executors = executors context.executors = executors
context.settings = settings context.settings = settings
context.incrementalManager = incrementalManagerFactory.create()
Kobalt.context = context Kobalt.context = context
// //