Add forceUpdateMs

This commit is contained in:
Andrew Johnson 2015-05-13 08:02:48 -04:00
parent f334d76f70
commit 4ec092617f
5 changed files with 43 additions and 2 deletions

View File

@ -115,7 +115,8 @@ object Defaults extends BuildCommon {
pomPostProcess :== idFun,
pomAllRepositories :== false,
pomIncludeRepository :== Classpaths.defaultRepositoryFilter,
updateOptions := UpdateOptions()
updateOptions := UpdateOptions(),
forceUpdateMs :== None
)
/** Core non-plugin settings for sbt builds. These *must* be on every build or the sbt engine will fail to run at all. */
@ -1324,7 +1325,13 @@ object Classpaths {
def updateTask: Initialize[Task[UpdateReport]] = Def.task {
val depsUpdated = transitiveUpdate.value.exists(!_.stats.cached)
val isRoot = executionRoots.value contains resolvedScoped.value
val forceUpdate = forceUpdateMs.value
val s = streams.value
val fullUpdateOutput = s.cacheDirectory / "out"
val forceUpdateByTime = forceUpdate match {
case None => false
case Some(period) => fullUpdateOutput.exists() && fullUpdateOutput.lastModified() <= (System.currentTimeMillis() - period)
}
val scalaProvider = appConfiguration.value.provider.scalaProvider
// Only substitute unmanaged jars for managed jars when the major.minor parts of the versions the same for:
@ -1360,7 +1367,7 @@ object Classpaths {
if (executionRoots.value exists { _.key == evicted.key }) EvictionWarningOptions.empty
else (evictionWarningOptions in update).value
cachedUpdate(s.cacheDirectory / updateCacheName.value, show, ivyModule.value, uc, transform,
skip = (skip in update).value, force = isRoot, depsUpdated = depsUpdated,
skip = (skip in update).value, force = isRoot || forceUpdateByTime, depsUpdated = depsUpdated,
uwConfig = uwConfig, logicalClock = logicalClock, depDir = Some(depDir),
ewo = ewo, log = s.log)
}

View File

@ -324,6 +324,7 @@ object Keys {
val publishArtifact = SettingKey[Boolean]("publish-artifact", "Enables (true) or disables (false) publishing an artifact.", AMinusSetting)
val packagedArtifact = TaskKey[(Artifact, File)]("packaged-artifact", "Generates a packaged artifact, returning the Artifact and the produced File.", CTask)
val checksums = SettingKey[Seq[String]]("checksums", "The list of checksums to generate and to verify for dependencies.", BSetting)
val forceUpdateMs = SettingKey[Option[Long]]("force-update-ms", "Amount of time in milliseconds after which to force a full update to occur", CSetting)
val classifiersModule = TaskKey[GetClassifiersModule]("classifiers-module", rank = CTask)
val conflictWarning = SettingKey[ConflictWarning]("conflict-warning", "Configures warnings for conflicts in dependency management.", CSetting)

View File

@ -0,0 +1,9 @@
[@ajsquared]: https://github.com/ajsquared
### Changes with compatibility implications
### Improvements
- Adds `forceUpdateMs` key, that takes values of `Option[Long]` representing a number of milliseconds. If set, a full `update` will occur after that amount of time without needing to explicitly run the `update` task.
### Fixes

View File

@ -0,0 +1,13 @@
libraryDependencies += "log4j" % "log4j" % "1.2.16" % "compile"
autoScalaLibrary := false
TaskKey[Unit]("check-last-update-time") <<= streams map { (s) =>
val fullUpdateOutput = s.cacheDirectory / "out"
val timeDiff = System.currentTimeMillis()-fullUpdateOutput.lastModified()
val exists = fullUpdateOutput.exists()
s.log.info(s"Amount of time since last full update: $timeDiff")
if (exists && timeDiff > 5000) {
sys.error("Full update not perfomed")
}
}

View File

@ -0,0 +1,11 @@
$ absent target/resolution-cache
> compile
$ exists target/resolution-cache
> checkLastUpdateTime
$ sleep 10000
> compile
# This is expected to fail
-> checkLastUpdateTime
> set forceUpdateMs := Some(5000)
> compile
> checkLastUpdateTime