@@ -32,6 +32,7 @@ import org.gradle.api.Project
32
32
import org.gradle.api.Task
33
33
import org.gradle.api.UnknownDomainObjectException
34
34
import org.gradle.api.logging.Logger
35
+ import org.gradle.api.tasks.TaskProvider
35
36
import java.io.File
36
37
37
38
/* *
@@ -140,9 +141,11 @@ abstract class AffectedModuleDetector {
140
141
rootProject.hasProperty(DEPENDENT_PROJECTS_ARG ) -> {
141
142
ProjectSubset .DEPENDENT_PROJECTS
142
143
}
144
+
143
145
rootProject.hasProperty(CHANGED_PROJECTS_ARG ) -> {
144
146
ProjectSubset .CHANGED_PROJECTS
145
147
}
148
+
146
149
else -> {
147
150
ProjectSubset .ALL_AFFECTED_PROJECTS
148
151
}
@@ -153,7 +156,7 @@ abstract class AffectedModuleDetector {
153
156
rootProject.extensions.findByType(AffectedModuleConfiguration ::class .java)
154
157
) {
155
158
" Root project ${rootProject.path} must have the AffectedModuleConfiguration " +
156
- " extension added."
159
+ " extension added."
157
160
}
158
161
159
162
val logger =
@@ -232,7 +235,7 @@ abstract class AffectedModuleDetector {
232
235
}
233
236
234
237
/* *
235
- * Call this method to configure the given task to execute only if the owner project
238
+ * Call this method to configure the given provided task to execute only if the owner project
236
239
* is affected by current changes
237
240
*
238
241
* Can be called during the configuration or execution phase
@@ -247,6 +250,24 @@ abstract class AffectedModuleDetector {
247
250
}
248
251
}
249
252
253
+ /* *
254
+ * Call this method to configure the given task to execute only if the owner project
255
+ * is affected by current changes
256
+ *
257
+ * Can be called during the configuration or execution phase
258
+ */
259
+ @Throws(GradleException ::class )
260
+ @JvmStatic
261
+ fun configureTaskGuard (taskProvider : TaskProvider <out Task >) {
262
+ taskProvider.configure { task ->
263
+ task.onlyIf {
264
+ getOrThrow(
265
+ task.project
266
+ ).shouldInclude(task.project)
267
+ }
268
+ }
269
+ }
270
+
250
271
/* *
251
272
* Call this method to determine if the project was affected in this change
252
273
*
@@ -340,7 +361,11 @@ class AffectedModuleDetectorImpl constructor(
340
361
injectedGitClient ? : GitClientImpl (
341
362
rootProject.projectDir,
342
363
logger,
343
- commitShaProvider = CommitShaProvider .fromString(config.compareFrom, config.specifiedBranch, config.specifiedRawCommitSha),
364
+ commitShaProvider = CommitShaProvider .fromString(
365
+ config.compareFrom,
366
+ config.specifiedBranch,
367
+ config.specifiedRawCommitSha
368
+ ),
344
369
ignoredFiles = config.ignoredFiles
345
370
)
346
371
}
@@ -399,9 +424,11 @@ class AffectedModuleDetectorImpl constructor(
399
424
changedProjects.contains(project.projectPath) -> {
400
425
ProjectSubset .CHANGED_PROJECTS
401
426
}
427
+
402
428
dependentProjects.contains(project.projectPath) -> {
403
429
ProjectSubset .DEPENDENT_PROJECTS
404
430
}
431
+
405
432
else -> {
406
433
ProjectSubset .NONE
407
434
}
@@ -435,13 +462,13 @@ class AffectedModuleDetectorImpl constructor(
435
462
unknownFiles.add(filePath)
436
463
logger?.info(
437
464
" Couldn't find containing project for file$filePath . " +
438
- " Adding to unknownFiles."
465
+ " Adding to unknownFiles."
439
466
)
440
467
} else {
441
468
changedProjects[containingProject.projectPath] = containingProject
442
469
logger?.info(
443
470
" For file $filePath containing project is $containingProject . " +
444
- " Adding to changedProjects."
471
+ " Adding to changedProjects."
445
472
)
446
473
}
447
474
}
@@ -487,7 +514,7 @@ class AffectedModuleDetectorImpl constructor(
487
514
}
488
515
logger?.info(
489
516
" unknownFiles: $unknownFiles , changedProjects: $changedProjects , buildAll: " +
490
- " $buildAll "
517
+ " $buildAll "
491
518
)
492
519
493
520
// If we're in a buildAll state, we return allProjects unless it's the changed target,
0 commit comments