From 2dc37ab4bcca5fa229f405ea6ce97b7d6875ac14 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 20 Nov 2018 16:46:57 +0100 Subject: [PATCH] Take excludeDependency setting into account in sbt-lm-coursier --- .../lmcoursier/CoursierConfiguration.scala | 22 ++++++++----- .../src/main/contraband/lm-coursier.json | 6 ++++ .../CoursierDependencyResolution.scala | 31 ++++++++++++++---- .../exclude-dependencies/build.sbt | 0 .../exclude-dependencies/coursier | Bin .../exclude-dependencies/project/plugins.sbt | 0 .../src/main/scala/Main.scala | 0 .../exclude-dependencies/test | 0 .../sbtlmcoursier/LmCoursierPlugin.scala | 19 +++++++++-- 9 files changed, 60 insertions(+), 18 deletions(-) rename modules/sbt-coursier/src/sbt-test/{sbt-coursier-group-1 => shared-1}/exclude-dependencies/build.sbt (100%) rename modules/sbt-coursier/src/sbt-test/{sbt-coursier-group-1 => shared-1}/exclude-dependencies/coursier (100%) rename modules/sbt-coursier/src/sbt-test/{sbt-coursier-group-1 => shared-1}/exclude-dependencies/project/plugins.sbt (100%) rename modules/sbt-coursier/src/sbt-test/{sbt-coursier-group-1 => shared-1}/exclude-dependencies/src/main/scala/Main.scala (100%) rename modules/sbt-coursier/src/sbt-test/{sbt-coursier-group-1 => shared-1}/exclude-dependencies/test (100%) diff --git a/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala b/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala index 3b00506cc..7c6f36d1f 100644 --- a/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala +++ b/modules/lm-coursier/src/main/contraband-scala/coursier/lmcoursier/CoursierConfiguration.scala @@ -14,22 +14,23 @@ final class CoursierConfiguration private ( val sbtScalaOrganization: Option[String], val sbtScalaVersion: Option[String], val sbtScalaJars: Vector[java.io.File], - val interProjectDependencies: Vector[coursier.core.Project]) extends Serializable { + val interProjectDependencies: Vector[coursier.core.Project], + val excludeDependencies: Vector[(String, String)]) extends Serializable { - private def this() = this(None, sbt.librarymanagement.Resolver.defaults, Vector.empty, true, 6, 100, None, None, Vector.empty, Vector.empty) + private def this() = this(None, sbt.librarymanagement.Resolver.defaults, Vector.empty, true, 6, 100, None, None, Vector.empty, Vector.empty, Vector.empty) override def equals(o: Any): Boolean = o match { - case x: CoursierConfiguration => (this.log == x.log) && (this.resolvers == x.resolvers) && (this.otherResolvers == x.otherResolvers) && (this.reorderResolvers == x.reorderResolvers) && (this.parallelDownloads == x.parallelDownloads) && (this.maxIterations == x.maxIterations) && (this.sbtScalaOrganization == x.sbtScalaOrganization) && (this.sbtScalaVersion == x.sbtScalaVersion) && (this.sbtScalaJars == x.sbtScalaJars) && (this.interProjectDependencies == x.interProjectDependencies) + case x: CoursierConfiguration => (this.log == x.log) && (this.resolvers == x.resolvers) && (this.otherResolvers == x.otherResolvers) && (this.reorderResolvers == x.reorderResolvers) && (this.parallelDownloads == x.parallelDownloads) && (this.maxIterations == x.maxIterations) && (this.sbtScalaOrganization == x.sbtScalaOrganization) && (this.sbtScalaVersion == x.sbtScalaVersion) && (this.sbtScalaJars == x.sbtScalaJars) && (this.interProjectDependencies == x.interProjectDependencies) && (this.excludeDependencies == x.excludeDependencies) case _ => false } override def hashCode: Int = { - 37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "coursier.lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + otherResolvers.##) + reorderResolvers.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + 37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + "coursier.lmcoursier.CoursierConfiguration".##) + log.##) + resolvers.##) + otherResolvers.##) + reorderResolvers.##) + parallelDownloads.##) + maxIterations.##) + sbtScalaOrganization.##) + sbtScalaVersion.##) + sbtScalaJars.##) + interProjectDependencies.##) + excludeDependencies.##) } override def toString: String = { - "CoursierConfiguration(" + log + ", " + resolvers + ", " + otherResolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ")" + "CoursierConfiguration(" + log + ", " + resolvers + ", " + otherResolvers + ", " + reorderResolvers + ", " + parallelDownloads + ", " + maxIterations + ", " + sbtScalaOrganization + ", " + sbtScalaVersion + ", " + sbtScalaJars + ", " + interProjectDependencies + ", " + excludeDependencies + ")" } - private[this] def copy(log: Option[xsbti.Logger] = log, resolvers: Vector[sbt.librarymanagement.Resolver] = resolvers, otherResolvers: Vector[sbt.librarymanagement.Resolver] = otherResolvers, reorderResolvers: Boolean = reorderResolvers, parallelDownloads: Int = parallelDownloads, maxIterations: Int = maxIterations, sbtScalaOrganization: Option[String] = sbtScalaOrganization, sbtScalaVersion: Option[String] = sbtScalaVersion, sbtScalaJars: Vector[java.io.File] = sbtScalaJars, interProjectDependencies: Vector[coursier.core.Project] = interProjectDependencies): CoursierConfiguration = { - new CoursierConfiguration(log, resolvers, otherResolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies) + private[this] def copy(log: Option[xsbti.Logger] = log, resolvers: Vector[sbt.librarymanagement.Resolver] = resolvers, otherResolvers: Vector[sbt.librarymanagement.Resolver] = otherResolvers, reorderResolvers: Boolean = reorderResolvers, parallelDownloads: Int = parallelDownloads, maxIterations: Int = maxIterations, sbtScalaOrganization: Option[String] = sbtScalaOrganization, sbtScalaVersion: Option[String] = sbtScalaVersion, sbtScalaJars: Vector[java.io.File] = sbtScalaJars, interProjectDependencies: Vector[coursier.core.Project] = interProjectDependencies, excludeDependencies: Vector[(String, String)] = excludeDependencies): CoursierConfiguration = { + new CoursierConfiguration(log, resolvers, otherResolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies) } def withLog(log: Option[xsbti.Logger]): CoursierConfiguration = { copy(log = log) @@ -70,10 +71,13 @@ final class CoursierConfiguration private ( def withInterProjectDependencies(interProjectDependencies: Vector[coursier.core.Project]): CoursierConfiguration = { copy(interProjectDependencies = interProjectDependencies) } + def withExcludeDependencies(excludeDependencies: Vector[(String, String)]): CoursierConfiguration = { + copy(excludeDependencies = excludeDependencies) + } } object CoursierConfiguration { def apply(): CoursierConfiguration = new CoursierConfiguration() - def apply(log: Option[xsbti.Logger], resolvers: Vector[sbt.librarymanagement.Resolver], otherResolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: Option[String], sbtScalaVersion: Option[String], sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project]): CoursierConfiguration = new CoursierConfiguration(log, resolvers, otherResolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies) - def apply(log: xsbti.Logger, resolvers: Vector[sbt.librarymanagement.Resolver], otherResolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: String, sbtScalaVersion: String, sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project]): CoursierConfiguration = new CoursierConfiguration(Option(log), resolvers, otherResolvers, reorderResolvers, parallelDownloads, maxIterations, Option(sbtScalaOrganization), Option(sbtScalaVersion), sbtScalaJars, interProjectDependencies) + def apply(log: Option[xsbti.Logger], resolvers: Vector[sbt.librarymanagement.Resolver], otherResolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: Option[String], sbtScalaVersion: Option[String], sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project], excludeDependencies: Vector[(String, String)]): CoursierConfiguration = new CoursierConfiguration(log, resolvers, otherResolvers, reorderResolvers, parallelDownloads, maxIterations, sbtScalaOrganization, sbtScalaVersion, sbtScalaJars, interProjectDependencies, excludeDependencies) + def apply(log: xsbti.Logger, resolvers: Vector[sbt.librarymanagement.Resolver], otherResolvers: Vector[sbt.librarymanagement.Resolver], reorderResolvers: Boolean, parallelDownloads: Int, maxIterations: Int, sbtScalaOrganization: String, sbtScalaVersion: String, sbtScalaJars: Vector[java.io.File], interProjectDependencies: Vector[coursier.core.Project], excludeDependencies: Vector[(String, String)]): CoursierConfiguration = new CoursierConfiguration(Option(log), resolvers, otherResolvers, reorderResolvers, parallelDownloads, maxIterations, Option(sbtScalaOrganization), Option(sbtScalaVersion), sbtScalaJars, interProjectDependencies, excludeDependencies) } diff --git a/modules/lm-coursier/src/main/contraband/lm-coursier.json b/modules/lm-coursier/src/main/contraband/lm-coursier.json index 168fab4eb..323a700dc 100644 --- a/modules/lm-coursier/src/main/contraband/lm-coursier.json +++ b/modules/lm-coursier/src/main/contraband/lm-coursier.json @@ -66,6 +66,12 @@ "type": "coursier.core.Project*", "default": "Vector.empty", "since": "0.0.1" + }, + { + "name": "excludeDependencies", + "type": "(String, String)*", + "default": "Vector.empty", + "since": "0.0.1" } ] } diff --git a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala index a166274e6..32c77e806 100644 --- a/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/coursier/lmcoursier/CoursierDependencyResolution.scala @@ -2,8 +2,8 @@ package coursier.lmcoursier import java.io.{File, OutputStreamWriter} -import _root_.coursier.{Artifact, Cache, CachePolicy, FileError, Organization, Project, Resolution, TermDisplay, organizationString} -import _root_.coursier.core.Configuration +import _root_.coursier.{Artifact, Cache, CachePolicy, FileError, Organization, Resolution, TermDisplay, organizationString} +import _root_.coursier.core.{Configuration, ModuleName} import _root_.coursier.ivy.IvyRepository import sbt.internal.librarymanagement.IvySbt import sbt.librarymanagement._ @@ -19,6 +19,14 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen else conf.resolvers + private lazy val excludeDependencies = conf + .excludeDependencies + .map { + case (strOrg, strName) => + (Organization(strOrg), ModuleName(strName)) + } + .toSet + def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): CoursierModuleDescriptor = CoursierModuleDescriptor(moduleSetting, conf) @@ -89,11 +97,20 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen val internalRepositories = globalPluginsRepos :+ interProjectRepo - val dependencies = module0.dependencies.flatMap { d => - // crossVersion already taken into account, wiping it here - val d0 = d.withCrossVersion(CrossVersion.Disabled()) - FromSbt.dependencies(d0, sv, sbv) - } + val dependencies = module0 + .dependencies + .flatMap { d => + // crossVersion already taken into account, wiping it here + val d0 = d.withCrossVersion(CrossVersion.Disabled()) + FromSbt.dependencies(d0, sv, sbv) + } + .map { + case (config, dep) => + val dep0 = dep.copy( + exclusions = dep.exclusions ++ excludeDependencies + ) + (config, dep0) + } val configGraphs = Inputs.ivyGraphs( Inputs.configExtends(module0.configurations) diff --git a/modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/build.sbt similarity index 100% rename from modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/build.sbt rename to modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/build.sbt diff --git a/modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/coursier b/modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/coursier similarity index 100% rename from modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/coursier rename to modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/coursier diff --git a/modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/project/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/project/plugins.sbt similarity index 100% rename from modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/project/plugins.sbt rename to modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/project/plugins.sbt diff --git a/modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/src/main/scala/Main.scala b/modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/src/main/scala/Main.scala similarity index 100% rename from modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/src/main/scala/Main.scala rename to modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/src/main/scala/Main.scala diff --git a/modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/test b/modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/test similarity index 100% rename from modules/sbt-coursier/src/sbt-test/sbt-coursier-group-1/exclude-dependencies/test rename to modules/sbt-coursier/src/sbt-test/shared-1/exclude-dependencies/test diff --git a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala index 3aa77bb3b..005452187 100644 --- a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala +++ b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala @@ -1,10 +1,10 @@ package coursier.sbtlmcoursier -import coursier.lmcoursier.{CoursierConfiguration, CoursierDependencyResolution} +import coursier.lmcoursier.{CoursierConfiguration, CoursierDependencyResolution, Inputs} import coursier.sbtcoursiershared.SbtCoursierShared import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey} import sbt.KeyRanks.DTask -import sbt.Keys.{dependencyResolution, fullResolvers, otherResolvers, streams} +import sbt.Keys.{dependencyResolution, excludeDependencies, fullResolvers, otherResolvers, scalaBinaryVersion, scalaVersion, streams} import sbt.librarymanagement.DependencyResolution object LmCoursierPlugin extends AutoPlugin { @@ -34,12 +34,27 @@ object LmCoursierPlugin extends AutoPlugin { Def.task { val (rs, other) = (fullResolvers.value.toVector, otherResolvers.value.toVector) val interProjectDependencies = coursierInterProjectDependencies.value + val excludeDeps = Inputs.exclusions( + excludeDependencies.value, + scalaVersion.value, + scalaBinaryVersion.value, + streams.value.log + ) val s = streams.value Classpaths.warnResolversConflict(rs ++: other, s.log) CoursierConfiguration() .withResolvers(rs) .withOtherResolvers(other) .withInterProjectDependencies(interProjectDependencies.toVector) + .withExcludeDependencies( + excludeDeps + .toVector + .sorted + .map { + case (o, n) => + (o.value, n.value) + } + ) .withLog(s.log) } private def mkDependencyResolution: Def.Initialize[Task[DependencyResolution]] =