mirror of https://github.com/sbt/sbt.git
Merge pull request #3673 from RomanIakovlev/sbt_1055
Add a check for a change in SBT version before reload
This commit is contained in:
commit
4527029584
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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."""))
|
||||
()
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
sbt.version=1.1.1
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
> help
|
||||
$ copy-file changes/build.properties project/build.properties
|
||||
> reload
|
||||
> checkSbtVersionWarning
|
||||
Loading…
Reference in New Issue