Merge pull request #3673 from RomanIakovlev/sbt_1055

Add a check for a change in SBT version before reload
This commit is contained in:
Dale Wijnand 2017-10-28 00:24:44 +01:00 committed by GitHub
commit 4527029584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View File

@ -56,7 +56,8 @@ import StandardMain._
import java.io.{ File, IOException }
import java.net.URI
import java.util.Locale
import java.util.{ Locale, Properties }
import scala.util.control.NonFatal
import BasicCommandStrings.{ Shell, TemplateCommand }
import CommandStrings.BootCommand
@ -672,7 +673,26 @@ object BuiltinCommands {
def loadProjectImpl: Command =
Command(LoadProjectImpl)(_ => Project.loadActionParser)(doLoadProject)
def checkSBTVersionChanged(state: State): Unit = {
import sbt.io.syntax._
val app = state.configuration.provider
val buildProps = state.baseDir / "project" / "build.properties"
// First try reading the sbt version from build.properties file.
val sbtVersionOpt = if (buildProps.exists) {
val buildProperties = new Properties()
IO.load(buildProperties, buildProps)
Option(buildProperties.getProperty("sbt.version"))
} else None
sbtVersionOpt.foreach(version =>
if (version != app.id.version()) {
state.log.warn(s"""sbt version mismatch, current: ${app.id
.version()}, in build.properties: "$version", use 'reboot' to use the new value.""")
})
}
def doLoadProject(s0: State, action: LoadAction.Value): State = {
checkSBTVersionChanged(s0)
val (s1, base) = Project.loadAction(SessionVar.clear(s0), action)
IO.createDirectory(base)
val s = if (s1 has Keys.stateCompilerCache) s1 else registerCompilerCache(s1)

View File

@ -0,0 +1,8 @@
TaskKey[Unit]("checkSbtVersionWarning") := {
val state = Keys.state.value
val logging = state.globalLogging
val currVersion = state.configuration.provider.id.version()
val contents = IO.read(logging.backing.file)
assert(contents.contains(s"""sbt version mismatch, current: $currVersion, in build.properties: "1.1.1", use 'reboot' to use the new value."""))
()
}

View File

@ -0,0 +1 @@
sbt.version=1.1.1

View File

@ -0,0 +1,4 @@
> help
$ copy-file changes/build.properties project/build.properties
> reload
> checkSbtVersionWarning