Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Output Affected Module Paths #278

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.gradle.api.Task
import org.gradle.api.tasks.testing.Test
import org.gradle.util.GradleVersion
import org.jetbrains.annotations.VisibleForTesting
import java.io.File

/**
* This plugin creates and registers all affected test tasks.
Expand Down Expand Up @@ -38,6 +39,8 @@ import org.jetbrains.annotations.VisibleForTesting
*/
class AffectedModuleDetectorPlugin : Plugin<Project> {

private val affectedProjects = mutableSetOf<String>()

override fun apply(project: Project) {
require(
value = project.isRoot,
Expand All @@ -48,6 +51,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {

registerSubprojectConfiguration(project)
registerMainConfiguration(project)
registerAffectedModulesOutputTask(project)
AffectedModuleDetector.configure(project)
registerCustomTasks(project)
registerTestTasks(project)
Expand Down Expand Up @@ -83,6 +87,43 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
}
}

private fun registerAffectedModulesOutputTask(rootProject: Project) {
val outputFile = File("${rootProject.rootProject.layout.buildDirectory.get()}/affected_modules_paths.txt")

outputFile.parentFile?.mkdirs()
if (outputFile.exists()) {
outputFile.writeText("")
} else {
outputFile.createNewFile()
}

rootProject.tasks.register("outputAffectedModules") { task ->
task.group = "affected modules"
task.description = "Outputs the list of affected modules"
task.doLast {
println("Affected Modules:")
affectedProjects.forEach {
println(it)
outputFile.appendText("$it\n")
}
affectedProjects.clear()
println("Affected Modules written to ${outputFile.path}")
}
}

configureOutputAffectedModulesTask(rootProject)
}

private fun configureOutputAffectedModulesTask(rootProject: Project) {
rootProject.gradle.projectsEvaluated {
rootProject.allprojects {
if (AffectedModuleDetector.isProjectAffected(it)) {
affectedProjects.add(it.path)
}
}
}
}

@VisibleForTesting
internal fun registerCustomTasks(
rootProject: Project,
Expand Down