@@ -56,6 +56,12 @@ import java.io.File
56
56
*/
57
57
enum class ProjectSubset { DEPENDENT_PROJECTS , CHANGED_PROJECTS , ALL_AFFECTED_PROJECTS , NONE }
58
58
59
+ /* *
60
+ * An identifier for a project, ensuring that projects are always identified by their path.
61
+ */
62
+ @JvmInline
63
+ value class ProjectPath (val path : String )
64
+
59
65
/* *
60
66
* A utility class that can discover which files are changed based on git history.
61
67
*
@@ -344,7 +350,7 @@ class AffectedModuleDetectorImpl constructor(
344
350
}
345
351
346
352
private val allProjects by lazy {
347
- rootProject.subprojects.toSet()
353
+ rootProject.subprojects.associateBy { it.projectPath }
348
354
}
349
355
350
356
private val projectGraph by lazy {
@@ -369,7 +375,7 @@ class AffectedModuleDetectorImpl constructor(
369
375
370
376
override fun shouldInclude (project : Project ): Boolean {
371
377
val isRootProject = project.isRoot
372
- val isProjectAffected = affectedProjects.contains(project)
378
+ val isProjectAffected = affectedProjects.contains(project.projectPath )
373
379
val isProjectProvided = isProjectProvided2(project)
374
380
val isModuleExcludedByName = config.excludedModules.contains(project.name)
375
381
val isModuleExcludedByRegex = config.excludedModules.any { project.path.matches(it.toRegex()) }
@@ -390,10 +396,10 @@ class AffectedModuleDetectorImpl constructor(
390
396
391
397
override fun getSubset (project : Project ): ProjectSubset {
392
398
return when {
393
- changedProjects.contains(project) -> {
399
+ changedProjects.contains(project.projectPath ) -> {
394
400
ProjectSubset .CHANGED_PROJECTS
395
401
}
396
- dependentProjects.contains(project) -> {
402
+ dependentProjects.contains(project.projectPath ) -> {
397
403
ProjectSubset .DEPENDENT_PROJECTS
398
404
}
399
405
else -> {
@@ -410,7 +416,7 @@ class AffectedModuleDetectorImpl constructor(
410
416
private fun findChangedProjects (
411
417
top : Sha ,
412
418
includeUncommitted : Boolean = true
413
- ): Set < Project > {
419
+ ): Map < ProjectPath , Project > {
414
420
git.findChangedFiles(
415
421
top = top,
416
422
includeUncommitted = includeUncommitted
@@ -421,7 +427,7 @@ class AffectedModuleDetectorImpl constructor(
421
427
changedFiles.add(fileName)
422
428
}
423
429
424
- val changedProjects = mutableSetOf< Project >()
430
+ val changedProjects = mutableMapOf< ProjectPath , Project >()
425
431
426
432
for (filePath in changedFiles) {
427
433
val containingProject = findContainingProject(filePath)
@@ -432,7 +438,7 @@ class AffectedModuleDetectorImpl constructor(
432
438
" Adding to unknownFiles."
433
439
)
434
440
} else {
435
- changedProjects.add( containingProject)
441
+ changedProjects[containingProject.projectPath] = containingProject
436
442
logger?.info(
437
443
" For file $filePath containing project is $containingProject . " +
438
444
" Adding to changedProjects."
@@ -447,10 +453,10 @@ class AffectedModuleDetectorImpl constructor(
447
453
* Gets all dependent projects from the set of changedProjects. This doesn't include the
448
454
* original changedProjects. Always build is still here to ensure at least 1 thing is built
449
455
*/
450
- private fun findDependentProjects (): Set < Project > {
451
- return changedProjects.flatMap {
452
- dependencyTracker.findAllDependents(it)
453
- }.toSet()
456
+ private fun findDependentProjects (): Map < ProjectPath , Project > {
457
+ return changedProjects.flatMap { (_, project) ->
458
+ dependencyTracker.findAllDependents(project).entries
459
+ }.associate { it.key to it.value }
454
460
}
455
461
456
462
/* *
@@ -466,7 +472,7 @@ class AffectedModuleDetectorImpl constructor(
466
472
* Also detects modules whose tests are codependent at runtime.
467
473
*/
468
474
@Suppress(" ComplexMethod" )
469
- private fun findAffectedProjects (): Set < Project > {
475
+ private fun findAffectedProjects (): Map < ProjectPath , Project > {
470
476
// In this case we don't care about any of the logic below, we're only concerned with
471
477
// running the changed projects in this test runner
472
478
if (projectSubset == ProjectSubset .CHANGED_PROJECTS ) {
@@ -525,3 +531,5 @@ class AffectedModuleDetectorImpl constructor(
525
531
}
526
532
527
533
val Project .isRoot get() = this == rootProject
534
+
535
+ val Project .projectPath: ProjectPath get() = ProjectPath (path)
0 commit comments