From 78a6a0038cf0429fac308e9d499c8392829dcc09 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Fri, 1 Sep 2023 15:56:23 +0200 Subject: [PATCH] Add withAddedResolvers to DependencyResolutionInterface --- .../librarymanagement/DependencyResolution.scala | 12 ++++++++++++ .../LibraryManagementInterface.scala | 10 ++++++++++ .../ivy/IvyDependencyResolution.scala | 13 +++++++++++++ 3 files changed, 35 insertions(+) diff --git a/core/src/main/scala/sbt/librarymanagement/DependencyResolution.scala b/core/src/main/scala/sbt/librarymanagement/DependencyResolution.scala index 1f2b37a2..1259a899 100644 --- a/core/src/main/scala/sbt/librarymanagement/DependencyResolution.scala +++ b/core/src/main/scala/sbt/librarymanagement/DependencyResolution.scala @@ -198,6 +198,18 @@ class DependencyResolution private[sbt] (lmEngine: DependencyResolutionInterface } } + /** + * Returns a new copy of DependencyResolutionInterface which contains the added resolvers. + * Useful for when you have resolvers that are outside the context of an sbt scope/project + * (i.e. a standalone setting) + * + * @param resolvers The resolvers to add + * @param log The logger + * @return A copy of DependencyResolutionInterface which contains the added resolvers + */ + def withAddedResolvers(resolvers: Seq[Resolver], log: Logger): DependencyResolutionInterface = + lmEngine.withAddedResolvers(resolvers, log) + protected def directDependenciesNames(module: ModuleDescriptor): String = (module.directDependencies map { case mID: ModuleID => import mID._ diff --git a/core/src/main/scala/sbt/librarymanagement/LibraryManagementInterface.scala b/core/src/main/scala/sbt/librarymanagement/LibraryManagementInterface.scala index cdca4a8d..a4402c05 100644 --- a/core/src/main/scala/sbt/librarymanagement/LibraryManagementInterface.scala +++ b/core/src/main/scala/sbt/librarymanagement/LibraryManagementInterface.scala @@ -32,6 +32,16 @@ trait DependencyResolutionInterface { uwconfig: UnresolvedWarningConfiguration, log: Logger ): Either[UnresolvedWarning, UpdateReport] + + /** + * Returns a new copy of DependencyResolutionInterface which contains the added resolvers. + * Useful for when you have resolvers that are outside the context of an sbt scope/project + * (i.e. a standalone setting) + * @param resolvers The resolvers to add + * @param log The logger + * @return A copy of DependencyResolutionInterface which contains the added resolvers + */ + def withAddedResolvers(resolvers: Seq[Resolver], log: Logger): DependencyResolutionInterface } /** diff --git a/ivy/src/main/scala/sbt/librarymanagement/ivy/IvyDependencyResolution.scala b/ivy/src/main/scala/sbt/librarymanagement/ivy/IvyDependencyResolution.scala index 3f5aedac..0bbb52d9 100644 --- a/ivy/src/main/scala/sbt/librarymanagement/ivy/IvyDependencyResolution.scala +++ b/ivy/src/main/scala/sbt/librarymanagement/ivy/IvyDependencyResolution.scala @@ -21,6 +21,19 @@ class IvyDependencyResolution private[sbt] (val ivySbt: IvySbt) ): Either[UnresolvedWarning, UpdateReport] = IvyActions.updateEither(toModule(module), configuration, uwconfig, log) + override def withAddedResolvers( + resolvers: Seq[Resolver], + log: Logger + ): IvyDependencyResolution = { + val newConfiguration = ivySbt.configuration match { + case configuration: ExternalIvyConfiguration => + configuration.withExtraResolvers(configuration.extraResolvers ++ resolvers) + case configuration: InlineIvyConfiguration => + configuration.withResolvers(configuration.resolvers ++ resolvers) + } + new IvyDependencyResolution(new IvySbt(newConfiguration)) + } + private[sbt] def toModule(module: ModuleDescriptor): Module = module match { case m: Module @unchecked => m