From fd5fb983e267972dc9df329d6c6ad59c87222c4b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 29 Nov 2015 08:56:33 -0800 Subject: [PATCH] Extract IAffinity in its own interface. --- .../com/beust/kobalt/api/IRunnerContributor.kt | 18 +----------------- .../com/beust/kobalt/internal/JUnitRunner.kt | 2 +- .../beust/kobalt/internal/JvmCompilerPlugin.kt | 4 ++-- .../com/beust/kobalt/internal/TestNgRunner.kt | 2 +- .../kobalt/plugin/android/AndroidPlugin.kt | 2 +- .../plugin/application/ApplicationPlugin.kt | 6 +++--- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt b/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt index bafdefa3..39276deb 100644 --- a/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt +++ b/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt @@ -6,25 +6,9 @@ import com.beust.kobalt.maven.dependency.IClasspathDependency /** * Plugins that can run a project (task "run" or "test") should implement this interface. */ -interface IRunnerContributor : IContributor { - companion object { - /** - * The recommended default affinity if your plug-in can run this project. Use a higher - * number if you expect to compete against other runners and you'd like to win over them. - */ - const val DEFAULT_POSITIVE_AFFINITY = 100 - } - - /** - * @return an integer indicating your affinity for running the current project. The runner with - * the highest affinity is selected to run it. - */ - fun runAffinity(project: Project, context: KobaltContext) : Int - +interface IRunnerContributor : IContributor, IAffinity { /** * Run the project. */ fun run(project: Project, context: KobaltContext, classpath: List) : TaskResult } - - diff --git a/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt index 1f824ef0..7d17246e 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt @@ -9,7 +9,7 @@ public class JUnitRunner() : GenericTestRunner() { override val mainClass = "org.junit.runner.JUnitCore" - override fun runAffinity(project: Project, context: KobaltContext) = + override fun affinity(project: Project, context: KobaltContext) = if (project.testDependencies.any { it.id.contains("junit")}) IRunnerContributor.DEFAULT_POSITIVE_AFFINITY else 0 diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index a569cc2a..43cbf7de 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -61,8 +61,8 @@ abstract class JvmCompilerPlugin @Inject constructor( fun taskTest(project: Project) : TaskResult { lp(project, "Running tests") - val runContributor = context.pluginInfo.testRunnerContributors.maxBy { it.runAffinity(project, context)} - if (runContributor != null && runContributor.runAffinity(project, context) > 0) { + val runContributor = context.pluginInfo.testRunnerContributors.maxBy { it.affinity(project, context)} + if (runContributor != null && runContributor.affinity(project, context) > 0) { return runContributor.run(project, context, dependencyManager.testDependencies(project, context, projects())) } else { diff --git a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 5368d8e4..0b683f98 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -11,7 +11,7 @@ public class TestNgRunner() : GenericTestRunner() { override val mainClass = "org.testng.TestNG" - override fun runAffinity(project: Project, context: KobaltContext) = + override fun affinity(project: Project, context: KobaltContext) = if (project.testDependencies.any { it.id.contains("testng")}) IRunnerContributor.DEFAULT_POSITIVE_AFFINITY else 0 diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt index 5ed46146..c30f9be6 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt @@ -390,7 +390,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v } // IRunContributor - override fun runAffinity(project: Project, context: KobaltContext): Int { + override fun affinity(project: Project, context: KobaltContext): Int { val manifest = AndroidFiles.manifest(project, context) return if (File(manifest).exists()) IRunnerContributor.DEFAULT_POSITIVE_AFFINITY else 0 } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index e1eac71b..6c9e71c7 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -49,8 +49,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.runAffinity(project, context)} - if (runContributor != null && runContributor.runAffinity(project, context) > 0) { + val runContributor = context.pluginInfo.runnerContributors.maxBy { it.affinity(project, context)} + if (runContributor != null && runContributor.affinity(project, context) > 0) { return runContributor.run(project, context, dependencyManager.dependencies(project, context, projects())) } else { warn("Couldn't find a runner for project ${project.name}") @@ -73,7 +73,7 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors, // IRunContributor - override fun runAffinity(project: Project, context: KobaltContext): Int { + override fun affinity(project: Project, context: KobaltContext): Int { return if (configurationFor(project) != null) IRunnerContributor.DEFAULT_POSITIVE_AFFINITY else 0 }