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

Extract IAffinity in its own interface.

This commit is contained in:
Cedric Beust 2015-11-29 08:56:33 -08:00
parent 4c63be1f16
commit fd5fb983e2
6 changed files with 9 additions and 25 deletions

View file

@ -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<IClasspathDependency>) : TaskResult
}

View file

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

View file

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

View file

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

View file

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

View file

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