mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Extract affinity selection.
This commit is contained in:
parent
87975284d9
commit
569eaf9fa8
3 changed files with 19 additions and 6 deletions
13
src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt
Normal file
13
src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt
Normal file
|
@ -0,0 +1,13 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.api.IAffinity
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
|
||||
class ActorUtils {
|
||||
companion object {
|
||||
fun <T : IAffinity> selectAffinityActor(project: Project, context: KobaltContext,
|
||||
actors: List<T>) : T?
|
||||
= actors.maxBy { it.affinity(project, context) }
|
||||
}
|
||||
}
|
|
@ -59,7 +59,8 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
fun taskTest(project: Project) : TaskResult {
|
||||
lp(project, "Running tests")
|
||||
|
||||
val runContributor = context.pluginInfo.testRunnerContributors.maxBy { it.affinity(project, context)}
|
||||
val runContributor = ActorUtils.selectAffinityActor(project, context,
|
||||
context.pluginInfo.testRunnerContributors)
|
||||
if (runContributor != null && runContributor.affinity(project, context) > 0) {
|
||||
return runContributor.run(project, context, dependencyManager.testDependencies(project, context,
|
||||
projects()))
|
||||
|
@ -137,7 +138,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
fun taskCompile(project: Project) : TaskResult {
|
||||
context.variant.maybeGenerateBuildConfig(project, context)
|
||||
val info = createCompilerActionInfo(project, context)
|
||||
val compiler = selectAffinityActor(project, context.pluginInfo.compilerContributors)
|
||||
val compiler = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.compilerContributors)
|
||||
if (compiler != null) {
|
||||
return compiler.compile(project, context, info)
|
||||
} else {
|
||||
|
@ -145,9 +146,6 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun <T : IAffinity> selectAffinityActor(project: Project, actors: List<T>) : T? =
|
||||
actors.maxBy { it.affinity(project, context) }
|
||||
|
||||
@Task(name = JavaPlugin.TASK_JAVADOC, description = "Run Javadoc")
|
||||
fun taskJavadoc(project: Project) = doJavadoc(project, createCompilerActionInfo(project, context))
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.beust.kobalt.*
|
|||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.internal.ActorUtils
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.dependency.IClasspathDependency
|
||||
|
@ -49,7 +50,8 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
|||
|
||||
@Task(name = "run", description = "Run the main class", runAfter = arrayOf("install"))
|
||||
fun taskRun(project: Project): TaskResult {
|
||||
val runContributor = context.pluginInfo.runnerContributors.maxBy { it.affinity(project, context)}
|
||||
val runContributor = ActorUtils.selectAffinityActor(project, context,
|
||||
context.pluginInfo.runnerContributors)
|
||||
if (runContributor != null && runContributor.affinity(project, context) > 0) {
|
||||
return runContributor.run(project, context, dependencyManager.dependencies(project, context, projects()))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue