Skip to content

Commit 6c2b902

Browse files
Merge pull request #130 from Evleaps/feature/easy_way_for_custom_command
Feature: New approach for creating custom command for impact analysis
2 parents 581fe1d + 28958b5 commit 6c2b902

File tree

15 files changed

+540
-100
lines changed

15 files changed

+540
-100
lines changed

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ affectedModuleDetector {
9494
]
9595
includeUncommitted = true
9696
top = "HEAD"
97+
customTasks = [
98+
new AffectedModuleConfiguration.CustomTask(
99+
"runDetektByImpact",
100+
"detekt",
101+
"Run static analysis tool without auto-correction by Impact analysis"
102+
)
103+
]
97104
}
98105
```
99106

@@ -109,15 +116,14 @@ affectedModuleDetector {
109116
- `excludedModules`: A list of modules that will be excluded from the build process
110117
- `includeUncommitted`: If uncommitted files should be considered affected
111118
- `top`: The top of the git log to use. Must be used in combination with configuration `includeUncommitted = false`
112-
113-
119+
- `customTasks`: set of [CustomTask](https://github.com/dropbox/AffectedModuleDetector/blob/main/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt)
114120

115121
By default, the Detector will look for `assembleAndroidDebugTest`, `connectedAndroidDebugTest`, and `testDebug`. Modules can specify a configuration block to specify which variant tests to run:
116122
```groovy
117123
affectedTestConfiguration {
118-
assembleAndroidTestTask = "assembleAndroidReleaseTest"
119-
runAndroidTestTask = "connectedAndroidReleaseTest"
120-
jvmTestTask = "testRelease"
124+
assembleAndroidTestTask = "assembleAndroidReleaseTest"
125+
runAndroidTestTask = "connectedAndroidReleaseTest"
126+
jvmTestTask = "testRelease"
121127
}
122128
```
123129

@@ -167,13 +173,39 @@ To run this on the sample app:
167173
```
168174

169175
2. Try running the following command:
170-
171176
```
172177
./gradlew runAffectedUnitTests -Paffected_module_detector.enable
173178
```
174179

175180
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.
176181

182+
## Custom tasks
183+
184+
If you want to add a custom gradle command to execute with impact analysis
185+
you must declare [AffectedModuleConfiguration.CustomTask](https://github.com/dropbox/AffectedModuleDetector/blob/main/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt)
186+
which is implementing [AffectedModuleTaskType]() in the configuration in `build.gradle` of your project:
187+
188+
```groovy
189+
// ...
190+
191+
affectedModuleDetector {
192+
// ...
193+
customTasks = [
194+
new AffectedModuleConfiguration.CustomTask(
195+
"runDetektByImpact",
196+
"detekt",
197+
"Run static analysis tool without auto-correction by Impact analysis"
198+
)
199+
]
200+
// ...
201+
}
202+
```
203+
204+
**NOTE:** Please, test all your custom commands.
205+
If your custom task doesn't work correctly after testing, might be your task quite complex
206+
and for correct working must using more gradle's api.
207+
Hence, you must create `buildSrc` module and write custom plugin manually like [AffectedModuleDetectorPlugin](https://github.com/dropbox/AffectedModuleDetector/blob/main/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt)
208+
177209
## Notes
178210

179211
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,46 @@ package com.dropbox.affectedmoduledetector
33
import java.io.File
44

55
class AffectedModuleConfiguration {
6+
7+
/**
8+
* Implementation of [AffectedModuleTaskType] for easy adding of custom gradle task to
9+
* AffectedModuleDetector. You can declare a new instance of it in build.gradle.
10+
*
11+
* @see AffectedModuleTaskType - interface
12+
* @see customTasks - configuration field
13+
*/
14+
data class CustomTask(
15+
override val commandByImpact: String,
16+
override val originalGradleCommand: String,
17+
override val taskDescription: String
18+
) : AffectedModuleTaskType
19+
20+
/**
21+
* If you want to add a custom task for impact analysis you must set the list
22+
* of [AffectedModuleTaskType] implementations.
23+
*
24+
* Example:
25+
* `build.gradle
26+
*
27+
* affectedModuleDetector {
28+
* ...
29+
* customTasks = [ // <- list of custom gradle invokes
30+
* new AffectedModuleConfiguration.CustomTask(
31+
* "runSomeCustomTaskByImpact",
32+
* "someTaskForExample",
33+
* "Task description."
34+
* )
35+
* ]
36+
* ...
37+
* }
38+
* `
39+
*
40+
* @see AffectedModuleTaskType - interface
41+
* @see CustomTask - Implementation class
42+
* @see AffectedModuleDetectorPlugin - gradle plugin
43+
*/
44+
var customTasks = emptySet<AffectedModuleConfiguration.CustomTask>()
45+
646
/**
747
* Folder to place the log in
848
*/
@@ -75,6 +115,7 @@ class AffectedModuleConfiguration {
75115
}
76116

77117
companion object {
118+
78119
const val name = "affectedModuleDetector"
79120
}
80121
}

0 commit comments

Comments
 (0)