mirror of https://github.com/sbt/sbt.git
Better terminal output
This commit is contained in:
parent
66fff86f9b
commit
139525355a
|
|
@ -19,6 +19,7 @@ class TermDisplay(
|
|||
private val fallbackRefreshInterval = 1000
|
||||
|
||||
private val lock = new AnyRef
|
||||
private var currentHeight = 0
|
||||
private val t = new Thread("TermDisplay") {
|
||||
override def run() = lock.synchronized {
|
||||
|
||||
|
|
@ -60,7 +61,9 @@ class TermDisplay(
|
|||
}
|
||||
|
||||
|
||||
@tailrec def helper(lineCount: Int): Unit =
|
||||
@tailrec def helper(lineCount: Int): Unit = {
|
||||
currentHeight = lineCount
|
||||
|
||||
Option(q.poll(100L, TimeUnit.MILLISECONDS)) match {
|
||||
case None => helper(lineCount)
|
||||
case Some(Left(())) => // poison pill
|
||||
|
|
@ -100,6 +103,7 @@ class TermDisplay(
|
|||
Thread.sleep(refreshInterval)
|
||||
helper(downloads0.length)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@tailrec def fallbackHelper(previous: Set[String]): Unit =
|
||||
|
|
@ -153,6 +157,13 @@ class TermDisplay(
|
|||
}
|
||||
|
||||
def stop(): Unit = {
|
||||
for (_ <- 0 until currentHeight) {
|
||||
ansi.clearLine(2)
|
||||
ansi.down(1)
|
||||
}
|
||||
for (_ <- 0 until currentHeight) {
|
||||
ansi.up(1)
|
||||
}
|
||||
q.put(Left(()))
|
||||
lock.synchronized(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,7 +213,6 @@ class Helper(
|
|||
Some(new TermDisplay(new OutputStreamWriter(System.err)))
|
||||
else
|
||||
None
|
||||
logger.foreach(_.init())
|
||||
|
||||
val fetchs = cachePolicies.map(p =>
|
||||
Cache.fetch(caches, p, logger = logger, pool = pool)
|
||||
|
|
@ -246,6 +245,7 @@ class Helper(
|
|||
}
|
||||
}
|
||||
|
||||
logger.foreach(_.init())
|
||||
|
||||
val res = startRes
|
||||
.process
|
||||
|
|
@ -341,24 +341,26 @@ class Helper(
|
|||
Some(new TermDisplay(new OutputStreamWriter(System.err)))
|
||||
else
|
||||
None
|
||||
logger.foreach(_.init())
|
||||
|
||||
if (verbose0 >= 1 && artifacts.nonEmpty)
|
||||
println(s"Found ${artifacts.length} artifacts")
|
||||
|
||||
val tasks = artifacts.map(artifact =>
|
||||
(Cache.file(artifact, caches, cachePolicies.head, logger = logger, pool = pool) /: cachePolicies.tail)(
|
||||
_ orElse Cache.file(artifact, caches, _, logger = logger, pool = pool)
|
||||
).run.map(artifact.->)
|
||||
)
|
||||
def printTask = Task {
|
||||
if (verbose0 >= 1 && artifacts.nonEmpty)
|
||||
println(s"Found ${artifacts.length} artifacts")
|
||||
}
|
||||
val task = printTask.flatMap(_ => Task.gatherUnordered(tasks))
|
||||
|
||||
logger.foreach(_.init())
|
||||
|
||||
val task = Task.gatherUnordered(tasks)
|
||||
|
||||
logger.foreach(_.stop())
|
||||
|
||||
val results = task.run
|
||||
val errors = results.collect{case (artifact, -\/(err)) => artifact -> err }
|
||||
val files0 = results.collect{case (artifact, \/-(f)) => f }
|
||||
|
||||
logger.foreach(_.stop())
|
||||
|
||||
if (errors.nonEmpty) {
|
||||
println(s"${errors.size} error(s):")
|
||||
for ((artifact, error) <- errors) {
|
||||
|
|
|
|||
|
|
@ -251,16 +251,17 @@ object Tasks {
|
|||
|
||||
val pool = Executors.newFixedThreadPool(parallelDownloads, Strategy.DefaultDaemonThreadFactory)
|
||||
|
||||
val logger = new TermDisplay(
|
||||
def createLogger() = new TermDisplay(
|
||||
new OutputStreamWriter(System.err),
|
||||
fallbackMode = sys.env.get("COURSIER_NO_TERM").nonEmpty
|
||||
)
|
||||
logger.init()
|
||||
|
||||
val resLogger = createLogger()
|
||||
|
||||
val fetch = coursier.Fetch(
|
||||
repositories,
|
||||
Cache.fetch(caches, CachePolicy.LocalOnly, checksums = checksums, logger = Some(logger), pool = pool),
|
||||
Cache.fetch(caches, cachePolicy, checksums = checksums, logger = Some(logger), pool = pool)
|
||||
Cache.fetch(caches, CachePolicy.LocalOnly, checksums = checksums, logger = Some(resLogger), pool = pool),
|
||||
Cache.fetch(caches, cachePolicy, checksums = checksums, logger = Some(resLogger), pool = pool)
|
||||
)
|
||||
|
||||
def depsRepr(deps: Seq[(String, Dependency)]) =
|
||||
|
|
@ -290,6 +291,8 @@ object Tasks {
|
|||
for (depRepr <- depsRepr(currentProject.dependencies))
|
||||
errPrintln(s" $depRepr")
|
||||
|
||||
resLogger.init()
|
||||
|
||||
val res = startRes
|
||||
.process
|
||||
.run(fetch, maxIterations)
|
||||
|
|
@ -297,6 +300,7 @@ object Tasks {
|
|||
.leftMap(ex => throw new Exception(s"Exception during resolution", ex))
|
||||
.merge
|
||||
|
||||
resLogger.stop()
|
||||
|
||||
|
||||
if (!res.isDone)
|
||||
|
|
@ -366,13 +370,17 @@ object Tasks {
|
|||
case Some(cl) => res.classifiersArtifacts(cl)
|
||||
}
|
||||
|
||||
val artifactsLogger = createLogger()
|
||||
|
||||
val artifactFileOrErrorTasks = allArtifacts.toVector.map { a =>
|
||||
Cache.file(a, caches, cachePolicy, checksums = artifactsChecksums, logger = Some(logger), pool = pool).run.map((a, _))
|
||||
Cache.file(a, caches, cachePolicy, checksums = artifactsChecksums, logger = Some(artifactsLogger), pool = pool).run.map((a, _))
|
||||
}
|
||||
|
||||
if (verbosity >= 0)
|
||||
errPrintln(s"Fetching artifacts")
|
||||
|
||||
artifactsLogger.init()
|
||||
|
||||
val artifactFilesOrErrors = Task.gatherUnordered(artifactFileOrErrorTasks).attemptRun match {
|
||||
case -\/(ex) =>
|
||||
throw new Exception(s"Error while downloading / verifying artifacts", ex)
|
||||
|
|
@ -380,6 +388,8 @@ object Tasks {
|
|||
l.toMap
|
||||
}
|
||||
|
||||
artifactsLogger.stop()
|
||||
|
||||
if (verbosity >= 0)
|
||||
errPrintln(s"Fetching artifacts: done")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue