Skip to content

Commit

Permalink
Fix subprojects evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaeldivita committed Apr 10, 2020
1 parent ec4cd5b commit 728a262
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class ChangeTrackerPlugin : Plugin<Project> {
}

project.extensions.create(CHANGE_TRACKER_EXTENSION, ChangeTrackerExtension::class.java)
project.evaluationDependsOnChildren()
project.evaluationDependsOnChildrenRecursive()

project.afterEvaluate {
project.tasks.create(CHANGED_TRACKER_MODULES_TASK_NAME, ChangedModulesTask::class.java)
configureTasks(project)
it.tasks.create(CHANGED_TRACKER_MODULES_TASK_NAME, ChangedModulesTask::class.java)
configureTasks(it)
}
}

Expand All @@ -37,13 +37,19 @@ class ChangeTrackerPlugin : Plugin<Project> {

private fun getTaskForSubProjects(taskName: String, subProjects: Set<Project>): List<Task> =
subProjects.mapNotNull { subProject ->
subProject.tasks.findByName(taskName)?.apply {
onlyIf {
subProject.rootProject
.getExtraProperty<Set<Project>>(CHANGED_TRACKER_OUTPUT)
?.contains(subProject)
?: false
val task = subProject.tasks.findByName(taskName)
if (task != null) {
task.apply {
onlyIf {
subProject.rootProject
.getExtraProperty<Set<Project>>(CHANGED_TRACKER_OUTPUT)
?.contains(subProject)
?: false
}
}
} else {
subProject.logger.quiet("ChangeTracker - Task [$taskName] not found for $subProject")
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ open class ChangedModulesTask : DefaultTask() {
result.removeAll(blacklist)
result.addAll(whitelist)

project.logger.quiet("Affected modules $result")
project.logger.quiet("Affected projects")
result.forEach { it.logger.quiet(it.toString()) }

rootProject.extensions.extraProperties.set(CHANGED_TRACKER_OUTPUT, result)
}

private fun getProjectsByName(projectArgs: Set<String>): Set<Project> =
projectArgs.let { args ->
rootProject.subprojects
.filter { args.contains(it.path) }
.toSet()
}
rootProject
.subprojects
.filter { projectArgs.contains(it.path) }
.toSet()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProjectLocator(private val rootProject: Project) {
rootProject
} else {
projects.find { (_, projectPaths) ->
(0 until projectPaths.size).all { projectPaths[it] == filePaths[it] }
(projectPaths.indices).all { projectPaths[it] == filePaths[it] }
}?.first
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ fun <T> Project.getExtraProperty(key: String): T? = extensions.extraProperties[k

val Project.changeTrackerExtension: ChangeTrackerExtension
get() = extensions.getByName(CHANGE_TRACKER_EXTENSION) as ChangeTrackerExtension

fun Project.evaluationDependsOnChildrenRecursive() {
subprojects.forEach { it.evaluationDependsOnChildrenRecursive() }
evaluationDependsOnChildren()
}

0 comments on commit 728a262

Please sign in to comment.