From dade161d3ecce46b6a891f72970a257827bed4a8 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 22 Feb 2016 22:54:24 +0100 Subject: [PATCH] Add --force option to the fetch CLI command, better error reporting --- .../scala-2.11/coursier/cli/Coursier.scala | 4 +- .../main/scala-2.11/coursier/cli/Helper.scala | 55 ++++++++++++------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/cli/src/main/scala-2.11/coursier/cli/Coursier.scala b/cli/src/main/scala-2.11/coursier/cli/Coursier.scala index 687069a06..30143a5fa 100644 --- a/cli/src/main/scala-2.11/coursier/cli/Coursier.scala +++ b/cli/src/main/scala-2.11/coursier/cli/Coursier.scala @@ -95,11 +95,13 @@ case class Fetch( @Help("Print java -cp compatible output") @Short("p") classpath: Boolean, + @Help("Fetch artifacts even if the resolution is errored") + force: Boolean, @Recurse common: CommonOptions ) extends CoursierCommand { - val helper = new Helper(common, remainingArgs) + val helper = new Helper(common, remainingArgs, ignoreErrors = force) val files0 = helper.fetch(sources = sources, javadoc = javadoc) diff --git a/cli/src/main/scala-2.11/coursier/cli/Helper.scala b/cli/src/main/scala-2.11/coursier/cli/Helper.scala index 132cba5a4..5f33b6955 100644 --- a/cli/src/main/scala-2.11/coursier/cli/Helper.scala +++ b/cli/src/main/scala-2.11/coursier/cli/Helper.scala @@ -59,7 +59,8 @@ object Util { class Helper( common: CommonOptions, rawDependencies: Seq[String], - printResultStdout: Boolean = false + printResultStdout: Boolean = false, + ignoreErrors: Boolean = false ) { import common._ import Helper.errPrintln @@ -236,25 +237,6 @@ class Helper( logger.foreach(_.stop()) - // FIXME Better to print all the messages related to the exit conditions below, then exit - // rather than exit at the first one - - exitIf(!res.isDone) { - errPrintln(s"Maximum number of iteration reached!") - sys.exit(1) - } - - exitIf(res.errors.nonEmpty) { - s"\nError:\n" + - res.errors.map { case (dep, errs) => - s" ${dep.module}:${dep.version}:\n${errs.map(" " + _.replace("\n", " \n")).mkString("\n")}" - }.mkString("\n") - } - - exitIf(res.conflicts.nonEmpty) { - s"\nConflict:\n${Print.dependenciesUnknownConfigs(res.conflicts.toVector, projCache)}" - } - val trDeps = res.minDependencies.toVector lazy val projCache = res.projectCache.mapValues { case (_, p) => p } @@ -268,6 +250,39 @@ class Helper( errPrintln(depsStr) } + var anyError = false + + if (!res.isDone) { + anyError = true + errPrintln("\nMaximum number of iterations reached!") + } + + if (res.errors.nonEmpty) { + anyError = true + errPrintln( + s"\nError:\n" + + res.errors.map { + case (dep, errs) => + s" ${dep.module}:${dep.version}:\n${errs.map(" " + _.replace("\n", " \n")).mkString("\n")}" + }.mkString("\n") + ) + } + + if (res.conflicts.nonEmpty) { + anyError = true + errPrintln( + s"\nConflict:\n" + + Print.dependenciesUnknownConfigs(res.conflicts.toVector, projCache) + ) + } + + if (anyError) { + if (ignoreErrors) + errPrintln("Ignoring errors") + else + sys.exit(1) + } + def fetch( sources: Boolean, javadoc: Boolean,