2018-12-09 05:13:11 +08:00
|
|
|
/*
|
2021-01-08 17:55:38 +01:00
|
|
|
* Copyright (C) 2018-2021 Lightbend Inc. <https://www.lightbend.com>
|
2018-12-09 05:13:11 +08:00
|
|
|
*/
|
2019-01-02 18:55:26 +08:00
|
|
|
|
2018-12-09 05:13:11 +08:00
|
|
|
package sbt
|
2019-01-16 11:44:07 +01:00
|
|
|
import Keys.baseDirectory
|
2018-12-09 05:13:11 +08:00
|
|
|
|
2019-01-12 01:41:54 +08:00
|
|
|
import akka.ProjectFileIgnoreSupport
|
2018-12-09 05:13:11 +08:00
|
|
|
import sbt.Keys.unmanagedSources
|
|
|
|
|
|
2019-01-16 11:44:07 +01:00
|
|
|
trait ScalafixSupport {
|
|
|
|
|
private val ignoreConfigFileName: String = ".scalafix.conf"
|
|
|
|
|
private val descriptor: String = "scalafix"
|
2018-12-09 05:13:11 +08:00
|
|
|
|
2019-01-12 01:41:54 +08:00
|
|
|
protected def ignore(configKey: ConfigKey): Def.Setting[Task[Seq[File]]] = {
|
|
|
|
|
import scalafix.sbt.ScalafixPlugin.autoImport._
|
2019-01-16 11:44:07 +01:00
|
|
|
|
2021-05-25 12:50:51 +02:00
|
|
|
configKey / scalafix / unmanagedSources := {
|
2020-12-09 15:20:13 +07:00
|
|
|
val ignoreSupport =
|
2021-05-25 12:50:51 +02:00
|
|
|
new ProjectFileIgnoreSupport((ThisBuild / baseDirectory).value / ignoreConfigFileName, descriptor)
|
2019-01-16 11:44:07 +01:00
|
|
|
|
2021-05-25 12:50:51 +02:00
|
|
|
(configKey / scalafix / unmanagedSources).value.filterNot(file => ignoreSupport.isIgnoredByFileOrPackages(file))
|
2019-01-16 11:44:07 +01:00
|
|
|
}
|
2018-12-09 05:13:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
import sbt.Keys._
|
|
|
|
|
|
|
|
|
|
def addProjectCommandsIfAbsent(alias: String, value: String): Def.Setting[Seq[Command]] = {
|
|
|
|
|
commands := {
|
|
|
|
|
val currentCommands = commands.value.collect {
|
|
|
|
|
case command: SimpleCommand => command.name
|
|
|
|
|
}.toSet
|
|
|
|
|
val isPresent = currentCommands(alias)
|
|
|
|
|
if (isPresent)
|
|
|
|
|
commands.value
|
|
|
|
|
else
|
2020-12-09 15:20:13 +07:00
|
|
|
commands.value :+ BasicCommands.newAlias(name = alias, value = value)
|
2018-12-09 05:13:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def updateProjectCommands(alias: String, value: String): Def.Setting[Seq[Command]] = {
|
|
|
|
|
commands := {
|
|
|
|
|
commands.value.filterNot({
|
|
|
|
|
case command: SimpleCommand => command.name == alias
|
2020-12-09 15:20:13 +07:00
|
|
|
case _ => false
|
|
|
|
|
}) :+ BasicCommands.newAlias(name = alias, value = value)
|
2018-12-09 05:13:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-09 15:20:13 +07:00
|
|
|
|
|
|
|
|
object ScalafixSupport {
|
|
|
|
|
def fixTestScope: Boolean = System.getProperty("akka.scalafix.fixTestScope", "false").toBoolean
|
|
|
|
|
}
|