mirror of https://github.com/sbt/sbt.git
Based on Ivy's behavior, bringing back approximation
I assumed 1.1+ should be treated as 1.+, but it seems like Ivy treats it more as “any version that starts with 1.1” including 1.10. Josh’s original implementation approximates this by making ranges for multiple digits, 1.1~1.2, 1.10~1.20, etc.
This commit is contained in:
parent
b812cdc916
commit
f99c5817f5
|
|
@ -210,17 +210,19 @@ class MakePom(val log: Logger) {
|
|||
}
|
||||
val startSym = Set(']', '[', '(')
|
||||
val stopSym = Set(']', '[', ')')
|
||||
val PlusPattern = """(.+)(\.\d*\+)""".r
|
||||
val DotPlusPattern = """(.+)\.\+""".r
|
||||
val DotNumPlusPattern = """(.+)\.(\d+)\+""".r
|
||||
val NumPlusPattern = """(\d+)\+""".r
|
||||
val maxDigit = 5
|
||||
try {
|
||||
revision match {
|
||||
case PlusPattern(base, tail) => plusRange(base)
|
||||
// There's no direct translation for a dynamic revision like "1+".
|
||||
// This is likely the build user misunderstanding the meaning of "+",
|
||||
// which means pick the latest in the version segment.
|
||||
// So if someone wanted (1.0 <= x), then it should be "[1.0)" or "1.+".
|
||||
// Technically speaking, "1+" should convert to "LATEST",
|
||||
// but that seems to be deprecated now, so picking the minimum version "0".
|
||||
case rev if rev endsWith "+" => "[0,)"
|
||||
case "+" => "[0,)"
|
||||
case DotPlusPattern(base) => plusRange(base)
|
||||
// This is a heuristic. Maven just doesn't support Ivy's notions of 1+, so
|
||||
// we assume version ranges never go beyond 5 siginificant digits.
|
||||
case NumPlusPattern(tail) => (0 until maxDigit).map(plusRange(tail, _)).mkString(",")
|
||||
case DotNumPlusPattern(base, tail) => (0 until maxDigit).map(plusRange(base + "." + tail, _)).mkString(",")
|
||||
case rev if rev endsWith "+" => sys.error(s"dynamic revision '$rev' cannot be translated to POM")
|
||||
case rev if startSym(rev(0)) && stopSym(rev(rev.length - 1)) =>
|
||||
val start = rev(0)
|
||||
val stop = rev(rev.length - 1)
|
||||
|
|
|
|||
|
|
@ -47,14 +47,27 @@ class MakePomSpec extends Specification {
|
|||
${convertTo("12.31.42.+", "[12.31.42,12.31.43)")}
|
||||
|
||||
1.1+ should
|
||||
${convertTo("1.1+", "[1,2)")}
|
||||
${convertTo("1.1+", "[1.1,1.2),[1.10,1.20),[1.100,1.200),[1.1000,1.2000),[1.10000,1.20000)")}
|
||||
|
||||
1+ should
|
||||
${convertTo("1+", "[0,)")}
|
||||
${convertTo("1+", "[1,2),[10,20),[100,200),[1000,2000),[10000,20000)")}
|
||||
|
||||
+ should
|
||||
${convertTo("+", "[0,)")}
|
||||
|
||||
foo+ should
|
||||
${beParsedAsError("foo+")}
|
||||
"""
|
||||
|
||||
val mp = new MakePom(ConsoleLogger())
|
||||
def convertTo(s: String, expected: String) =
|
||||
mp.makeDependencyVersion(s) must_== expected
|
||||
def beParsedAsError(s: String) =
|
||||
try {
|
||||
mp.makeDependencyVersion(s)
|
||||
failure
|
||||
} catch {
|
||||
case e: Throwable => success
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue