mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Refactor to enable multiple test{} configs.
This commit is contained in:
parent
596c6859d9
commit
32b0d12770
10 changed files with 57 additions and 39 deletions
|
@ -0,0 +1,18 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Actors that have one config object per project can use this helper class.
|
||||
*/
|
||||
interface IConfigActor<T> {
|
||||
val configurations : HashMap<String, T>
|
||||
|
||||
fun configurationFor(project: Project?) = if (project != null) configurations[project.name] else null
|
||||
|
||||
fun addConfiguration(project: Project, configuration: T) = configurations.put(project.name, configuration)
|
||||
}
|
||||
|
||||
open class ConfigActor<T>: IConfigActor<T> {
|
||||
override val configurations : HashMap<String, T> = hashMapOf()
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
/**
|
||||
* A plug-in that has some per-project configuration in the build file.
|
||||
*/
|
||||
abstract public class ConfigPlugin<T> : BasePlugin() {
|
||||
private val configurations = hashMapOf<String, T>()
|
||||
|
||||
fun configurationFor(project: Project?) = if (project != null) configurations[project.name] else null
|
||||
|
||||
fun addConfiguration(project: Project, configuration: T) = configurations.put(project.name, configuration)
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.common.collect.ListMultimap
|
||||
|
||||
/**
|
||||
* Actors that have more than config object per project can use this helper class.
|
||||
*/
|
||||
interface IConfigsActor<T> {
|
||||
val configurations : ListMultimap<String, T>
|
||||
|
||||
fun configurationFor(project: Project?) = if (project != null) configurations[project.name] else null
|
||||
|
||||
fun addConfiguration(project: Project, configuration: T) = configurations.put(project.name, configuration)
|
||||
}
|
||||
|
||||
open class ConfigsActor<T>: IConfigsActor<T> {
|
||||
override val configurations = ArrayListMultimap.create<String, T>()
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
|
||||
/**
|
||||
* A plug-in that has some per-project list of configurations in the build file.
|
||||
*/
|
||||
abstract public class ConfigsPlugin<T> : BasePlugin() {
|
||||
private val configurations = ArrayListMultimap.create<String, T>()
|
||||
|
||||
fun configurationFor(project: Project) = configurations[project.name]
|
||||
|
||||
fun addConfiguration(project: Project, configuration: T) = configurations.put(project.name, configuration)
|
||||
}
|
|
@ -1,12 +1,17 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.api.ConfigPlugin
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.api.ConfigActor
|
||||
import com.beust.kobalt.api.ICompilerFlagContributor
|
||||
import com.beust.kobalt.api.IConfigActor
|
||||
|
||||
/**
|
||||
* Base class for JVM language plug-ins.
|
||||
*/
|
||||
abstract class BaseJvmPlugin<T> : ConfigPlugin<T>(), ICompilerFlagContributor {
|
||||
abstract class BaseJvmPlugin<T>(open val configActor: ConfigActor<T>) :
|
||||
BasePlugin(),
|
||||
IConfigActor<T> by configActor,
|
||||
ICompilerFlagContributor {
|
||||
companion object {
|
||||
// Run before other flag contributors
|
||||
val FLAG_CONTRIBUTOR_PRIORITY = ICompilerFlagContributor.DEFAULT_FLAG_PRIORITY - 10
|
||||
|
|
|
@ -34,9 +34,10 @@ fun Project.application(init: ApplicationConfig.() -> Unit) {
|
|||
}
|
||||
|
||||
@Singleton
|
||||
class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
||||
class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<ApplicationConfig>,
|
||||
val executors: KobaltExecutors,
|
||||
val dependencyManager: DependencyManager, val taskContributor : TaskContributor)
|
||||
: ConfigPlugin<ApplicationConfig>(), IRunnerContributor, ITaskContributor {
|
||||
: BasePlugin(), IRunnerContributor, ITaskContributor, IConfigActor<ApplicationConfig> by configActor {
|
||||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Application"
|
||||
|
|
|
@ -18,8 +18,8 @@ import javax.inject.Singleton
|
|||
* (outputDir, etc...).
|
||||
*/
|
||||
@Singleton
|
||||
public class AptPlugin @Inject constructor(val depFactory: DepFactory)
|
||||
: ConfigPlugin<AptConfig>(), ICompilerFlagContributor, ISourceDirectoryContributor {
|
||||
class AptPlugin @Inject constructor(val depFactory: DepFactory, val configActor: ConfigActor<AptConfig>)
|
||||
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, IConfigActor<AptConfig> by configActor {
|
||||
|
||||
// ISourceDirectoryContributor
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ import javax.inject.Inject
|
|||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||
: BaseJvmPlugin<JavaConfig>(), IDocContributor, ICompilerContributor, ITestSourceDirectoryContributor,
|
||||
IBuildConfigContributor {
|
||||
class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler, override val configActor: ConfigActor<JavaConfig>)
|
||||
: BaseJvmPlugin<JavaConfig>(configActor), IDocContributor, ICompilerContributor,
|
||||
ITestSourceDirectoryContributor, IBuildConfigContributor {
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Java"
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@ import javax.inject.Inject
|
|||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||
: BaseJvmPlugin<KotlinConfig>(), IDocContributor, IClasspathContributor, ICompilerContributor,
|
||||
class KotlinPlugin @Inject constructor(val executors: KobaltExecutors,
|
||||
override val configActor: ConfigActor<KotlinConfig>)
|
||||
: BaseJvmPlugin<KotlinConfig>(configActor), IDocContributor, IClasspathContributor, ICompilerContributor,
|
||||
IBuildConfigContributor {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -24,8 +24,8 @@ import javax.inject.Singleton
|
|||
class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager,
|
||||
val executors: KobaltExecutors, val jarGenerator: JarGenerator, val warGenerator: WarGenerator,
|
||||
val zipGenerator: ZipGenerator, val taskContributor: TaskContributor,
|
||||
val pomFactory: PomGenerator.IFactory)
|
||||
: ConfigPlugin<InstallConfig>(), ITaskContributor {
|
||||
val pomFactory: PomGenerator.IFactory, val configActor: ConfigActor<InstallConfig>)
|
||||
: BasePlugin(), IConfigActor<InstallConfig> by configActor, ITaskContributor {
|
||||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Packaging"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue