Skip to content

Commit

Permalink
chore(sbt): Move static private entities to the top level
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Feb 27, 2024
1 parent 55e08aa commit de60539
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions plugins/package-managers/sbt/src/main/kotlin/Sbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,6 @@ class Sbt(
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
companion object {
// See https://github.com/sbt/sbt/blob/v1.5.1/launcher-package/integration-test/src/test/scala/RunnerTest.scala#L9.
private const val SBT_VERSION_PATTERN = "\\d(\\.\\d+){2}(-\\w+)?"

private val VERSION_REGEX = Regex("\\[info]\\s+($SBT_VERSION_PATTERN)")
private val PROJECT_REGEX = Regex("\\[info] \t [ *] (.+)")
private val POM_REGEX = Regex("\\[info] Wrote (.+\\.pom)")

// Batch mode (which suppresses interactive prompts) is not supported on Windows, compare
// https://github.com/sbt/sbt-launcher-package/blob/25c1b96/src/universal/bin/sbt.bat#L861 with
// https://github.com/sbt/sbt-launcher-package/blob/25c1b96/src/universal/bin/sbt#L449.
private val BATCH_MODE = "-batch".takeUnless { Os.isWindows }.orEmpty()

// Enable the CI mode which disables console colors and supershell, see
// https://www.scala-sbt.org/1.x/docs/Command-Line-Reference.html#Command+Line+Options.
private val CI_MODE = "-Dsbt.ci=true".addQuotesOnWindows()

// Disable console colors explicitly as in some cases CI_MODE is not enough.
private val NO_COLOR = "-Dsbt.color=false".addQuotesOnWindows()

// Disable the JLine terminal. Without this the JLine terminal can occasionally send a signal that causes the
// parent process to suspend, for example IntelliJ can be suspended while running the SbtTest.
private val DISABLE_JLINE = "-Djline.terminal=none".addQuotesOnWindows()

private val FIXED_USER_HOME = "-Duser.home=${Os.userHomeDirectory}".addQuotesOnWindows()

private val SBT_OPTIONS = arrayOf(BATCH_MODE, CI_MODE, NO_COLOR, DISABLE_JLINE, FIXED_USER_HOME)

private fun String.addQuotesOnWindows() = if (Os.isWindows) "\"$this\"" else this
}

class Factory : AbstractPackageManagerFactory<Sbt>("SBT") {
override val globsForDefinitionFiles = listOf("build.sbt", "build.scala")

Expand Down Expand Up @@ -237,6 +206,35 @@ class Sbt(
throw NotImplementedError()
}

// See https://github.com/sbt/sbt/blob/v1.5.1/launcher-package/integration-test/src/test/scala/RunnerTest.scala#L9.
private const val SBT_VERSION_PATTERN = "\\d(\\.\\d+){2}(-\\w+)?"

private val VERSION_REGEX = Regex("\\[info]\\s+($SBT_VERSION_PATTERN)")
private val PROJECT_REGEX = Regex("\\[info] \t [ *] (.+)")
private val POM_REGEX = Regex("\\[info] Wrote (.+\\.pom)")

// Batch mode (which suppresses interactive prompts) is not supported on Windows, compare
// https://github.com/sbt/sbt-launcher-package/blob/25c1b96/src/universal/bin/sbt.bat#L861 with
// https://github.com/sbt/sbt-launcher-package/blob/25c1b96/src/universal/bin/sbt#L449.
private val BATCH_MODE = "-batch".takeUnless { Os.isWindows }.orEmpty()

// Enable the CI mode which disables console colors and supershell, see
// https://www.scala-sbt.org/1.x/docs/Command-Line-Reference.html#Command+Line+Options.
private val CI_MODE = "-Dsbt.ci=true".addQuotesOnWindows()

// Disable console colors explicitly as in some cases CI_MODE is not enough.
private val NO_COLOR = "-Dsbt.color=false".addQuotesOnWindows()

// Disable the JLine terminal. Without this the JLine terminal can occasionally send a signal that causes the
// parent process to suspend, for example IntelliJ can be suspended while running the SbtTest.
private val DISABLE_JLINE = "-Djline.terminal=none".addQuotesOnWindows()

private val FIXED_USER_HOME = "-Duser.home=${Os.userHomeDirectory}".addQuotesOnWindows()

private val SBT_OPTIONS = arrayOf(BATCH_MODE, CI_MODE, NO_COLOR, DISABLE_JLINE, FIXED_USER_HOME)

private fun String.addQuotesOnWindows() = if (Os.isWindows) "\"$this\"" else this

private fun moveGeneratedPom(pomFile: File): Result<File> {
val targetDirParent = pomFile.parentFile.searchUpwardsForSubdirectory("target")
?: return Result.failure(IllegalArgumentException("No target subdirectory found for '$pomFile'."))
Expand Down

0 comments on commit de60539

Please sign in to comment.