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

io.gitlab.arturbosch.detekt.cli.OutputFacade.kt Maven / Gradle / Ivy

There is a newer version: 1.23.7
Show newest version
package io.gitlab.arturbosch.detekt.cli

import io.gitlab.arturbosch.detekt.api.ConsoleReport
import io.gitlab.arturbosch.detekt.api.Detektion
import io.gitlab.arturbosch.detekt.api.OutputReport
import io.gitlab.arturbosch.detekt.api.internal.SimpleNotification
import io.gitlab.arturbosch.detekt.core.ProcessingSettings

class OutputFacade(
    arguments: CliArgs,
    private val result: Detektion,
    private val settings: ProcessingSettings
) {

    private val config = settings.config
    private val reportPaths = arguments.reportPaths.toHashMap({ it.kind }, { it.path })

    fun run() {
        val reports = ReportLocator(settings)
            .load()
            .sortedBy { it.priority }
            .asReversed()

        reports.forEach { report ->
            report.init(config)
            report.init(settings)
            when (report) {
                is ConsoleReport -> handleConsoleReport(report, result)
                is OutputReport -> handleOutputReport(report, result)
            }
        }
    }

    private fun handleOutputReport(report: OutputReport, result: Detektion) {
        val filePath = reportPaths[report.id]
        if (filePath != null) {
            report.write(filePath, result)
            result.add(SimpleNotification("Successfully generated ${report.name} at $filePath"))
        }
    }

    private fun handleConsoleReport(report: ConsoleReport, result: Detektion) {
        report.print(settings.outPrinter, result)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy