Skip to content

Commit

Permalink
Fix issue with wrong report name
Browse files Browse the repository at this point in the history
When splitting a report path provided on JCommander, given a Windows path
would cause a false split, that would continue the execution despite the assert check.

This commit fixes this issue by the assumption that an absolute path on Windows
systems, will contain the current disk drive's letter.

Resolves: detekt#1123 - detekt#1141
  • Loading branch information
pavlospt committed Sep 22, 2018
1 parent b8f11c9 commit 05413f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Expand Up @@ -11,10 +11,24 @@ import java.nio.file.Paths
*/
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 = ":"
private const val ILLEGAL_PARTS_SIZE_ERROR = "Must consist of two parts for Unix OSs or three for Windows (report-id:path)."

fun from(input: String): ReportPath {
val parts = input.split(":")
assert(parts.size == 2) { "Must consist of exactly two parts (report-id:path)." }
val (kind, path) = parts
val parts = input.split(REPORT_PATH_SEPARATOR)
val partsSize = parts.size

require(partsSize == NUM_OF_PARTS_UNIX || partsSize == NUM_OF_PARTS_WINDOWS) { ILLEGAL_PARTS_SIZE_ERROR }

val kind = parts[0]
val path = when (partsSize) {
NUM_OF_PARTS_UNIX -> parts[1]
NUM_OF_PARTS_WINDOWS -> parts.slice(1 until partsSize).joinToString(REPORT_PATH_SEPARATOR)
else -> throw IllegalStateException(ILLEGAL_PARTS_SIZE_ERROR)
}

return ReportPath(defaultMapping(kind), Paths.get(path))
}

Expand Down
Expand Up @@ -25,14 +25,15 @@ internal class ReportsSpec : Spek({
"--input", "/tmp/must/be/given",
"--report", "xml:/tmp/path1",
"--report", "plain:/tmp/path2",
"--report", "$reportUnderTest:/tmp/path3"
"--report", "$reportUnderTest:/tmp/path3",
"--report", "html:D:_Gradle\\xxx\\xxx\\build\\reports\\detekt\\detekt.html"
)
val (cli, _) = parseArguments<CliArgs>(args)

val reports = cli.reportPaths

it("should parse multiple report entries") {
assertThat(reports).hasSize(3)
assertThat(reports).hasSize(4)
}

val extensions = ReportLocator(ProcessingSettings(listOf())).load()
Expand Down

0 comments on commit 05413f7

Please sign in to comment.