Skip to content

Commit ae455b5

Browse files
Merge pull request #170 from dropbox/jfein/fix-register
Switch registering tasks to lazy
2 parents bc56d36 + 0563972 commit ae455b5

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
9090
customTasks: Set<AffectedModuleTaskType>
9191
) {
9292
customTasks.forEach { taskType ->
93-
val task = rootProject.tasks.register(taskType.commandByImpact).get()
94-
task.group = CUSTOM_TASK_GROUP_NAME
95-
task.description = taskType.taskDescription
96-
disableConfigCache(task)
97-
98-
rootProject.subprojects { project ->
99-
pluginIds.forEach { pluginId ->
100-
withPlugin(pluginId, task, taskType, project)
93+
rootProject.tasks.register(taskType.commandByImpact) { task ->
94+
task.group = CUSTOM_TASK_GROUP_NAME
95+
task.description = taskType.taskDescription
96+
disableConfigCache(task)
97+
98+
rootProject.subprojects { project ->
99+
pluginIds.forEach { pluginId ->
100+
withPlugin(pluginId, task, taskType, project)
101+
}
101102
}
102103
}
103104
}
@@ -131,20 +132,19 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
131132
taskType: AffectedModuleTaskType,
132133
groupName: String
133134
) {
134-
val task = rootProject.tasks.register(taskType.commandByImpact).get()
135-
task.group = groupName
136-
task.description = taskType.taskDescription
137-
disableConfigCache(task)
135+
rootProject.tasks.register(taskType.commandByImpact) { task ->
136+
task.group = groupName
137+
task.description = taskType.taskDescription
138+
disableConfigCache(task)
138139

139-
rootProject.subprojects { project ->
140-
project.afterEvaluate { evaluatedProject ->
140+
rootProject.subprojects { project ->
141141
pluginIds.forEach { pluginId ->
142142
if (pluginId == PLUGIN_JAVA_LIBRARY || pluginId == PLUGIN_KOTLIN) {
143143
if (taskType == InternalTaskType.ANDROID_JVM_TEST) {
144-
withPlugin(pluginId, task, InternalTaskType.JVM_TEST, evaluatedProject)
144+
withPlugin(pluginId, task, InternalTaskType.JVM_TEST, project)
145145
}
146146
} else {
147-
withPlugin(pluginId, task, taskType, evaluatedProject)
147+
withPlugin(pluginId, task, taskType, project)
148148
}
149149
}
150150
}
@@ -175,12 +175,10 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
175175
task.dependsOn(path)
176176
}
177177

178-
project.afterEvaluate {
179-
project.tasks.findByPath(path)?.onlyIf { task ->
180-
when {
181-
!AffectedModuleDetector.isProjectEnabled(task.project) -> true
182-
else -> AffectedModuleDetector.isProjectAffected(task.project)
183-
}
178+
project.tasks.findByPath(path)?.onlyIf { task ->
179+
when {
180+
!AffectedModuleDetector.isProjectEnabled(task.project) -> true
181+
else -> AffectedModuleDetector.isProjectAffected(task.project)
184182
}
185183
}
186184
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class AffectedModuleDetectorPluginTest {
8282
// GIVEN
8383
val task = fakeTask
8484
val plugin = AffectedModuleDetectorPlugin()
85+
rootProject.pluginManager.apply(AffectedModuleDetectorPlugin::class.java)
8586

8687
// WHEN
8788
plugin.registerInternalTask(

0 commit comments

Comments
 (0)