Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be friendly to SBT plugins that also use URLHandlerRegistry.setDefault #183

Merged
merged 7 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ scala:
- 2.11.11
- 2.12.3

matrix:
include:
- scala: 2.12.3
jdk: oraclejdk9

script:
- sbt -Dfile.encoding=UTF8 -J-XX:ReservedCodeCacheSize=256M ";++$TRAVIS_SCALA_VERSION;mimaReportBinaryIssues;scalafmt::test;test:scalafmt::test;sbt:scalafmt::test;test"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ object EvictionWarning {
out += "Scala version was updated by one of library dependencies:"
out ++= (a.scalaEvictions flatMap { _.lines })
out += "To force scalaVersion, add the following:"
out += "\tivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }"
out += "\tscalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(true)))"
}

if (a.directEvictions.nonEmpty || a.transitiveEvictions.nonEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private[sbt] object ConvertResolver {
val overwriteWarning =
if (destination contains "-SNAPSHOT") s"Attempting to overwrite $destination"
else
"Attempting to overwrite $destination (non-SNAPSHOT)\n\tYou need to remove it from the cache manually to take effect."
s"Attempting to overwrite $destination (non-SNAPSHOT)\n\tYou need to remove it from the cache manually to take effect."
import org.apache.ivy.util.Message
Message.warn(overwriteWarning)
super.put(source, destination, true)
Expand Down
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
4 changes: 2 additions & 2 deletions ivy/src/test/scala/EvictionWarningSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class EvictionWarningSpec extends BaseIvySpecification {
"\t* org.scala-lang:scala-library:2.10.3 is selected over 2.10.2",
"",
"To force scalaVersion, add the following:",
"\tivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }",
"\tscalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(true)))",
"Run 'evicted' to see detailed eviction warnings"
)
}
Expand All @@ -109,7 +109,7 @@ class EvictionWarningSpec extends BaseIvySpecification {
"\t +- com.example:foo:0.1.0 (depends on 2.10.2)",
"",
"To force scalaVersion, add the following:",
"\tivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }",
"\tscalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(true)))",
"Run 'evicted' to see detailed eviction warnings"
)
}
Expand Down