diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/ToSbt.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/ToSbt.scala index 7ac41ac6d..2d6bb1748 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/ToSbt.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/ToSbt.scala @@ -254,7 +254,7 @@ object ToSbt { } UpdateReport( - new File("."), + new File("."), // dummy value configReports.toVector, UpdateStats(-1L, -1L, -1L, cached = false), Map.empty diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateParams.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateParams.scala index 7700a75dd..71c780449 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateParams.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateParams.scala @@ -15,4 +15,44 @@ final case class UpdateParams( ignoreArtifactErrors: Boolean, includeSignatures: Boolean, sbtBootJarOverrides: Map[(Module, String), File] -) +) { + + lazy val artifactFiles = artifacts.collect { + case (artifact, Right(file)) => + artifact -> file + } + + // can be non empty only if ignoreArtifactErrors is true or some optional artifacts are not found + lazy val erroredArtifacts = artifacts + .collect { + case (artifact, Left(_)) => + artifact + } + .toSet + + def artifactFileOpt( + module: Module, + version: String, + attributes: Attributes, + artifact: Artifact + ): Option[File] = { + + // Under some conditions, SBT puts the scala JARs of its own classpath + // in the application classpath. Ensuring we return SBT's jars rather than + // JARs from the coursier cache, so that a same JAR doesn't land twice in the + // application classpath (once via SBT jars, once via coursier cache). + val fromBootJars = + if (attributes.classifier.isEmpty && attributes.`type` == Type.jar) + sbtBootJarOverrides.get((module, version)) + else + None + + val res = fromBootJars.orElse(artifactFiles.get(artifact)) + + if (res.isEmpty && !erroredArtifacts(artifact)) + sys.error(s"${artifact.url} not downloaded (should not happen)") + + res + } + +} diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateRun.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateRun.scala index 7ea5a1b78..8ddfe312f 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateRun.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/UpdateRun.scala @@ -1,7 +1,5 @@ package coursier.lmcoursier -import java.io.File - import coursier.core.Resolution.ModuleVersion import coursier.core._ import coursier.util.Print @@ -10,35 +8,6 @@ import sbt.util.Logger object UpdateRun { - private def artifactFileOpt( - sbtBootJarOverrides: Map[(Module, String), File], - artifactFiles: Map[Artifact, File], - erroredArtifacts: Set[Artifact] - )( - module: Module, - version: String, - attributes: Attributes, - artifact: Artifact - ): Option[File] = { - - // Under some conditions, SBT puts the scala JARs of its own classpath - // in the application classpath. Ensuring we return SBT's jars rather than - // JARs from the coursier cache, so that a same JAR doesn't land twice in the - // application classpath (once via SBT jars, once via coursier cache). - val fromBootJars = - if (attributes.classifier.isEmpty && attributes.`type` == Type.jar) - sbtBootJarOverrides.get((module, version)) - else - None - - val res = fromBootJars.orElse(artifactFiles.get(artifact)) - - if (res.isEmpty && !erroredArtifacts(artifact)) - sys.error(s"${artifact.url} not downloaded (should not happen)") - - res - } - // Move back to coursier.util (in core module) after 1.0? private def allDependenciesByConfig( res: Map[Configuration, Resolution], @@ -114,11 +83,6 @@ object UpdateRun { log.info(repr.split('\n').map(" " + _).mkString("\n")) } - val artifactFiles = params.artifacts.collect { - case (artifact, Right(file)) => - artifact -> file - } - val artifactErrors = params .artifacts .toVector @@ -127,26 +91,13 @@ object UpdateRun { a -> err } - // can be non empty only if ignoreArtifactErrors is true or some optional artifacts are not found - val erroredArtifacts = params - .artifacts - .collect { - case (artifact, Left(_)) => - artifact - } - .toSet - def report = ToSbt.updateReport( depsByConfig, configResolutions, params.configs, params.classifiers, - artifactFileOpt( - params.sbtBootJarOverrides, - artifactFiles, - erroredArtifacts - ), + params.artifactFileOpt, log, includeSignatures = params.includeSignatures ) diff --git a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala index e23b30353..339f18c2c 100644 --- a/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala +++ b/modules/sbt-coursier-shared/src/main/scala/coursier/sbtcoursiershared/InputsTasks.scala @@ -1,7 +1,5 @@ package coursier.sbtcoursiershared -import java.net.URL - import coursier.core._ import coursier.lmcoursier._ import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._