Skip to content

Commit

Permalink
Merge pull request #170 from dropbox/jfein/fix-register
Browse files Browse the repository at this point in the history
Switch registering tasks to lazy
  • Loading branch information
joshafeinberg authored Oct 31, 2022
2 parents bc56d36 + 0563972 commit ae455b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
customTasks: Set<AffectedModuleTaskType>
) {
customTasks.forEach { taskType ->
val task = rootProject.tasks.register(taskType.commandByImpact).get()
task.group = CUSTOM_TASK_GROUP_NAME
task.description = taskType.taskDescription
disableConfigCache(task)

rootProject.subprojects { project ->
pluginIds.forEach { pluginId ->
withPlugin(pluginId, task, taskType, project)
rootProject.tasks.register(taskType.commandByImpact) { task ->
task.group = CUSTOM_TASK_GROUP_NAME
task.description = taskType.taskDescription
disableConfigCache(task)

rootProject.subprojects { project ->
pluginIds.forEach { pluginId ->
withPlugin(pluginId, task, taskType, project)
}
}
}
}
Expand Down Expand Up @@ -131,20 +132,19 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
taskType: AffectedModuleTaskType,
groupName: String
) {
val task = rootProject.tasks.register(taskType.commandByImpact).get()
task.group = groupName
task.description = taskType.taskDescription
disableConfigCache(task)
rootProject.tasks.register(taskType.commandByImpact) { task ->
task.group = groupName
task.description = taskType.taskDescription
disableConfigCache(task)

rootProject.subprojects { project ->
project.afterEvaluate { evaluatedProject ->
rootProject.subprojects { project ->
pluginIds.forEach { pluginId ->
if (pluginId == PLUGIN_JAVA_LIBRARY || pluginId == PLUGIN_KOTLIN) {
if (taskType == InternalTaskType.ANDROID_JVM_TEST) {
withPlugin(pluginId, task, InternalTaskType.JVM_TEST, evaluatedProject)
withPlugin(pluginId, task, InternalTaskType.JVM_TEST, project)
}
} else {
withPlugin(pluginId, task, taskType, evaluatedProject)
withPlugin(pluginId, task, taskType, project)
}
}
}
Expand Down Expand Up @@ -175,12 +175,10 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
task.dependsOn(path)
}

project.afterEvaluate {
project.tasks.findByPath(path)?.onlyIf { task ->
when {
!AffectedModuleDetector.isProjectEnabled(task.project) -> true
else -> AffectedModuleDetector.isProjectAffected(task.project)
}
project.tasks.findByPath(path)?.onlyIf { task ->
when {
!AffectedModuleDetector.isProjectEnabled(task.project) -> true
else -> AffectedModuleDetector.isProjectAffected(task.project)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class AffectedModuleDetectorPluginTest {
// GIVEN
val task = fakeTask
val plugin = AffectedModuleDetectorPlugin()
rootProject.pluginManager.apply(AffectedModuleDetectorPlugin::class.java)

// WHEN
plugin.registerInternalTask(
Expand Down

0 comments on commit ae455b5

Please sign in to comment.