Skip to content

Commit

Permalink
Merge pull request #183 from tpunder/fm-sbt-s3-resolver-conflict-fix
Browse files Browse the repository at this point in the history
Be friendly to SBT plugins that also use URLHandlerRegistry.setDefault
  • Loading branch information
eed3si9n authored Nov 24, 2017
2 parents 9e0d9dd + 8330d16 commit 50d024a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
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

0 comments on commit 50d024a

Please sign in to comment.