Skip to content

Commit 2c16c05

Browse files
Merge pull request #181 from blundell/pblundell/exclude-by-name-or-regex-3
Allow exclude by regex
2 parents cbc026c + baa9a7c commit 2c16c05

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ affectedModuleDetector {
9090
logFolder = "${project.rootDir}/output"
9191
compareFrom = "PreviousCommit" //default is PreviousCommit
9292
excludedModules = [
93-
"sample-util"
93+
"sample-util", ":(app|library):.+"
9494
]
9595
includeUncommitted = true
9696
top = "HEAD"
@@ -116,7 +116,7 @@ affectedModuleDetector {
116116
- SpecifiedBranchCommitMergeBase: compare against the nearest ancestors with `$specifiedBranch` using `git merge base` approach.
117117

118118
**Note:** specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
119-
- `excludedModules`: A list of modules that will be excluded from the build process
119+
- `excludedModules`: A list of modules that will be excluded from the build process, can be the name of a module, or a regex against the module gradle path
120120
- `includeUncommitted`: If uncommitted files should be considered affected
121121
- `top`: The top of the git log to use. Must be used in combination with configuration `includeUncommitted = false`
122122
- `customTasks`: set of [CustomTask](https://github.com/dropbox/AffectedModuleDetector/blob/main/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ class AffectedModuleDetectorImpl constructor(
366366
val isRootProject = project.isRoot
367367
val isProjectAffected = affectedProjects.contains(project)
368368
val isProjectProvided = isProjectProvided2(project)
369-
val isNotModuleExcluded = !config.excludedModules.contains(project.name)
369+
val isModuleExcludedByName = config.excludedModules.contains(project.name)
370+
val isModuleExcludedByRegex = config.excludedModules.any { project.path.matches(it.toRegex()) }
371+
val isNotModuleExcluded = !(isModuleExcludedByName || isModuleExcludedByRegex)
370372

371373
val shouldInclude = (isRootProject || (isProjectAffected && isProjectProvided)) && isNotModuleExcluded
372374
logger?.info("checking whether I should include ${project.path} and my answer is $shouldInclude")

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,34 @@ class AffectedModuleDetectorImplTest {
12601260
Truth.assertThat(detector.shouldInclude(p5)).isTrue()
12611261
}
12621262

1263+
@Test
1264+
fun `GIVEN regex is in excludedModules configuration WHEN shouldInclude THEN excluded module false AND dependent modules true`() {
1265+
affectedModuleConfiguration = affectedModuleConfiguration.also {
1266+
it.excludedModules = setOf(":p1:p3:[a-zA-Z0-9:]+")
1267+
}
1268+
val detector = AffectedModuleDetectorImpl(
1269+
rootProject = root,
1270+
logger = logger,
1271+
ignoreUnknownProjects = false,
1272+
projectSubset = ProjectSubset.ALL_AFFECTED_PROJECTS,
1273+
modules = null,
1274+
injectedGitClient = MockGitClient(
1275+
changedFiles = listOf(
1276+
convertToFilePath("p1/p3", "foo.java"),
1277+
convertToFilePath("p1/p3/p4", "foo.java"),
1278+
convertToFilePath("p2/p5", "foo.java"),
1279+
convertToFilePath("p1/p3/p6", "foo.java")
1280+
),
1281+
tmpFolder = tmpFolder.root
1282+
),
1283+
config = affectedModuleConfiguration
1284+
)
1285+
Truth.assertThat(detector.shouldInclude(p3)).isTrue()
1286+
Truth.assertThat(detector.shouldInclude(p4)).isFalse()
1287+
Truth.assertThat(detector.shouldInclude(p5)).isTrue()
1288+
Truth.assertThat(detector.shouldInclude(p6)).isFalse()
1289+
}
1290+
12631291
@Test
12641292
fun `GIVEN a file that effects all changes has a change WHEN projectSubset is CHANGED_PROJECTS THEN all modules should be in this`() {
12651293
val changedFile = convertToFilePath("android", "gradle", "test.java")

0 commit comments

Comments
 (0)