From 8330d164316540b4b6aba89b5833a0c96a9035e9 Mon Sep 17 00:00:00 2001 From: Tim Underwood Date: Wed, 22 Nov 2017 10:48:59 -0800 Subject: [PATCH] Be friendly to SBT plugins that also use URLHandlerRegistry.setDefault Other plugins (for example: https://github.com/frugalmechanic/fm-sbt-s3-resolver) also make use of the URLHandlerRegistry.setDefault mechanism to register handlers for other protocols (e.g. "s3"). This change makes it so that SBT will only register the http/https protocols and will preserve any other protocol handlers that have already been registered. --- .../sbt/internal/librarymanagement/Ivy.scala | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala b/ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala index c2b5b6cfb..95c4d3db2 100644 --- a/ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala +++ b/ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala @@ -80,16 +80,29 @@ final class IvySbt(val configuration: IvyConfiguration) { self => } private lazy val basicUrlHandler: URLHandler = new BasicURLHandler - private lazy val gigahorseUrlHandler: URLHandler = { - val dispatcher = new URLHandlerDispatcher - val handler = new GigahorseUrlHandler - dispatcher.setDownloader("http", handler) - dispatcher.setDownloader("https", handler) - dispatcher - } + private lazy val gigahorseUrlHandler: URLHandler = new GigahorseUrlHandler + private lazy val settings: IvySettings = { - if (configuration.updateOptions.gigahorse) URLHandlerRegistry.setDefault(gigahorseUrlHandler) - else URLHandlerRegistry.setDefault(basicUrlHandler) + val dispatcher: URLHandlerDispatcher = URLHandlerRegistry.getDefault match { + // If the default is already a URLHandlerDispatcher then just use that + case disp: URLHandlerDispatcher => disp + + // Otherwise wrap the existing URLHandler in a URLHandlerDispatcher + // while retaining the existing URLHandler as the default. + case default => + val disp: URLHandlerDispatcher = new URLHandlerDispatcher() + disp.setDefault(default) + URLHandlerRegistry.setDefault(disp) + disp + } + + val urlHandler: URLHandler = if (configuration.updateOptions.gigahorse) gigahorseUrlHandler else basicUrlHandler + + // Only set the urlHandler for the http/https protocols so we do not conflict with any other plugins + // that might register other protocol handlers. + // For example https://github.com/frugalmechanic/fm-sbt-s3-resolver registers "s3" + dispatcher.setDownloader("http", urlHandler) + dispatcher.setDownloader("https", urlHandler) val is = new IvySettings is.setCircularDependencyStrategy(