Skip to content

Commit

Permalink
Use File.pathSeparator to split entries in classpath (#3084)
Browse files Browse the repository at this point in the history
* Use File.pathSeparator to split entries in classpath

* Use File.pathSeparator to split entries in classpath

* Update detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/settings/EnvironmentAware.kt

Co-authored-by: Nicola Corti <corti.nico@gmail.com>

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
  • Loading branch information
petertrr and cortinico committed Sep 18, 2020
1 parent 793cece commit 802659b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageVersion
import java.io.Closeable
import java.io.File

interface EnvironmentAware {

Expand Down Expand Up @@ -43,7 +44,7 @@ internal class EnvironmentFacade(
}

internal fun CompilerSpec.classpathEntries(): List<String> =
classpath?.split(":", ";") ?: emptyList() // support both windows ; and unix :
classpath?.split(File.pathSeparator) ?: emptyList()

internal fun CompilerSpec.parseLanguageVersion(): LanguageVersion? {
fun parse(value: String): LanguageVersion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ package io.gitlab.arturbosch.detekt.core.settings
import io.gitlab.arturbosch.detekt.core.createNullLoggingSpec
import io.gitlab.arturbosch.detekt.core.createProcessingSettings
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.konan.file.File
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe

internal class EnvironmentFacadeSpec : Spek({

describe("classpath entries can be separated by : or ;") {
describe("classpath entries should be separated by platform-specific separator") {

arrayOf(
"supports ;" to "file1;file2;file3",
"supports :" to "file1:file2:file3",
"supports mixing ; and :" to "file1;file2:file3"
).forEach { (testName, classpath) ->
it(testName) {
testSettings(classpath).use {
assertThat(it.classpath).hasSize(3)
}
val classpath = when (File.pathSeparator) {
":" -> "/path/to/file1:/path/to/file2:/path/to/file3"
";" -> """C:\path\to\file1;C:\path\to\file2;C:\path\to\file3"""
else -> ""
}

it("supports ${File.pathSeparator}") {
testSettings(classpath).use {
assertThat(it.classpath).hasSize(3)
}
}
}
Expand Down

0 comments on commit 802659b

Please sign in to comment.