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

io.gitlab.arturbosch.detekt.cli.out.XmlOutputReport.kt Maven / Gradle / Ivy

package io.gitlab.arturbosch.detekt.cli.out

import io.gitlab.arturbosch.detekt.api.Detektion
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.OutputReport
import io.gitlab.arturbosch.detekt.api.Severity

/**
 * Generates an XML report following the structure of a Checkstyle report.
 */
class XmlOutputReport : OutputReport() {

    override val ending = "xml"

    override val name = "Checkstyle XML report"

    override fun render(detektion: Detektion): String {
        val smells = detektion.findings.flatMap { it.value }

        val lines = ArrayList()
        lines += ""
        lines += ""

        smells.groupBy { it.location.file }.forEach { fileName, findings ->
            lines += ""
            findings.forEach {
                lines += arrayOf(
                        "\t"
                ).joinToString(separator = " ")
            }
            lines += ""
        }

        lines += ""
        return lines.joinToString(separator = "\n")
    }

    private val Finding.severityLabel: String
        get() = when (issue.severity) {
            Severity.CodeSmell,
            Severity.Style,
            Severity.Warning,
            Severity.Maintainability,
            Severity.Performance -> "warning"
            Severity.Defect -> "error"
            Severity.Minor -> "info"
            Severity.Security -> "fatal"
        }

    private fun Any.toXmlString() = XmlEscape.escapeXml(toString().trim())
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy