mirror of
https://github.com/sbt/sbt.git
synced 2026-09-04 08:45:56 +02:00
Add support for TTL
This commit is contained in:
@@ -15,6 +15,7 @@ object CoursierPlugin extends AutoPlugin {
|
||||
val coursierChecksums = Keys.coursierChecksums
|
||||
val coursierArtifactsChecksums = Keys.coursierArtifactsChecksums
|
||||
val coursierCachePolicies = Keys.coursierCachePolicies
|
||||
val coursierTtl = Keys.coursierTtl
|
||||
val coursierVerbosity = Keys.coursierVerbosity
|
||||
val coursierSourceRepositories = Keys.coursierSourceRepositories
|
||||
val coursierResolvers = Keys.coursierResolvers
|
||||
@@ -58,7 +59,8 @@ object CoursierPlugin extends AutoPlugin {
|
||||
coursierMaxIterations := 50,
|
||||
coursierChecksums := Seq(Some("SHA-1"), None),
|
||||
coursierArtifactsChecksums := Seq(None),
|
||||
coursierCachePolicies := Settings.defaultCachePolicies,
|
||||
coursierCachePolicies := CachePolicy.default,
|
||||
coursierTtl := Cache.defaultTtl,
|
||||
coursierVerbosity := Settings.defaultVerbosityLevel,
|
||||
coursierSourceRepositories := Nil,
|
||||
coursierResolvers <<= Tasks.coursierResolversTask,
|
||||
|
||||
@@ -4,14 +4,18 @@ import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
import coursier.core.Publication
|
||||
|
||||
import sbt.{ GetClassifiersModule, Resolver, SettingKey, TaskKey }
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
object Keys {
|
||||
val coursierParallelDownloads = SettingKey[Int]("coursier-parallel-downloads")
|
||||
val coursierMaxIterations = SettingKey[Int]("coursier-max-iterations")
|
||||
val coursierChecksums = SettingKey[Seq[Option[String]]]("coursier-checksums")
|
||||
val coursierArtifactsChecksums = SettingKey[Seq[Option[String]]]("coursier-artifacts-checksums")
|
||||
val coursierCachePolicies = SettingKey[Seq[CachePolicy]]("coursier-cache-policies")
|
||||
val coursierTtl = SettingKey[Option[FiniteDuration]]("coursier-ttl")
|
||||
|
||||
val coursierVerbosity = SettingKey[Int]("coursier-verbosity")
|
||||
|
||||
|
||||
@@ -40,46 +40,4 @@ object Settings {
|
||||
.getOrElse(baseDefaultVerbosityLevel)
|
||||
}
|
||||
|
||||
|
||||
private val baseDefaultCachePolicies = Seq(
|
||||
CachePolicy.LocalOnly,
|
||||
CachePolicy.FetchMissing
|
||||
)
|
||||
|
||||
def defaultCachePolicies: Seq[CachePolicy] = {
|
||||
|
||||
def fromOption(value: Option[String], description: String): Option[Seq[CachePolicy]] =
|
||||
value.filter(_.nonEmpty).flatMap {
|
||||
str =>
|
||||
CacheParse.cachePolicies(str) match {
|
||||
case scalaz.Success(Seq()) =>
|
||||
Console.err.println(
|
||||
s"Warning: no mode found in $description, ignoring it."
|
||||
)
|
||||
None
|
||||
case scalaz.Success(policies) =>
|
||||
Some(policies)
|
||||
case scalaz.Failure(errors) =>
|
||||
Console.err.println(
|
||||
s"Warning: unrecognized mode in $description, ignoring it."
|
||||
)
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
val fromEnv = fromOption(
|
||||
sys.env.get("COURSIER_MODE"),
|
||||
"COURSIER_MODE environment variable"
|
||||
)
|
||||
|
||||
def fromProps = fromOption(
|
||||
sys.props.get("coursier.mode"),
|
||||
"Java property coursier.mode"
|
||||
)
|
||||
|
||||
fromEnv
|
||||
.orElse(fromProps)
|
||||
.getOrElse(baseDefaultCachePolicies)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -269,6 +269,7 @@ object Tasks {
|
||||
val checksums = coursierChecksums.value
|
||||
val maxIterations = coursierMaxIterations.value
|
||||
val cachePolicies = coursierCachePolicies.value
|
||||
val ttl = coursierTtl.value
|
||||
val cache = coursierCache.value
|
||||
|
||||
val log = streams.value.log
|
||||
@@ -461,9 +462,9 @@ object Tasks {
|
||||
|
||||
val fetch = Fetch.from(
|
||||
repositories,
|
||||
Cache.fetch(cache, cachePolicies.head, checksums = checksums, logger = Some(resLogger), pool = pool),
|
||||
Cache.fetch(cache, cachePolicies.head, checksums = checksums, logger = Some(resLogger), pool = pool, ttl = ttl),
|
||||
cachePolicies.tail.map(p =>
|
||||
Cache.fetch(cache, p, checksums = checksums, logger = Some(resLogger), pool = pool)
|
||||
Cache.fetch(cache, p, checksums = checksums, logger = Some(resLogger), pool = pool, ttl = ttl)
|
||||
): _*
|
||||
)
|
||||
|
||||
@@ -610,6 +611,7 @@ object Tasks {
|
||||
val parallelDownloads = coursierParallelDownloads.value
|
||||
val artifactsChecksums = coursierArtifactsChecksums.value
|
||||
val cachePolicies = coursierCachePolicies.value
|
||||
val ttl = coursierTtl.value
|
||||
val cache = coursierCache.value
|
||||
|
||||
val log = streams.value.log
|
||||
@@ -687,7 +689,8 @@ object Tasks {
|
||||
p,
|
||||
checksums = artifactsChecksums,
|
||||
logger = Some(artifactsLogger),
|
||||
pool = pool
|
||||
pool = pool,
|
||||
ttl = ttl
|
||||
)
|
||||
|
||||
cachePolicies.tail
|
||||
|
||||
Reference in New Issue
Block a user