Merge pull request #3163 from scalacenter/unique-settings-computation

Add duplicated settings test
This commit is contained in:
eugene yokota 2017-05-03 11:48:47 -04:00 committed by GitHub
commit da21e26339
3 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,9 @@
lazy val root = project
val checkComputedOnce = taskKey[Unit]("Check computed once")
checkComputedOnce := {
val buildValue = (foo in ThisBuild).value
assert(buildValue == "build 0", "Setting in ThisBuild was computed twice")
val globalValue = (foo in Global).value
assert(globalValue == "global 0", "Setting in Global was computed twice")
}

View File

@ -0,0 +1,3 @@
> checkComputedOnce
> setUpScripted
> checkComputedOnce

View File

@ -0,0 +1,27 @@
import java.util.concurrent.atomic.AtomicInteger
import sbt._, Keys._
object A extends AutoPlugin {
object autoImport {
lazy val foo = settingKey[String]("Foo.")
}
import autoImport._
override def trigger = allRequirements
override def buildSettings: Seq[Setting[_]] =
(foo := s"build ${buildCount.getAndIncrement}") ::
Nil
override def globalSettings: Seq[Setting[_]] =
(foo := s"global ${globalCount.getAndIncrement}") ::
(commands += setUpScripted) ::
Nil
def setUpScripted = Command.command("setUpScripted") { (state0: State) =>
Project.extract(state0).append(name := "foo", state0)
}
// used to ensure the build-level and global settings are only added once
private[this] val buildCount = new AtomicInteger(0)
private[this] val globalCount = new AtomicInteger(0)
}