mirror of https://github.com/sbt/sbt.git
Configurable concurrent download count (default: 6)
This commit is contained in:
parent
8e8bbc6c9f
commit
77fc66aae8
|
|
@ -13,11 +13,15 @@ case class Coursier(
|
||||||
scope: List[String],
|
scope: List[String],
|
||||||
keepOptional: Boolean,
|
keepOptional: Boolean,
|
||||||
fetch: Boolean,
|
fetch: Boolean,
|
||||||
|
@ExtraName("J") default: Boolean,
|
||||||
|
@ExtraName("S") sources: Boolean,
|
||||||
|
@ExtraName("D") javadoc: Boolean,
|
||||||
@ExtraName("P") @ExtraName("cp") classpath: Boolean,
|
@ExtraName("P") @ExtraName("cp") classpath: Boolean,
|
||||||
@ExtraName("c") offline: Boolean,
|
@ExtraName("c") offline: Boolean,
|
||||||
@ExtraName("v") verbose: List[Unit],
|
@ExtraName("v") verbose: List[Unit],
|
||||||
@ExtraName("N") maxIterations: Int = 100,
|
@ExtraName("N") maxIterations: Int = 100,
|
||||||
@ExtraName("r") repository: List[String]
|
@ExtraName("r") repository: List[String],
|
||||||
|
@ExtraName("n") parallel: Option[Int]
|
||||||
) extends App {
|
) extends App {
|
||||||
|
|
||||||
val verbose0 = verbose.length
|
val verbose0 = verbose.length
|
||||||
|
|
@ -165,6 +169,8 @@ case class Coursier(
|
||||||
print.flatMap(_ => fetchQuiet(modVers))
|
print.flatMap(_ => fetchQuiet(modVers))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println(s"Resolving\n" + moduleVersions.map{case (mod, ver) => s" $mod:$ver"}.mkString("\n"))
|
||||||
|
|
||||||
val res = startRes
|
val res = startRes
|
||||||
.process
|
.process
|
||||||
.run(fetch0, maxIterations)
|
.run(fetch0, maxIterations)
|
||||||
|
|
@ -205,11 +211,29 @@ case class Coursier(
|
||||||
if (fetch || classpath) {
|
if (fetch || classpath) {
|
||||||
println("")
|
println("")
|
||||||
|
|
||||||
val artifacts = res.artifacts
|
val artifacts0 = res.artifacts
|
||||||
|
val default0 = default || (!sources && !javadoc)
|
||||||
|
val artifacts = artifacts0
|
||||||
|
.flatMap{ artifact =>
|
||||||
|
var l = List.empty[Artifact]
|
||||||
|
if (sources)
|
||||||
|
l = artifact.extra.get("sources").toList ::: l
|
||||||
|
if (javadoc)
|
||||||
|
l = artifact.extra.get("javadoc").toList ::: l
|
||||||
|
if (default0)
|
||||||
|
l = artifact :: l
|
||||||
|
|
||||||
val files = cache
|
l
|
||||||
|
}
|
||||||
|
|
||||||
|
val files = {
|
||||||
|
var files0 = cache
|
||||||
.files()
|
.files()
|
||||||
.copy(logger = Some(logger))
|
.copy(logger = Some(logger))
|
||||||
|
for (n <- parallel)
|
||||||
|
files0 = files0.copy(concurrentDownloadCount = n)
|
||||||
|
files0
|
||||||
|
}
|
||||||
|
|
||||||
val tasks = artifacts.map(artifact => files.file(artifact, cachePolicy).run.map(artifact.->))
|
val tasks = artifacts.map(artifact => files.file(artifact, cachePolicy).run.map(artifact.->))
|
||||||
val task = Task.gatherUnordered(tasks)
|
val task = Task.gatherUnordered(tasks)
|
||||||
|
|
@ -225,17 +249,10 @@ case class Coursier(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classpath)
|
|
||||||
Console.out.println(
|
Console.out.println(
|
||||||
files0
|
files0
|
||||||
.map(_.toString)
|
.map(_.toString)
|
||||||
.mkString(File.pathSeparator)
|
.mkString(if (classpath) File.pathSeparator else "\n")
|
||||||
)
|
|
||||||
else
|
|
||||||
println(
|
|
||||||
files0
|
|
||||||
.map(_.toString)
|
|
||||||
.mkString("\n")
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,29 @@
|
||||||
package coursier
|
package coursier
|
||||||
|
|
||||||
import java.net.{ URI, URL }
|
import java.net.{ URI, URL }
|
||||||
|
import java.util.concurrent.{ Executors, ExecutorService }
|
||||||
|
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scalaz.{ -\/, \/-, \/, EitherT }
|
import scalaz.{ -\/, \/-, \/, EitherT }
|
||||||
import scalaz.concurrent.Task
|
import scalaz.concurrent.{ Task, Strategy }
|
||||||
|
|
||||||
import java.io._
|
import java.io._
|
||||||
|
|
||||||
case class Files(
|
case class Files(
|
||||||
cache: Seq[(String, File)],
|
cache: Seq[(String, File)],
|
||||||
tmp: () => File,
|
tmp: () => File,
|
||||||
logger: Option[Files.Logger] = None
|
logger: Option[Files.Logger] = None,
|
||||||
|
concurrentDownloadCount: Int = Files.defaultConcurrentDownloadCount
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
lazy val defaultPool =
|
||||||
|
Executors.newFixedThreadPool(concurrentDownloadCount, Strategy.DefaultDaemonThreadFactory)
|
||||||
|
|
||||||
def file(
|
def file(
|
||||||
artifact: Artifact,
|
artifact: Artifact,
|
||||||
cachePolicy: CachePolicy
|
cachePolicy: CachePolicy
|
||||||
|
)(implicit
|
||||||
|
pool: ExecutorService = defaultPool
|
||||||
): EitherT[Task, String, File] = {
|
): EitherT[Task, String, File] = {
|
||||||
|
|
||||||
if (artifact.url.startsWith("file:///")) {
|
if (artifact.url.startsWith("file:///")) {
|
||||||
|
|
@ -95,6 +102,8 @@ case class Files(
|
||||||
|
|
||||||
object Files {
|
object Files {
|
||||||
|
|
||||||
|
val defaultConcurrentDownloadCount = 6
|
||||||
|
|
||||||
// FIXME This kind of side-effecting API is lame, we should aim at a more functional one.
|
// FIXME This kind of side-effecting API is lame, we should aim at a more functional one.
|
||||||
trait Logger {
|
trait Logger {
|
||||||
def foundLocally(f: File): Unit
|
def foundLocally(f: File): Unit
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue