mirror of https://github.com/sbt/sbt.git
Made implicit the cache policy arguments
This commit is contained in:
parent
e2c654eb88
commit
6eeb792829
|
|
@ -6,12 +6,14 @@ import java.io.File
|
|||
import caseapp._
|
||||
import coursier.core.{ MavenRepository, Parse, Repository, CachePolicy }
|
||||
|
||||
import scalaz.{\/-, -\/}
|
||||
import scalaz.concurrent.Task
|
||||
|
||||
case class Coursier(
|
||||
scope: List[String],
|
||||
keepOptional: Boolean,
|
||||
fetch: Boolean,
|
||||
@ExtraName("P") @ExtraName("cp") classpath: Boolean,
|
||||
@ExtraName("c") offline: Boolean,
|
||||
@ExtraName("v") verbose: List[Unit],
|
||||
@ExtraName("N") maxIterations: Int = 100
|
||||
|
|
@ -29,10 +31,11 @@ case class Coursier(
|
|||
|
||||
def fileRepr(f: File) = f.toString
|
||||
|
||||
def println(s: String) = Console.err.println(s)
|
||||
|
||||
|
||||
val logger: MavenRepository.Logger with Files.Logger =
|
||||
new MavenRepository.Logger with Files.Logger {
|
||||
def println(s: String) = Console.err.println(s)
|
||||
|
||||
def downloading(url: String) =
|
||||
println(s"Downloading $url")
|
||||
def downloaded(url: String, success: Boolean) =
|
||||
|
|
@ -57,6 +60,12 @@ case class Coursier(
|
|||
)
|
||||
}
|
||||
|
||||
implicit val cachePolicy =
|
||||
if (offline)
|
||||
CachePolicy.LocalOnly
|
||||
else
|
||||
CachePolicy.Default
|
||||
|
||||
val cachedMavenCentral = Repository.mavenCentral.copy(
|
||||
cache = Some(centralCacheDir),
|
||||
logger = if (verbose0 <= 1) None else Some(logger)
|
||||
|
|
@ -78,7 +87,7 @@ case class Coursier(
|
|||
}
|
||||
|
||||
if (malformed.nonEmpty) {
|
||||
Console.err.println(s"Malformed dependencies:\n${malformed.map(_.mkString(":")).mkString("\n")}")
|
||||
println(s"Malformed dependencies:\n${malformed.map(_.mkString(":")).mkString("\n")}")
|
||||
sys exit 1
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +123,7 @@ case class Coursier(
|
|||
.run
|
||||
|
||||
if (!res.isDone) {
|
||||
Console.err.println(s"Maximum number of iteration reached!")
|
||||
println(s"Maximum number of iteration reached!")
|
||||
sys exit 1
|
||||
}
|
||||
|
||||
|
|
@ -145,14 +154,8 @@ case class Coursier(
|
|||
}
|
||||
}
|
||||
|
||||
if (fetch) {
|
||||
println()
|
||||
|
||||
val cachePolicy: CachePolicy =
|
||||
if (offline)
|
||||
CachePolicy.LocalOnly
|
||||
else
|
||||
CachePolicy.Default
|
||||
if (fetch || classpath) {
|
||||
println("")
|
||||
|
||||
val artifacts = res.artifacts
|
||||
|
||||
|
|
@ -164,10 +167,25 @@ case class Coursier(
|
|||
if (verbose0 <= 0) None else Some(logger)
|
||||
)
|
||||
|
||||
val tasks = artifacts.map(files.file(_, cachePolicy).run)
|
||||
val tasks = artifacts.map(artifact => files.file(artifact, cachePolicy).run.map(artifact.->))
|
||||
val task = Task.gatherUnordered(tasks)
|
||||
|
||||
task.run
|
||||
val results = task.run
|
||||
val errors = results.collect{case (artifact, -\/(err)) => artifact -> err }
|
||||
val files0 = results.collect{case (artifact, \/-(f)) => f }
|
||||
|
||||
if (errors.nonEmpty) {
|
||||
println(s"${errors.size} error(s):")
|
||||
for ((artifact, error) <- errors) {
|
||||
println(s" ${artifact.url}: $error")
|
||||
}
|
||||
}
|
||||
|
||||
Console.out.println(
|
||||
files0
|
||||
.map(_.toString)
|
||||
.mkString(File.pathSeparator)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ object JsTests extends TestSuite {
|
|||
}
|
||||
|
||||
'getProj{
|
||||
implicit val cachePolicy = CachePolicy.Default
|
||||
|
||||
Repository.mavenCentral
|
||||
.find(Module("ch.qos.logback", "logback-classic"), "1.1.3")
|
||||
.map{case (_, proj) =>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ import coursier.core.compatibility.encodeURIComponent
|
|||
trait Repository {
|
||||
def find(
|
||||
module: Module,
|
||||
version: String,
|
||||
cachePolicy: CachePolicy = CachePolicy.Default
|
||||
version: String
|
||||
)(implicit
|
||||
cachePolicy: CachePolicy
|
||||
): EitherT[Task, String, (Artifact.Source, Project)]
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +39,8 @@ object Repository {
|
|||
repositories: Seq[Repository],
|
||||
module: Module,
|
||||
version: String
|
||||
)(implicit
|
||||
cachePolicy: CachePolicy
|
||||
): EitherT[Task, Seq[String], (Artifact.Source, Project)] = {
|
||||
|
||||
val lookups = repositories
|
||||
|
|
@ -295,7 +298,8 @@ abstract class BaseMavenRepository(
|
|||
|
||||
def find(
|
||||
module: Module,
|
||||
version: String,
|
||||
version: String
|
||||
)(implicit
|
||||
cachePolicy: CachePolicy
|
||||
): EitherT[Task, String, (Artifact.Source, Project)] = {
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ package object coursier {
|
|||
|
||||
implicit def fetch(
|
||||
repositories: Seq[core.Repository]
|
||||
)(implicit
|
||||
cachePolicy: CachePolicy
|
||||
): ResolutionProcess.Fetch[Task] = {
|
||||
|
||||
modVers =>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ object CentralTests extends TestSuite {
|
|||
Repository.mavenCentral
|
||||
)
|
||||
|
||||
implicit val cachePolicy = CachePolicy.Default
|
||||
|
||||
def resolve(deps: Set[Dependency], filter: Option[Dependency => Boolean] = None, extraRepo: Option[Repository] = None) = {
|
||||
val repositories0 = extraRepo.toSeq ++ repositories
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import coursier.test.compatibility._
|
|||
|
||||
object ResolutionTests extends TestSuite {
|
||||
|
||||
implicit val cachePolicy = CachePolicy.Default
|
||||
|
||||
def resolve0(deps: Set[Dependency], filter: Option[Dependency => Boolean] = None) = {
|
||||
Resolution(deps, filter = filter)
|
||||
.process
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class TestRepository(projects: Map[(Module, String), Project]) extends Repositor
|
|||
val source = new core.Artifact.Source {
|
||||
def artifacts(dependency: Dependency, project: Project) = ???
|
||||
}
|
||||
def find(module: Module, version: String, cachePolicy: CachePolicy) =
|
||||
def find(module: Module, version: String)(implicit cachePolicy: CachePolicy) =
|
||||
EitherT(Task.now(
|
||||
projects.get((module, version)).map((source, _)).toRightDisjunction("Not found")
|
||||
))
|
||||
|
|
|
|||
|
|
@ -133,9 +133,11 @@ class Backend($: BackendScope[Unit, State]) {
|
|||
filter = Some(dep => (s.options.followOptional || !dep.optional) && (s.options.keepTest || dep.scope != Scope.Test))
|
||||
)
|
||||
|
||||
implicit val cachePolicy = CachePolicy.Default
|
||||
|
||||
res
|
||||
.process
|
||||
.run(fetch(s.repositories.map(r => r.copy(logger = Some(logger)))), 100)
|
||||
.run(s.repositories.map(r => r.copy(logger = Some(logger))), 100)
|
||||
}
|
||||
|
||||
// For reasons that are unclear to me, not delaying this when using the runNow execution context
|
||||
|
|
|
|||
Loading…
Reference in New Issue