Skip to content

Commit bc56d36

Browse files
Merge pull request #167 from dropbox/jfein/exclude-modules-completely
Excluded modules should not be added to task graph
2 parents 4667549 + e2bcf44 commit bc56d36

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
7777
}
7878

7979
private fun registerCustomTasks(rootProject: Project) {
80-
val mainConfiguration = requireNotNull(
81-
value = rootProject.extensions.findByName(AffectedModuleConfiguration.name),
82-
lazyMessage = { "Unable to find ${AffectedTestConfiguration.name} in $rootProject" }
83-
) as AffectedModuleConfiguration
80+
val mainConfiguration = requireConfiguration(rootProject)
8481

8582
rootProject.afterEvaluate {
8683
registerCustomTasks(rootProject, mainConfiguration.customTasks)
@@ -166,9 +163,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
166163
testType: AffectedModuleTaskType,
167164
project: Project
168165
) {
166+
val config = requireConfiguration(project)
167+
168+
fun isExcludedModule(configuration: AffectedModuleConfiguration, path: String): Boolean {
169+
return configuration.excludedModules.find { path.startsWith(":$it") } != null
170+
}
171+
169172
project.pluginManager.withPlugin(pluginId) {
170173
getAffectedPath(testType, project)?.let { path ->
171-
if (AffectedModuleDetector.isProjectProvided(project)) {
174+
if (AffectedModuleDetector.isProjectProvided(project) && !isExcludedModule(config, path)) {
172175
task.dependsOn(path)
173176
}
174177

@@ -249,6 +252,13 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
249252
}
250253
}
251254

255+
private fun requireConfiguration(project: Project): AffectedModuleConfiguration {
256+
return requireNotNull(
257+
value = project.rootProject.extensions.findByName(AffectedModuleConfiguration.name),
258+
lazyMessage = { "Unable to find ${AffectedModuleConfiguration.name} in ${project.rootProject}" }
259+
) as AffectedModuleConfiguration
260+
}
261+
252262
companion object {
253263

254264
@VisibleForTesting

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorIntegrationTest.kt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,82 @@ class AffectedModuleDetectorIntegrationTest {
114114
assertThat(result.output).contains(":sample-core:assembleAndroidTest SKIPPED")
115115
assertThat(result.output).contains(":assembleAffectedAndroidTests SKIPPED")
116116
}
117+
118+
@Test
119+
fun `GIVEN multiple project with one excluded WHEN plugin is applied THEN tasks has dependencies minus the exclusions`() {
120+
// GIVEN
121+
tmpFolder.newFolder("sample-app")
122+
tmpFolder.newFolder("sample-core")
123+
tmpFolder.newFile("settings.gradle").writeText(
124+
"""
125+
|include ':sample-app'
126+
|include ':sample-core'
127+
""".trimMargin()
128+
)
129+
130+
tmpFolder.newFile("build.gradle").writeText(
131+
"""buildscript {
132+
| repositories {
133+
| google()
134+
| jcenter()
135+
| }
136+
| dependencies {
137+
| classpath "com.android.tools.build:gradle:4.1.0"
138+
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
139+
| }
140+
|}
141+
|plugins {
142+
| id "com.dropbox.affectedmoduledetector"
143+
|}
144+
|affectedModuleDetector {
145+
| excludedModules = [ "sample-core" ]
146+
|}
147+
|allprojects {
148+
| repositories {
149+
| google()
150+
| jcenter()
151+
| }
152+
|}""".trimMargin()
153+
)
154+
155+
tmpFolder.newFile("sample-app/build.gradle").writeText(
156+
"""plugins {
157+
| id 'com.android.application'
158+
| id 'kotlin-android'
159+
| }
160+
| android {
161+
| compileSdkVersion 30
162+
| buildToolsVersion "30.0.2"
163+
| }
164+
| dependencies {
165+
| implementation project(":sample-core")
166+
| }""".trimMargin()
167+
)
168+
169+
tmpFolder.newFile("sample-core/build.gradle").writeText(
170+
"""plugins {
171+
| id 'com.android.library'
172+
| id 'kotlin-android'
173+
| }
174+
| affectedTestConfiguration {
175+
| assembleAndroidTestTask = "assembleAndroidTest"
176+
| }
177+
| android {
178+
| compileSdkVersion 30
179+
| buildToolsVersion "30.0.2"
180+
| }""".trimMargin()
181+
)
182+
183+
// WHEN
184+
val result = GradleRunner.create()
185+
.withProjectDir(tmpFolder.root)
186+
.withPluginClasspath()
187+
.withArguments("assembleAffectedAndroidTests", "--dry-run")
188+
.build()
189+
190+
// THEN
191+
assertThat(result.output).contains(":sample-app:assembleDebugAndroidTest SKIPPED")
192+
assertThat(result.output).doesNotContain(":sample-core:assembleAndroidTest SKIPPED")
193+
assertThat(result.output).contains(":assembleAffectedAndroidTests SKIPPED")
194+
}
117195
}

0 commit comments

Comments
 (0)