<commit_before>package com.google.firebase.gradle.plugins.ci

import com.google.gson.Gson
import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option

abstract class ChangedModulesTask : DefaultTask() {
    @get:Input
    @set:Option(option = "changed-git-paths", description = "Hellos")
    abstract var changedGitPaths: List<String>

    @get:Input
    @set:Option(option = "output-file-path", description = "Hello")
    abstract var outputFilePath: String

    @get:OutputFile
    val outputFile by lazy {
        File(outputFilePath)
    }

    init {
        outputs.upToDateWhen { false }
    }

    @TaskAction
    fun execute() {
        val projects =
            AffectedProjectFinder(project, changedGitPaths.toSet(), listOf()).find().map { it.path }
                .toSet()

        val result = mutableMapOf<String, MutableSet<String>>()
        project.rootProject.subprojects.forEach { p ->
            p.configurations.forEach { c ->
                c.dependencies.filterIsInstance<ProjectDependency>().forEach {
                    result.getOrPut(it.dependencyProject.path) { mutableSetOf() }.add(p.path)
                }
            }
        }
        val affectedProjects =
            result.flatMap { (key, value) ->
                if (projects.contains(key)) setOf(key) + value else setOf()
            }.toSet()

        outputFile.writeText(Gson().toJson(affectedProjects))
    }
}
<commit_msg>Support leaf modules in changed modules task. (#3871)<commit_after>package com.google.firebase.gradle.plugins.ci

import com.google.gson.Gson
import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option

abstract class ChangedModulesTask : DefaultTask() {
    @get:Input
    @set:Option(option = "changed-git-paths", description = "Hellos")
    abstract var changedGitPaths: List<String>

    @get:Input
    @set:Option(option = "output-file-path", description = "Hello")
    abstract var outputFilePath: String

    @get:OutputFile
    val outputFile by lazy {
        File(outputFilePath)
    }

    init {
        outputs.upToDateWhen { false }
    }

    @TaskAction
    fun execute() {
        val projects =
            AffectedProjectFinder(project, changedGitPaths.toSet(), listOf()).find().map { it.path }
                .toSet()

        val result = project.rootProject.subprojects.associate {
            it.path to mutableSetOf<String>()
        }
        project.rootProject.subprojects.forEach { p ->
            p.configurations.forEach { c ->
                c.dependencies.filterIsInstance<ProjectDependency>().forEach {
                    result[it.dependencyProject.path]?.add(p.path)
                }
            }
        }
        val affectedProjects =
            result.flatMap { (key, value) ->
                if (projects.contains(key)) setOf(key) + value else setOf()
            }.toSet()

        outputFile.writeText(Gson().toJson(affectedProjects))
    }
}

{'fraction_non_alphanumeric': 0.11255280627640314, 'fraction_numerical': 0.0012070006035003018, 'mean_word_length': 2.5303514376996805, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743925', 'n_tokens_mistral': 991, 'n_tokens_neox': 936, 'n_words': 175}