Skip to content

Commit

Permalink
Add support for isolated projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Chelombitko committed Sep 11, 2024
1 parent c33274a commit 8393618
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.malinskiy.marathon

import org.gradle.api.flow.BuildWorkResult
import org.gradle.api.flow.FlowAction
import org.gradle.api.flow.FlowParameters
import org.gradle.api.provider.Property
import org.gradle.api.services.ServiceReference
import org.gradle.api.tasks.Input

@Suppress("UnstableApiUsage")
abstract class MarathonFlowAction : FlowAction<MarathonFlowAction.Params> {
override fun execute(parameters: Params) {
// Consume build result
parameters.buildWorkResult.get()

parameters.buildService.get().await()
}

interface Params : FlowParameters {
@get:Input
val buildWorkResult: Property<BuildWorkResult>

@get:ServiceReference
val buildService: Property<MarathonBuildService>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ import com.android.build.api.variant.Variant
import com.malinskiy.marathon.android.findAdbPath
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.configuration.BuildFeatures
import org.gradle.api.flow.FlowProviders
import org.gradle.api.flow.FlowScope
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.always
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.registerIfAbsent
import javax.inject.Inject

@Suppress("UnstableApiUsage")
class MarathonPlugin @Inject constructor(
private val buildFeatures: BuildFeatures,
private val flowProviders: FlowProviders,
private val flowScope: FlowScope
) : Plugin<Project> {

class MarathonPlugin : Plugin<Project> {
override fun apply(project: Project) {
if (project.path == Project.PATH_SEPARATOR) {
project.configureRootProject()
Expand All @@ -43,7 +54,13 @@ class MarathonPlugin : Plugin<Project> {
parameters.marathonConfig.set(marathonConfig)
}

tasks.register<MarathonWorkerRunTask>(WORKER_TASK_NAME)
if (buildFeatures.isolatedProjects.active.get()) {
flowScope.always(MarathonFlowAction::class) {
parameters.buildWorkResult.set(flowProviders.buildWorkResult)
}
} else {
tasks.register<MarathonWorkerRunTask>(WORKER_TASK_NAME)
}
}

private fun Project.configureAndroidProject() {
Expand All @@ -52,22 +69,20 @@ class MarathonPlugin : Plugin<Project> {
description = "Runs all the instrumentation test variations on all the connected devices"
}

val marathonWorkerTask = rootProject.tasks.named<MarathonWorkerRunTask>(WORKER_TASK_NAME)
val androidComponents = extensions.getByType(AndroidComponentsExtension::class.java)
androidComponents.onVariants { variant ->
variant.components
.filter { it is GeneratesTestApk }
.forEach { component ->
val testTask = registerTestTask(variant, component, marathonWorkerTask)
val testTask = registerTestTask(variant, component)
marathonTask.configure { dependsOn(testTask) }
}
}
}

private fun Project.registerTestTask(
variant: Variant,
testComponent: Component,
marathonWorkerTask: TaskProvider<MarathonWorkerRunTask>
testComponent: Component
): TaskProvider<MarathonScheduleTestsToWorkerTask> =
tasks.register<MarathonScheduleTestsToWorkerTask>(variant.computeTaskName(TASK_PREFIX, "androidTest")) {
group = JavaBasePlugin.VERIFICATION_GROUP
Expand All @@ -83,7 +98,9 @@ class MarathonPlugin : Plugin<Project> {
is TestVariant -> testedApkDir.set(variant.testedApks)
}

finalizedBy(marathonWorkerTask)
if (!buildFeatures.isolatedProjects.active.get()) {
finalizedBy(rootProject.tasks.named<MarathonWorkerRunTask>(WORKER_TASK_NAME))
}
}

companion object {
Expand Down
1 change: 1 addition & 0 deletions sample/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.jvmargs=-Xmx8g -XX:+UseParallelGC
org.gradle.parallel=true
org.gradle.unsafe.isolated-projects=true
kotlin.daemon.jvmargs=-Xmx1g -XX:+UseParallelGC

android.useAndroidX=true

0 comments on commit 8393618

Please sign in to comment.