Skip to content

Commit

Permalink
Be friendly to SBT plugins that also use URLHandlerRegistry.setDefault
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tpunder committed Nov 22, 2017
1 parent 163e8bf commit 8330d16
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8330d16

Please sign in to comment.