Skip to content

Commit 25c9c40

Browse files
committed
new approach to creating custom command for impact analysis
1 parent c4f6f1f commit 25c9c40

File tree

8 files changed

+403
-194
lines changed

8 files changed

+403
-194
lines changed

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ affectedModuleDetector {
9090
- `excludedModules`: A list of modules that will be excluded from the build process
9191
- `includeUncommitted`: If uncommitted files should be considered affected
9292
- `top`: The top of the git log to use. Must be used in combination with configuration `includeUncommitted = false`
93-
94-
93+
- `customTasks`: set of enum fields which implemented [AffectedModuleTaskType]()
9594

9695
By default, the Detector will look for `assembleAndroidDebugTest`, `connectedAndroidDebugTest`, and `testDebug`. Modules can specify a configuration block to specify which variant tests to run:
9796
```groovy
9897
affectedTestConfiguration {
99-
assembleAndroidTestTask = "assembleAndroidReleaseTest"
100-
runAndroidTestTask = "connectedAndroidReleaseTest"
101-
jvmTestTask = "testRelease"
98+
assembleAndroidTestTask = "assembleAndroidReleaseTest"
99+
runAndroidTestTask = "connectedAndroidReleaseTest"
100+
jvmTestTask = "testRelease"
102101
}
103102
```
104103

@@ -148,13 +147,50 @@ To run this on the sample app:
148147
```
149148

150149
2. Try running the following command:
151-
152150
```
153151
./gradlew runAffectedUnitTests -Paffected_module_detector.enable
154152
```
155153

156154
You should see zero tests run. Make a change within one of the modules and commit it. Rerunning the command should execute tests in that module and its dependent modules.
157155

156+
## Custom tasks
157+
158+
If you want to add a custom gradle command to execute with impact analysis
159+
you must create enum which implementing [AffectedModuleTaskType]().
160+
161+
Example:
162+
```kotlin
163+
164+
enum class CustomImpactAnalysisTaskType(
165+
override val commandByImpact: String,
166+
override val originalGradleCommand: String,
167+
override val taskDescription: String
168+
): AffectedModuleTaskType {
169+
170+
DETEKT_TASK(
171+
commandByImpact = "runDetektByImpact",
172+
originalGradleCommand = "detekt",
173+
taskDescription = "Run static analysis tool without auto-correction by Impact analysis"
174+
)
175+
}
176+
```
177+
178+
And then you must add your custom enum fields to configuration in `build.gradle` of your project:
179+
180+
```groovy
181+
affectedModuleDetector {
182+
baseDir = "${project.rootDir}"
183+
pathsAffectingAllModules = ["buildSrc/"]
184+
specifiedBranch = "dev"
185+
customTasks = [CustomImpactAnalysisTaskType.DETEKT_TASK] // <- list of enum fields
186+
compareFrom = "SpecifiedBranchCommit"
187+
includeUncommitted = false
188+
}
189+
```
190+
191+
**NOTE:** Your task might be complex and doesn't work correctly, if it is true
192+
you must create `buildSrc` module and write custom plugin manually like [AffectedModuleDetectorPlugin](https://github.com/RomanAimaletdinov/TestImpactAnalysisLib/blob/dev/buildSrc/src/main/java/AffectedModuleDetectorPlugin.kt)
193+
158194
## Notes
159195

160196
Special thanks to the AndroidX for originally developing this project at https://android.googlesource.com/platform/frameworks/support/+/androidx-main/buildSrc/src/main/kotlin/androidx/build/dependencyTracker

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package com.dropbox.affectedmoduledetector
22

3+
import com.dropbox.affectedmoduledetector.plugin.AffectedModuleTaskType
34
import java.io.File
45

56
class AffectedModuleConfiguration {
7+
8+
companion object {
9+
10+
const val name = "affectedModuleDetector"
11+
}
12+
613
/**
714
* Folder to place the log in
815
*/
@@ -63,6 +70,27 @@ class AffectedModuleConfiguration {
6370
*/
6471
var includeUncommitted: Boolean = true
6572

73+
/**
74+
* If you want to add a custom task for impact analysis you must set the list of enum's fields
75+
*
76+
* Example:
77+
* `build.gradle
78+
*
79+
* affectedModuleDetector {
80+
* baseDir = "${project.rootDir}"
81+
* pathsAffectingAllModules = ["buildSrc/"]
82+
* specifiedBranch = "dev"
83+
* customTasks = [MyCustomTask.DETEKT_TASK] // <- list of enum fields
84+
* compareFrom = "SpecifiedBranchCommit"
85+
* includeUncommitted = false
86+
* }
87+
* `
88+
*
89+
* @see AffectedModuleTaskType
90+
* @see AffectedModuleDetectorPlugin
91+
*/
92+
var customTasks = emptySet<AffectedModuleTaskType>()
93+
6694
/**
6795
* The top of the git log to use, only used when [includeUncommitted] is false
6896
*/
@@ -73,8 +101,4 @@ class AffectedModuleConfiguration {
73101
}
74102
field = value
75103
}
76-
77-
companion object {
78-
const val name = "affectedModuleDetector"
79-
}
80104
}

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

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)