mirror of https://github.com/sbt/sbt.git
commit
20d7ceac68
|
|
@ -5,6 +5,7 @@
|
|||
A pure Scala substitute for [Aether](http://www.eclipse.org/aether/)
|
||||
|
||||
[](https://travis-ci.org/alexarchambault/coursier)
|
||||
[](https://ci.appveyor.com/project/alexarchambault/coursier)
|
||||
[](https://gitter.im/alexarchambault/coursier?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
See [Scala JS demo](https://alexarchambault.github.io/coursier/index.html#demo) and [usage](https://github.com/alexarchambault/coursier/blob/master/USAGE.md).
|
||||
|
|
|
|||
|
|
@ -80,7 +80,13 @@ case class MavenRepository(
|
|||
)
|
||||
}
|
||||
|
||||
EitherT(cachePolicy.saving(locally(localFile))(remote)(save))
|
||||
EitherT(
|
||||
cachePolicy[String \/ String](
|
||||
_.isLeft )(
|
||||
locally(localFile) )(
|
||||
_ => CachePolicy.saving(remote)(save)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -455,18 +455,18 @@ abstract class BaseMavenRepository(
|
|||
}
|
||||
|
||||
sealed trait CachePolicy {
|
||||
def apply[E,T](local: => Task[E \/ T])
|
||||
(remote: => Task[E \/ T]): Task[E \/ T]
|
||||
|
||||
def saving[E,T](local: => Task[E \/ T])
|
||||
(remote: => Task[E \/ T])
|
||||
(save: => T => Task[Unit]): Task[E \/ T] =
|
||||
apply(local)(CachePolicy.saving(remote)(save))
|
||||
def apply[T](
|
||||
tryRemote: T => Boolean )(
|
||||
local: => Task[T] )(
|
||||
remote: Option[T] => Task[T]
|
||||
): Task[T]
|
||||
}
|
||||
|
||||
object CachePolicy {
|
||||
def saving[E,T](remote: => Task[E \/ T])
|
||||
(save: T => Task[Unit]): Task[E \/ T] = {
|
||||
def saving[E,T](
|
||||
remote: => Task[E \/ T] )(
|
||||
save: T => Task[Unit]
|
||||
): Task[E \/ T] = {
|
||||
for {
|
||||
res <- remote
|
||||
_ <- res.fold(_ => Task.now(()), t => save(t))
|
||||
|
|
@ -474,19 +474,28 @@ object CachePolicy {
|
|||
}
|
||||
|
||||
case object Default extends CachePolicy {
|
||||
def apply[E,T](local: => Task[E \/ T])
|
||||
(remote: => Task[E \/ T]): Task[E \/ T] =
|
||||
def apply[T](
|
||||
tryRemote: T => Boolean )(
|
||||
local: => Task[T] )(
|
||||
remote: Option[T] => Task[T]
|
||||
): Task[T] =
|
||||
local
|
||||
.flatMap(res => if (res.isLeft) remote else Task.now(res))
|
||||
.flatMap(res => if (tryRemote(res)) remote(Some(res)) else Task.now(res))
|
||||
}
|
||||
case object LocalOnly extends CachePolicy {
|
||||
def apply[E,T](local: => Task[E \/ T])
|
||||
(remote: => Task[E \/ T]): Task[E \/ T] =
|
||||
def apply[T](
|
||||
tryRemote: T => Boolean )(
|
||||
local: => Task[T] )(
|
||||
remote: Option[T] => Task[T]
|
||||
): Task[T] =
|
||||
local
|
||||
}
|
||||
case object ForceDownload extends CachePolicy {
|
||||
def apply[E,T](local: => Task[E \/ T])
|
||||
(remote: => Task[E \/ T]): Task[E \/ T] =
|
||||
remote
|
||||
def apply[T](
|
||||
tryRemote: T => Boolean )(
|
||||
local: => Task[T] )(
|
||||
remote: Option[T] => Task[T]
|
||||
): Task[T] =
|
||||
remote(None)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,8 +143,11 @@ case class Files(
|
|||
val tasks =
|
||||
for ((f, url) <- pairs if url != ("file:" + f) && url != ("file://" + f)) yield {
|
||||
val file = new File(f)
|
||||
cachePolicy(locally(file))(remote(file, url))
|
||||
.map(e => (file, url) -> e.map(_ => ()))
|
||||
cachePolicy[FileError \/ File](
|
||||
_.isLeft )(
|
||||
locally(file) )(
|
||||
_ => remote(file, url)
|
||||
).map(e => (file, url) -> e.map(_ => ()))
|
||||
}
|
||||
|
||||
Nondeterminism[Task].gather(tasks)
|
||||
|
|
|
|||
Loading…
Reference in New Issue