mirror of https://github.com/sbt/sbt.git
Accept non-finite durations as TTL
This commit is contained in:
parent
b76fbf363a
commit
387d88d717
|
|
@ -20,7 +20,7 @@ import scalaz.concurrent.{ Task, Strategy }
|
|||
|
||||
import java.io.{ Serializable => _, _ }
|
||||
|
||||
import scala.concurrent.duration.{ Duration, DurationInt, FiniteDuration }
|
||||
import scala.concurrent.duration.{ Duration, DurationInt }
|
||||
import scala.util.Try
|
||||
|
||||
trait AuthenticatedURLConnection extends URLConnection {
|
||||
|
|
@ -310,7 +310,7 @@ object Cache {
|
|||
cachePolicy: CachePolicy,
|
||||
pool: ExecutorService,
|
||||
logger: Option[Logger] = None,
|
||||
ttl: Option[FiniteDuration] = defaultTtl
|
||||
ttl: Option[Duration] = defaultTtl
|
||||
): Task[Seq[((File, String), FileError \/ Unit)]] = {
|
||||
|
||||
implicit val pool0 = pool
|
||||
|
|
@ -436,12 +436,15 @@ object Cache {
|
|||
|
||||
def shouldDownload(file: File, url: String): EitherT[Task, FileError, Boolean] = {
|
||||
|
||||
def checkNeeded = ttl.map(_.toMillis).filter(_ > 0L).fold(Task.now(true)) { ttlMs =>
|
||||
lastCheck(file).flatMap {
|
||||
case None => Task.now(true)
|
||||
case Some(ts) =>
|
||||
Task(System.currentTimeMillis()).map(_ > ts + ttlMs)
|
||||
}
|
||||
def checkNeeded = ttl.fold(Task.now(true)) { ttl =>
|
||||
if (ttl.isFinite())
|
||||
lastCheck(file).flatMap {
|
||||
case None => Task.now(true)
|
||||
case Some(ts) =>
|
||||
Task(System.currentTimeMillis()).map(_ > ts + ttl.toMillis)
|
||||
}
|
||||
else
|
||||
Task.now(false)
|
||||
}
|
||||
|
||||
def check = for {
|
||||
|
|
@ -782,7 +785,7 @@ object Cache {
|
|||
checksums: Seq[Option[String]] = defaultChecksums,
|
||||
logger: Option[Logger] = None,
|
||||
pool: ExecutorService = defaultPool,
|
||||
ttl: Option[FiniteDuration] = defaultTtl
|
||||
ttl: Option[Duration] = defaultTtl
|
||||
): EitherT[Task, FileError, File] = {
|
||||
|
||||
implicit val pool0 = pool
|
||||
|
|
@ -835,7 +838,7 @@ object Cache {
|
|||
checksums: Seq[Option[String]] = defaultChecksums,
|
||||
logger: Option[Logger] = None,
|
||||
pool: ExecutorService = defaultPool,
|
||||
ttl: Option[FiniteDuration] = defaultTtl
|
||||
ttl: Option[Duration] = defaultTtl
|
||||
): Fetch.Content[Task] = {
|
||||
artifact =>
|
||||
file(
|
||||
|
|
@ -890,11 +893,9 @@ object Cache {
|
|||
lazy val defaultPool =
|
||||
Executors.newFixedThreadPool(defaultConcurrentDownloadCount, Strategy.DefaultDaemonThreadFactory)
|
||||
|
||||
lazy val defaultTtl: Option[FiniteDuration] = {
|
||||
lazy val defaultTtl: Option[Duration] = {
|
||||
def fromString(s: String) =
|
||||
Try(Duration(s)).toOption.collect {
|
||||
case d: FiniteDuration => d
|
||||
}
|
||||
Try(Duration(s)).toOption
|
||||
|
||||
val fromEnv = sys.env.get("COURSIER_TTL").flatMap(fromString)
|
||||
def fromProps = sys.props.get("coursier.ttl").flatMap(fromString)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import coursier.ivy.IvyRepository
|
|||
import coursier.util.{Print, Parse}
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
import scalaz.{Failure, Success, \/-, -\/}
|
||||
import scalaz.concurrent.{ Task, Strategy }
|
||||
|
|
@ -85,21 +85,13 @@ class Helper(
|
|||
val ttl0 =
|
||||
if (ttl.isEmpty)
|
||||
Cache.defaultTtl
|
||||
else {
|
||||
val d = try {
|
||||
Duration(ttl)
|
||||
} catch {
|
||||
else
|
||||
try Some(Duration(ttl))
|
||||
catch {
|
||||
case e: Exception =>
|
||||
prematureExit(s"Unrecognized TTL duration: $ttl")
|
||||
}
|
||||
|
||||
d match {
|
||||
case f: FiniteDuration => Some(f)
|
||||
case _ =>
|
||||
prematureExit(s"Non finite TTL duration: $ttl")
|
||||
}
|
||||
}
|
||||
|
||||
val cachePolicies =
|
||||
if (common.mode.isEmpty)
|
||||
CachePolicy.default
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import coursier.core.Publication
|
|||
|
||||
import sbt.{ GetClassifiersModule, Resolver, SettingKey, TaskKey }
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
object Keys {
|
||||
val coursierParallelDownloads = SettingKey[Int]("coursier-parallel-downloads")
|
||||
|
|
@ -15,7 +15,7 @@ object Keys {
|
|||
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 coursierTtl = SettingKey[Option[Duration]]("coursier-ttl")
|
||||
|
||||
val coursierVerbosity = SettingKey[Int]("coursier-verbosity")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue