Merge pull request #658 from coursier/topic/cross-version-patch

Fix MatchError when using cross version patch with sbt 1.0
This commit is contained in:
Alexandre Archambault 2017-09-20 02:00:19 +02:00 committed by GitHub
commit 0b5b2f25f2
8 changed files with 47 additions and 27 deletions

View File

@ -18,10 +18,6 @@ object SbtCompatibility {
type IvySbt = sbt.IvySbt
type Binary = sbt.CrossVersion.Binary
type Disabled = sbt.CrossVersion.Disabled.type
type Full = sbt.CrossVersion.Full
implicit class ModuleIDOps(val id: sbt.ModuleID) extends AnyVal {
def withConfigurations(configurations: Option[String]): sbt.ModuleID =
id.copy(configurations = configurations)

View File

@ -16,20 +16,6 @@ object SbtCompatibility {
type IvySbt = sbt.internal.librarymanagement.IvySbt
type Binary = sbt.librarymanagement.Binary
type Disabled = sbt.librarymanagement.Disabled
type Full = sbt.librarymanagement.Full
implicit class BinaryOps(private val binary: Binary) extends AnyVal {
def remapVersion(scalaBinaryVersion: String): String =
binary.prefix + scalaBinaryVersion + binary.suffix
}
implicit class FullOps(private val full: Full) extends AnyVal {
def remapVersion(scalaVersion: String): String =
full.prefix + scalaVersion + full.suffix
}
def needsIvyXmlLocal = sbt.Keys.publishLocalConfiguration
def needsIvyXml = sbt.Keys.publishConfiguration

View File

@ -25,11 +25,9 @@ object FromSbt {
crossVersion: CrossVersion,
scalaVersion: => String,
scalaBinaryVersion: => String
): String = crossVersion match {
case _: Disabled => name
case f: Full => name + "_" + f.remapVersion(scalaVersion)
case b: Binary => name + "_" + b.remapVersion(scalaBinaryVersion)
}
): String =
CrossVersion(crossVersion, scalaVersion, scalaBinaryVersion)
.fold(name)(_(name))
def attributes(attr: Map[String, String]): Map[String, String] =
attr.map { case (k, v) =>

View File

@ -221,9 +221,25 @@ object ToSbt {
includeSignatures = includeSignatures
)
val reports0 =
if (subRes.rootDependencies.size == 1) {
// quick hack ensuring the module for the only root dependency
// appears first in the update report, see https://github.com/coursier/coursier/issues/650
val dep = subRes.rootDependencies.head
val (_, proj) = subRes.projectCache(dep.moduleVersion)
val mod = ToSbt.moduleId(dep, proj.properties.toMap)
val (main, other) = reports.partition { r =>
r.module.organization == mod.organization &&
r.module.name == mod.name &&
r.module.crossVersion == mod.crossVersion
}
main.toVector ++ other.toVector
} else
reports.toVector
sbt.ConfigurationReport(
ConfigRef(config),
reports.toVector,
reports0,
Vector()
)
}

View File

@ -1,9 +1,10 @@
import Compatibility._
scalaVersion := "2.12.2-bin-typelevel-4"
scalaOrganization := "org.typelevel"
scalacOptions += "-Yinduction-heuristics"
libraryDependencies ++= Seq(
"com.47deg" %% "freestyle" % "0.1.0",
// CrossVersion.patch not available in sbt 0.13.8
compilerPlugin("org.scalamacros" % "paradise_2.12.2" % "2.1.0")
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.patch)
)

View File

@ -0,0 +1,19 @@
object Compatibility {
// patch method not available in sbt 0.13.8
implicit class CrossVersionOps(val companion: sbt.CrossVersion.type) extends AnyVal {
def patch: sbt.CrossVersion = new sbt.CrossVersion.Full(patchFun)
}
// adapted from sbt.CrossVersion from the sbt 0.13.16 sources
private val BinCompatV = """(\d+)\.(\d+)\.(\d+)(-\w+)??-bin(-.*)?""".r
private def patchFun(fullVersion: String): String =
fullVersion match {
case BinCompatV(x, y, z, w, _) => s"""$x.$y.$z${if (w == null) "" else w}"""
case other => other
}
}

View File

@ -774,7 +774,10 @@ abstract class CentralTests extends TestSuite {
val mod = Module("org.webjars.bower", "dgrid")
val ver = "1.0.0"
* - resolutionCheck(mod, ver)
* - {
if (isActualCentral) // if false, the tests rely on things straight from Central, which can be updated sometimes
resolutionCheck(mod, ver)
}
}
'dependencyManagementScopeOverriding - {