diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalAssemblyContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalAssemblyContributor.kt new file mode 100644 index 00000000..a11ab639 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IIncrementalAssemblyContributor.kt @@ -0,0 +1,12 @@ +package com.beust.kobalt.api + +import com.beust.kobalt.IncrementalTaskInfo + +/** + * Plug-ins that will be invoked during the "assemble" task and wish to return an incremental task instead + * of a regular one. + */ +interface IIncrementalAssemblyContributor { + fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo +} + 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 b4f8ff82..192fd8ed 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 @@ -74,6 +74,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { val buildConfigFieldContributors = arrayListOf() val taskContributors = arrayListOf() val assemblyContributors = arrayListOf() + val incrementalAssemblyContributors = arrayListOf() // Not documented yet val buildConfigContributors = arrayListOf() @@ -160,6 +161,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { if (this is ITestSourceDirectoryContributor) testSourceDirContributors.add(this) if (this is IBuildConfigContributor) buildConfigContributors.add(this) if (this is IAssemblyContributor) assemblyContributors.add(this) + if (this is IIncrementalAssemblyContributor) incrementalAssemblyContributors.add(this) // Not documented yet } @@ -193,6 +195,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors) buildConfigContributors.addAll(pluginInfo.buildConfigContributors) assemblyContributors.addAll(pluginInfo.assemblyContributors) + incrementalAssemblyContributors.addAll(pluginInfo.incrementalAssemblyContributors) } } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index c5d90eeb..3ed25496 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -9,6 +9,7 @@ import com.beust.kobalt.api.annotation.ExportedProjectProperty import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.archive.* import com.beust.kobalt.glob +import com.beust.kobalt.internal.IncrementalManager import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.PomGenerator @@ -21,10 +22,11 @@ import javax.inject.Singleton @Singleton class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager, + val incrementalManager: IncrementalManager, val executors: KobaltExecutors, val jarGenerator: JarGenerator, val warGenerator: WarGenerator, val zipGenerator: ZipGenerator, val taskContributor: TaskContributor, val pomFactory: PomGenerator.IFactory, val configActor: ConfigActor) - : BasePlugin(), IConfigActor by configActor, ITaskContributor, IAssemblyContributor { + : BasePlugin(), ITaskContributor, IAssemblyContributor, IConfigActor by configActor { companion object { const val PLUGIN_NAME = "Packaging" @@ -69,9 +71,39 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } } + private fun doAssemble(project: Project, context: KobaltContext) : TaskResult { + try { + project.projectProperties.put(PACKAGES, packages) + packages.filter { it.project.name == project.name }.forEach { pkg -> + pkg.jars.forEach { jarGenerator.generateJar(pkg.project, context, it) } + pkg.wars.forEach { warGenerator.generateWar(pkg.project, context, it) } + pkg.zips.forEach { zipGenerator.generateZip(pkg.project, context, it) } + if (pkg.generatePom) { + pomFactory.create(project).generate() + } + } + return TaskResult() + } catch(ex: Exception) { + throw KobaltException(ex) + } + } + @Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE)) fun doTaskAssemble(project: Project) : TaskResult { + // Incremental assembly contributors + context.pluginInfo.incrementalAssemblyContributors.forEach { + val taskInfo = it.assemble(project, context) + val closure = incrementalManager.toIncrementalTaskClosure(TASK_ASSEMBLE, { p: Project -> taskInfo }, + context.variant) + val thisResult = closure.invoke(project) + if (! thisResult.success) { + // Abort at the first failure + return thisResult + } + } + + // Regular assembly contributors context.pluginInfo.assemblyContributors.forEach { val thisResult = it.assemble(project, context) if (! thisResult.success) {