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

Introduce IAssemblyContributor.

This commit is contained in:
Cedric Beust 2016-03-04 03:06:28 +04:00
parent 9f2f96e38a
commit 52183bbf0a
3 changed files with 29 additions and 5 deletions

View file

@ -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
}

View file

@ -3,7 +3,6 @@ package com.beust.kobalt.internal
import com.beust.kobalt.api.* import com.beust.kobalt.api.*
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import java.io.File
import java.io.InputStream import java.io.InputStream
import javax.xml.bind.JAXBContext import javax.xml.bind.JAXBContext
import javax.xml.bind.annotation.XmlElement import javax.xml.bind.annotation.XmlElement
@ -74,6 +73,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
val testSourceDirContributors = arrayListOf<ITestSourceDirectoryContributor>() val testSourceDirContributors = arrayListOf<ITestSourceDirectoryContributor>()
val buildConfigFieldContributors = arrayListOf<IBuildConfigFieldContributor>() val buildConfigFieldContributors = arrayListOf<IBuildConfigFieldContributor>()
val taskContributors = arrayListOf<ITaskContributor>() val taskContributors = arrayListOf<ITaskContributor>()
val assemblyContributors = arrayListOf<IAssemblyContributor>()
// Not documented yet // Not documented yet
val buildConfigContributors = arrayListOf<IBuildConfigContributor>() val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
@ -161,6 +161,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
if (this is IMavenIdInterceptor) mavenIdInterceptors.add(this) if (this is IMavenIdInterceptor) mavenIdInterceptors.add(this)
if (this is ITestSourceDirectoryContributor) testSourceDirContributors.add(this) if (this is ITestSourceDirectoryContributor) testSourceDirContributors.add(this)
if (this is IBuildConfigContributor) buildConfigContributors.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) testSourceDirContributors.addAll(pluginInfo.testSourceDirContributors)
mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors) mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors)
buildConfigContributors.addAll(pluginInfo.buildConfigContributors) buildConfigContributors.addAll(pluginInfo.buildConfigContributors)
assemblyContributors.addAll(pluginInfo.assemblyContributors)
} }
} }

View file

@ -25,7 +25,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
val executors: KobaltExecutors, val jarGenerator: JarGenerator, val warGenerator: WarGenerator, val executors: KobaltExecutors, val jarGenerator: JarGenerator, val warGenerator: WarGenerator,
val zipGenerator: ZipGenerator, val taskContributor: TaskContributor, val zipGenerator: ZipGenerator, val taskContributor: TaskContributor,
val pomFactory: PomGenerator.IFactory, val configActor: ConfigActor<InstallConfig>) val pomFactory: PomGenerator.IFactory, val configActor: ConfigActor<InstallConfig>)
: BasePlugin(), IConfigActor<InstallConfig> by configActor, ITaskContributor { : BasePlugin(), IConfigActor<InstallConfig> by configActor, ITaskContributor, IAssemblyContributor {
companion object { companion object {
const val PLUGIN_NAME = "Packaging" const val PLUGIN_NAME = "Packaging"
@ -140,9 +140,8 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
runTask = { doTaskAssemble(project) }) runTask = { doTaskAssemble(project) })
} }
@Task(name = TASK_ASSEMBLE, description = "Package the artifacts", // IAssemblyContributor
runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE)) override fun assemble(project: Project, context: KobaltContext) : TaskResult {
fun doTaskAssemble(project: Project) : TaskResult {
try { try {
project.projectProperties.put(PACKAGES, packages) project.projectProperties.put(PACKAGES, packages)
packages.filter { it.project.name == project.name }.forEach { pkg -> 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) { fun addPackage(p: PackageConfig) {
packages.add(p) packages.add(p)
} }