io.github.gmazzo.codeowners.compiler.CodeOwnersIrGenerationExtension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler Show documentation
Show all versions of kotlin-compiler Show documentation
CodeOwners Kotlin Compiler Plugin
package io.github.gmazzo.codeowners.compiler
import io.github.gmazzo.codeowners.matcher.CodeOwnersFile
import io.github.gmazzo.codeowners.matcher.CodeOwnersMatcher
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import java.io.File
internal class CodeOwnersIrGenerationExtension(
private val matcher: CodeOwnersMatcher,
private val mappingsFile: File?,
) : IrGenerationExtension {
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
val mappings = mappingsFile?.let { mutableMapOf>() }
val transformer = CodeOwnersIrTransformer(pluginContext, mappings)
val owners = moduleFragment.files.asSequence()
.flatMap { matcher.ownerOf(File(it.fileEntry.name)).orEmpty() }
.toSet()
if (owners.isNotEmpty()) {
moduleFragment.accept(transformer, owners)
if (mappings != null) {
val entries = mappings.map { (file, owners) -> CodeOwnersFile.Entry(file, owners.toList()) }
val codeOwners = CodeOwnersFile(entries)
mappingsFile!!.appendText(codeOwners.content)
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy