diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IAssemblyContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IAssemblyContributor.kt new file mode 100644 index 00000000..64c1d19b --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IAssemblyContributor.kt @@ -0,0 +1,10 @@ +package com.beust.kobalt.api + +import com.beust.kobalt.TaskResult + +/** + * Plug-ins that will be invoked during the "assemble" task. + */ +interface IAssemblyContributor { + fun assemble(project: Project, context: KobaltContext) : TaskResult +} 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 34c00333..b114af02 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 @@ -3,7 +3,6 @@ package com.beust.kobalt.internal import com.beust.kobalt.api.* import com.beust.kobalt.misc.log import java.io.ByteArrayInputStream -import java.io.File import java.io.InputStream import javax.xml.bind.JAXBContext import javax.xml.bind.annotation.XmlElement @@ -74,6 +73,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { val testSourceDirContributors = arrayListOf() val buildConfigFieldContributors = arrayListOf() val taskContributors = arrayListOf() + val assemblyContributors = arrayListOf() // Not documented yet val buildConfigContributors = arrayListOf() @@ -161,6 +161,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { if (this is IMavenIdInterceptor) mavenIdInterceptors.add(this) if (this is ITestSourceDirectoryContributor) testSourceDirContributors.add(this) if (this is IBuildConfigContributor) buildConfigContributors.add(this) + if (this is IAssemblyContributor) assemblyContributors.add(this) } } } @@ -191,6 +192,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { testSourceDirContributors.addAll(pluginInfo.testSourceDirContributors) mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors) buildConfigContributors.addAll(pluginInfo.buildConfigContributors) + assemblyContributors.addAll(pluginInfo.assemblyContributors) } } 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 4f1c582c..10d6cc09 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -25,7 +25,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana 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 { + : BasePlugin(), IConfigActor by configActor, ITaskContributor, IAssemblyContributor { companion object { const val PLUGIN_NAME = "Packaging" @@ -140,9 +140,8 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana runTask = { doTaskAssemble(project) }) } - @Task(name = TASK_ASSEMBLE, description = "Package the artifacts", - runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE)) - fun doTaskAssemble(project: Project) : TaskResult { + // IAssemblyContributor + override fun assemble(project: Project, context: KobaltContext) : TaskResult { try { project.projectProperties.put(PACKAGES, packages) packages.filter { it.project.name == project.name }.forEach { pkg -> @@ -159,6 +158,19 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } } + @Task(name = TASK_ASSEMBLE, description = "Package the artifacts", + runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE)) + fun doTaskAssemble(project: Project) : TaskResult { + context.pluginInfo.assemblyContributors.forEach { + val thisResult = it.assemble(project, context) + if (! thisResult.success) { + // Abort at the first failure + return thisResult + } + } + return TaskResult() + } + fun addPackage(p: PackageConfig) { packages.add(p) }