All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.gmazzo.codeowners.compiler.CodeOwnersComponentRegistrar.kt Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
@file:OptIn(ExperimentalCompilerApi::class)

package io.github.gmazzo.codeowners.compiler

import io.github.gmazzo.codeowners.compiler.BuildConfig.COMPILER_PLUGIN_ID
import io.github.gmazzo.codeowners.compiler.CodeOwnersConfigurationKeys.CODEOWNERS_FILE
import io.github.gmazzo.codeowners.compiler.CodeOwnersConfigurationKeys.CODEOWNERS_ROOT
import io.github.gmazzo.codeowners.compiler.CodeOwnersConfigurationKeys.MAPPINGS_OUTPUT
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.cli.common.messages.getLogger
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter

internal class CodeOwnersComponentRegistrar : CompilerPluginRegistrar() {

    override val supportsK2 = true

    override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
        if (KotlinVersion.CURRENT.toString() != BuildConfig.EXPECTED_KOTLIN_VERSION) {
            configuration.getLogger().warning("The '$COMPILER_PLUGIN_ID' plugin was designed for Kotlin ${BuildConfig.EXPECTED_KOTLIN_VERSION}, but you are using ${KotlinVersion.CURRENT}")
        }

        val codeOwnersRoot = configuration.get(CODEOWNERS_ROOT)!!
        val codeOwnersFile = configuration.get(CODEOWNERS_FILE)!!.useLines { CodeOwnersFile(it) }
        val mappingFile = configuration.get(MAPPINGS_OUTPUT)

        val matcher = CodeOwnersMatcher(codeOwnersRoot, codeOwnersFile)
        val mappings = CodeOwnersMappings(matcher, mappingFile)

        FirExtensionRegistrarAdapter.registerExtension(CodeOwnersFirExtensionRegistrar(mappings))
        IrGenerationExtension.registerExtension(CodeOwnersIrGenerationExtension(mappings))
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy