Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 95 lines (77 sloc) 3.502 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
package sbt

final case class ScalaVersion(full: String, binary: String)

sealed trait CrossVersion
object CrossVersion
{
val TransitionScalaVersion = "2.10"
val TransitionSbtVersion = "0.12"

object Disabled extends CrossVersion { override def toString = "disabled" }
final class Binary(val remapVersion: String => String) extends CrossVersion {
override def toString = "Binary"
}
final class Full(val remapVersion: String => String) extends CrossVersion {
override def toString = "Full"
}

def full: CrossVersion = new Full(idFun)
def fullMapped(remapVersion: String => String): CrossVersion = new Full(remapVersion)

def binary: CrossVersion = new Binary(idFun)
def binaryMapped(remapVersion: String => String): CrossVersion = new Full(remapVersion)

private[this] def idFun[T]: T => T = x => x
def append(s: String): Option[String => String] = Some(x => crossName(x, s))

def apply(cross: CrossVersion, fullVersion: String, binaryVersion: String): Option[String => String] =
cross match
{
case Disabled => None
case b: Binary => append(b.remapVersion(binaryVersion))
case f: Full => append(f.remapVersion(fullVersion))
}

def apply(module: ModuleID, is: IvyScala): Option[String => String] =
CrossVersion(module.crossVersion, is.scalaFullVersion, is.scalaBinaryVersion)

def apply(module: ModuleID, is: Option[IvyScala]): Option[String => String] =
is flatMap { i => apply(module, i) }

def substituteCross(artifacts: Seq[Artifact], cross: Option[String => String]): Seq[Artifact] =
cross match {
case None => artifacts
case Some(is) => substituteCrossA(artifacts, cross)
}

def applyCross(s: String, fopt: Option[String => String]): String =
fopt match {
case None => s
case Some(fopt) => fopt(s)
}

def crossName(name: String, cross: String): String =
name + "_" + cross
def substituteCross(a: Artifact, cross: Option[String => String]): Artifact =
a.copy(name = applyCross(a.name, cross))
def substituteCrossA(as: Seq[Artifact], cross: Option[String => String]): Seq[Artifact] =
as.map(art => substituteCross(art, cross))

def apply(scalaFullVersion: String, scalaBinaryVersion: String): ModuleID => ModuleID = m =>
{
val cross = apply(m.crossVersion, scalaFullVersion, scalaBinaryVersion)
if(cross.isDefined)
m.copy(name = applyCross(m.name, cross), explicitArtifacts = substituteCrossA(m.explicitArtifacts, cross))
else
m
}

def isStable(v: String): Boolean = !v.contains("-")
def selectVersion(full: String, binary: String): String = if(isStable(full)) binary else full

val PartialVersion = """(\d+)\.(\d+)(?:\..+)?""".r
def partialVersion(s: String): Option[(Int,Int)] =
s match {
case PartialVersion(major, minor) => Some(major.toInt, minor.toInt)
case _ => None
}
private[this] def isNewer(major: Int, minor: Int, minMajor: Int, minMinor: Int): Boolean =
major > minMajor || (major == minMajor && minor >= minMinor)

def binaryScalaVersion(full: String): String = binaryVersion(full, TransitionScalaVersion)
def binarySbtVersion(full: String): String = binaryVersion(full, TransitionSbtVersion)
def binaryVersion(full: String, cutoff: String): String =
{
def sub(major: Int, minor: Int) = major + "." + minor
(partialVersion(full), partialVersion(cutoff)) match {
case (Some((major, minor)), None) => sub(major, minor)
case (Some((major, minor)), Some((minMajor, minMinor))) if isNewer(major, minor, minMajor, minMinor) => sub(major, minor)
case _ => full
}
}
}

Something went wrong with that request. Please try again.