Skip to content

Commit e4e8017

Browse files
authored
Add excluded modules configuration (#54)
* Fix for comparing with uncommitted changes * Add ability to specify a branch to compare changes against * Add exception test * Change ordering as specified branch must be before compareFrom configuration * can now define excluded modules to not be considered in the build process * add excluded module * Can now define modules to exclude from build process * use new exclude functionality * add test * Add excluded modules to README.md
1 parent 40de297 commit e4e8017

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ affectedModuleDetector {
7070
logFilename = "output.log"
7171
logFolder = "${project.rootDir}/output"
7272
compareFrom = "PreviousCommit" //default is PreviousCommit
73+
excludedModules = [
74+
"sample-util"
75+
]
7376
}
7477
```
7578

@@ -82,6 +85,7 @@ affectedModuleDetector {
8285
- PreviousCommit: compare against the previous commit
8386
- ForkCommit: compare against the commit the branch was forked from
8487
- SpecifiedBranchCommit: specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
88+
- `excludedModules` : A list of modules that will be excluded from the build process
8589

8690

8791

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class AffectedModuleConfiguration {
5353
field = value
5454
}
5555

56+
/**
57+
* A set of modules that will not be considered in the build process, even if changes are made in them.
58+
*/
59+
var excludedModules = emptySet<String>()
60+
5661
companion object {
5762
const val name = "affectedModuleDetector"
5863
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ class AffectedModuleDetectorImpl constructor(
362362

363363
override fun shouldInclude(project: Project): Boolean {
364364
return (
365-
project.isRoot || (
365+
(project.isRoot || (
366366
affectedProjects.contains(project) &&
367367
isProjectProvided2(project)
368-
)
368+
)) && !config.excludedModules.contains(project.name)
369369
).also {
370370
logger?.info(
371371
"checking whether I should include ${project.path} and my answer is $it"

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,28 @@ class AffectedModuleDetectorImplTest {
12301230
Truth.assertThat(detector.shouldInclude(p5)).isTrue()
12311231
}
12321232

1233+
@Test
1234+
fun `GIVEN module is in excludedModules configuration WHEN shouldInclude THEN excluded module false AND dependent modules true`() {
1235+
affectedModuleConfiguration = affectedModuleConfiguration.also {
1236+
it.excludedModules = setOf("p1")
1237+
}
1238+
val detector = AffectedModuleDetectorImpl(
1239+
rootProject = root,
1240+
logger = logger,
1241+
ignoreUnknownProjects = false,
1242+
projectSubset = ProjectSubset.ALL_AFFECTED_PROJECTS,
1243+
modules = null,
1244+
injectedGitClient = MockGitClient(
1245+
changedFiles = listOf(convertToFilePath("p1", "foo.java")),
1246+
tmpFolder = tmpFolder.root
1247+
),
1248+
config = affectedModuleConfiguration
1249+
)
1250+
Truth.assertThat(detector.shouldInclude(p1)).isFalse()
1251+
Truth.assertThat(detector.shouldInclude(p4)).isTrue()
1252+
Truth.assertThat(detector.shouldInclude(p5)).isTrue()
1253+
}
1254+
12331255
// For both Linux/Windows
12341256
fun convertToFilePath(vararg list: String): String {
12351257
return list.toList().joinToString(File.separator)

sample/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ affectedModuleDetector {
2929
compareFrom = "SpecifiedBranchCommit"
3030

3131
logFolder = "${project.rootDir}"
32+
excludedModules = [
33+
"sample-util"
34+
]
3235
}
3336

3437
allprojects {

0 commit comments

Comments
 (0)