Accept single version interval syntax

Fixes https://github.com/alexarchambault/coursier/issues/310
This commit is contained in:
Alexandre Archambault 2016-08-04 17:42:16 -04:00
parent 3a79f0a924
commit f61a258574
No known key found for this signature in database
GPG Key ID: 14640A6839C263A9
4 changed files with 73 additions and 11 deletions

View File

@ -29,17 +29,32 @@ object Parse {
None
def versionInterval(s: String): Option[VersionInterval] = {
def parseBounds(fromIncluded: Boolean, toIncluded: Boolean, s: String) = {
val commaIdx = s.indexOf(',')
if (commaIdx >= 0) {
val strFrom = s.take(commaIdx)
val strTo = s.drop(commaIdx + 1)
for {
from <- if (strFrom.isEmpty) Some(None) else version(strFrom).map(Some(_))
to <- if (strTo.isEmpty) Some(None) else version(strTo).map(Some(_))
} yield VersionInterval(from.filterNot(_.isEmpty), to.filterNot(_.isEmpty), fromIncluded, toIncluded)
} else if (s.nonEmpty && fromIncluded && toIncluded)
for (v <- version(s) if !v.isEmpty)
yield VersionInterval(Some(v), Some(v), fromIncluded, toIncluded)
else
None
}
for {
fromIncluded <- if (s.startsWith("[")) Some(true) else if (s.startsWith("(")) Some(false) else None
toIncluded <- if (s.endsWith("]")) Some(true) else if (s.endsWith(")")) Some(false) else None
s0 = s.drop(1).dropRight(1)
commaIdx = s0.indexOf(',')
if commaIdx >= 0
strFrom = s0.take(commaIdx)
strTo = s0.drop(commaIdx + 1)
from <- if (strFrom.isEmpty) Some(None) else version(strFrom).map(Some(_))
to <- if (strTo.isEmpty) Some(None) else version(strTo).map(Some(_))
} yield VersionInterval(from.filterNot(_.isEmpty), to.filterNot(_.isEmpty), fromIncluded, toIncluded)
itv <- parseBounds(fromIncluded, toIncluded, s0)
} yield itv
}
def versionConstraint(s: String): Option[VersionConstraint] = {

View File

@ -0,0 +1,12 @@
com.google.code.findbugs:jsr305:3.0.0:compile
com.google.guava:guava:19.0:compile
io.grpc:grpc-core:0.14.1:compile
io.grpc:grpc-netty:0.14.1:compile
io.netty:netty-buffer:4.1.1.Final:compile
io.netty:netty-codec:4.1.1.Final:compile
io.netty:netty-codec-http:4.1.1.Final:compile
io.netty:netty-codec-http2:4.1.1.Final:compile
io.netty:netty-common:4.1.1.Final:compile
io.netty:netty-handler:4.1.1.Final:compile
io.netty:netty-resolver:4.1.1.Final:compile
io.netty:netty-transport:4.1.1.Final:compile

View File

@ -280,6 +280,13 @@ object CentralTests extends TestSuite {
}
}
'fixedVersionDependency - {
val mod = Module("io.grpc", "grpc-netty")
val version = "0.14.1"
resolutionCheck(mod, version)
}
'mavenScopes - {
def check(config: String) = resolutionCheck(
Module("com.android.tools", "sdklib"),

View File

@ -163,10 +163,6 @@ object VersionIntervalTests extends TestSuite {
'parse{
'malformed{
val s1 = "[1.1]"
val itv1 = Parse.versionInterval(s1)
assert(itv1 == None)
val s2 = "(1.1)"
val itv2 = Parse.versionInterval(s2)
assert(itv2 == None)
@ -263,6 +259,38 @@ object VersionIntervalTests extends TestSuite {
assert(itv4 == Some(VersionInterval(None, None, false, true)))
assert(!itv4.get.isValid)
}
'fixedVersion - {
* - {
val itv = Parse.versionInterval("[1.2]")
assert(itv == Some(VersionInterval(Some(Version("1.2")), Some(Version("1.2")), true, true)))
}
* - {
val itv = Parse.versionInterval("[1.2)")
assert(itv.isEmpty)
}
* - {
val itv = Parse.versionInterval("(1.2]")
assert(itv.isEmpty)
}
* - {
val itv = Parse.versionInterval("(1.2)")
assert(itv.isEmpty)
}
* - {
val itv = Parse.versionInterval("[]")
assert(itv.isEmpty)
}
* - {
val itv = Parse.versionInterval("[0.0]")
assert(itv.isEmpty)
}
}
}
'constraint{