mirror of https://github.com/sbt/sbt.git
Support resolving the latest sub-revision of a module
Components of revisions are separated by dots or hyphens. In case you "end the revision with a `+`" (see [1]), the latest sub-revision of the dependency module should be selected when resolving dependencies. Accept revisions such as "1.2+" or "1.2.+" and "1.2.3-+". Fixes #424. [1]: http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html
This commit is contained in:
parent
f6493a2d5a
commit
2851f7d364
|
|
@ -11,23 +11,28 @@ object Parse {
|
||||||
else Some(Version(trimmed))
|
else Some(Version(trimmed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches revisions with a '+' appended, e.g. "1.2.+", "1.2+" or "1.2.3-+"
|
||||||
|
private val latestSubRevision = "(.*[^.-])[.-]?[+]".r
|
||||||
|
|
||||||
def ivyLatestSubRevisionInterval(s: String): Option[VersionInterval] =
|
def ivyLatestSubRevisionInterval(s: String): Option[VersionInterval] =
|
||||||
if (s.endsWith(".+")) {
|
s match {
|
||||||
for {
|
case latestSubRevision(prefix) =>
|
||||||
from <- version(s.stripSuffix(".+"))
|
for {
|
||||||
if from.rawItems.nonEmpty
|
from <- version(prefix)
|
||||||
last <- Some(from.rawItems.last).collect { case n: Version.Numeric => n }
|
if from.rawItems.nonEmpty
|
||||||
// a bit loose, but should do the job
|
last <- Some(from.rawItems.last).collect { case n: Version.Numeric => n }
|
||||||
if from.repr.endsWith(last.repr)
|
// a bit loose, but should do the job
|
||||||
// appending -a1 to the next version, so has not to include things like
|
if from.repr.endsWith(last.repr)
|
||||||
// nextVersion-RC1 in the interval - nothing like nextVersion* should be included
|
// appending -a1 to the next version, so has not to include things like
|
||||||
to <- version(from.repr.stripSuffix(last.repr) + last.next.repr + "-a1")
|
// nextVersion-RC1 in the interval - nothing like nextVersion* should be included
|
||||||
// the contrary would mean something went wrong in the loose substitution above
|
to <- version(from.repr.stripSuffix(last.repr) + last.next.repr + "-a1")
|
||||||
if from.rawItems.init == to.rawItems.dropRight(2).init
|
// the contrary would mean something went wrong in the loose substitution above
|
||||||
if to.rawItems.takeRight(2) == Seq(Version.Literal("a"), Version.Number(1))
|
if from.rawItems.init == to.rawItems.dropRight(2).init
|
||||||
} yield VersionInterval(Some(from), Some(to), fromIncluded = true, toIncluded = false)
|
if to.rawItems.takeRight(2) == Seq(Version.Literal("a"), Version.Number(1))
|
||||||
} else
|
} yield VersionInterval(Some(from), Some(to), fromIncluded = true, toIncluded = false)
|
||||||
None
|
case _ =>
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
def versionInterval(s: String): Option[VersionInterval] = {
|
def versionInterval(s: String): Option[VersionInterval] = {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ object VersionConstraintTests extends TestSuite {
|
||||||
val c0 = Parse.versionConstraint("(,1.2]")
|
val c0 = Parse.versionConstraint("(,1.2]")
|
||||||
assert(c0 == Some(VersionConstraint.interval(VersionInterval(None, Some(Version("1.2")), false, true))))
|
assert(c0 == Some(VersionConstraint.interval(VersionInterval(None, Some(Version("1.2")), false, true))))
|
||||||
}
|
}
|
||||||
|
'latestSubRevision{
|
||||||
|
val c0 = Parse.versionConstraint("1.2.3-+")
|
||||||
|
assert(c0 == Some(VersionConstraint.interval(VersionInterval(Some(Version("1.2.3")), Some(Version("1.2.4-a1")), true, false))))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
'repr{
|
'repr{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue