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

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

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

import java.nio.file.Path
import kotlin.io.path.Path

data class ReportPath(val kind: String, val path: Path) {

    companion object {
        private const val NUM_OF_PARTS_UNIX = 2
        private const val NUM_OF_PARTS_WINDOWS = 3
        private const val REPORT_PATH_SEPARATOR = ":"

        fun from(input: String): ReportPath {
            val parts = input.split(REPORT_PATH_SEPARATOR)

            val path = when (val partsSize = parts.size) {
                NUM_OF_PARTS_UNIX -> parts[1]
                NUM_OF_PARTS_WINDOWS -> parts.slice(1 until partsSize).joinToString(REPORT_PATH_SEPARATOR)
                else -> error(
                    "Input '$input' must consist of two parts for Unix OSs or three for Windows (report-id:path)."
                )
            }

            val kind = parts[0]
            require(kind.isNotEmpty()) { "The kind of report must not be empty (path - $path)" }
            require(path.isNotEmpty()) { "The path of the report must not be empty (kind - $kind)" }
            return ReportPath(kind, Path(path))
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy