aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Christopher Vogt <oss.nsp@cvogt.org>2017-06-22 01:19:42 -0400
committerGitHub <noreply@github.com>2017-06-22 01:19:42 -0400
commit3307c0d0ec54b7d87e83596572da2853328ed009 (patch)
tree1f39f2f458a532425f7c1ae401e57f247170b448
parent96d01f08f8c8f097a7b391a92acd63f6295f43d6 (diff)
parent2c3db4e1ed46059736440e494fe400dcb2f50e9f (diff)
downloadcbt-3307c0d0ec54b7d87e83596572da2853328ed009.tar.gz
cbt-3307c0d0ec54b7d87e83596572da2853328ed009.tar.bz2
cbt-3307c0d0ec54b7d87e83596572da2853328ed009.zip
Merge pull request #535 from cvogt/version-ranges
add basic support for maven version ranges
-rw-r--r--stage1/resolver.scala15
-rw-r--r--test/simple/build/build.scala15
-rw-r--r--test/test.scala29
3 files changed, 51 insertions, 8 deletions
diff --git a/stage1/resolver.scala b/stage1/resolver.scala
index 13d4070..0da8f6f 100644
--- a/stage1/resolver.scala
+++ b/stage1/resolver.scala
@@ -268,7 +268,10 @@ case class BoundMavenDependency(
classpath.strings.map(new File(_).lastModified).max
}
- private lazy val base = "/" + groupId.split("\\.").mkString("/") + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version
+ private lazy val base = {
+ val v = BoundMavenDependency.extractVersion(version)
+ "/" + groupId.split("\\.").mkString("/") + "/" + artifactId + "/" + v + "/" + artifactId + "-" + v
+ }
protected[cbt] def basePath(useClassifier: Boolean) = // PERFORMANCE HOTSPOT
base + (if (useClassifier && classifier.name.nonEmpty) "-" + classifier.name.get else "")
@@ -421,6 +424,16 @@ case class BoundMavenDependency(
}
}
object BoundMavenDependency{
+ private lazy val versionRangeRegex = "^[\\[\\(]([^,\\]\\)]*)(,([^\\]\\)]*))?[\\]\\)]".r
+ def extractVersion( versionOrRange: String ) = {
+ versionOrRange match {
+ case versionRangeRegex(left,middle,right) if left != null || right != null => {
+ Option(left).filterNot(_ == "") getOrElse right
+ }
+ case version => version
+ }
+ }
+
val ValidIdentifier = "^([A-Za-z0-9_\\-.]+)$".r // according to maven's DefaultModelValidator.java
def semanticVersionLessThan(left: Array[Either[Int,String]], right: Array[Either[Int,String]]) = {
// FIXME: this ignores ends when different size
diff --git a/test/simple/build/build.scala b/test/simple/build/build.scala
index 3465ec3..66bee95 100644
--- a/test/simple/build/build.scala
+++ b/test/simple/build/build.scala
@@ -7,6 +7,9 @@ class Build(val context: cbt.Context) extends BaseBuild{
// FIXME: make the below less verbose
Resolver( mavenCentral ).bind(
ScalaDependency("com.typesafe.play", "play-json", "2.4.4"),
+ ScalaDependency("io.spray","spray-http","1.3.3"),
+ ScalaDependency( "com.lihaoyi", "scalatex-api", "0.3.6" ),
+ ScalaDependency( "com.lihaoyi", "scalatex-site", "0.3.6" ),
MavenDependency("joda-time", "joda-time", "2.9.2"),
// the below tests pom inheritance with dependencyManagement and variable substitution for pom properties
MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"),
@@ -16,15 +19,13 @@ class Build(val context: cbt.Context) extends BaseBuild{
MavenDependency("cc.factorie","factorie_2.11","1.2"),
// test recursive substitution. see https://github.com/cvogt/cbt/issues/434
MavenDependency("com.amazonaws", "aws-java-sdk-s3", "1.11.86"),
- // the dependency below uses a maven version range. Currently not supported.
+ // requires maven version ranges
+ MavenDependency("io.grpc", "grpc-netty", "1.2.0")
+ // the dependency below uses a maven version range with automatic minor version. Currently not supported.
// TODO: put in a proper error message for version range not supported
- //MavenDependency("com.github.nikita-volkov", "sext", "0.2.4")
+ // MavenDependency("com.github.nikita-volkov", "sext", "0.2.4")
// currently breaks with can't find https://repo1.maven.org/maven2/org/apache/avro/avro-mapred/1.7.7/avro-mapred-1.7.7-hadoop2.pom.sha1
- // org.apache.spark:spark-sql_2.11:1.6.1
- // currently fails, let's see if because of a bug
- // io.spray:spray-http:1.3.3
- ScalaDependency( "com.lihaoyi", "scalatex-api", "0.3.6" ),
- ScalaDependency( "com.lihaoyi", "scalatex-site", "0.3.6" )
+ // ScalaDependency("org.apache.spark","spark-sql_2.11","1.6.1")
) ++
Resolver( mavenCentral, sonatypeReleases ).bind(
"org.scalameta" %% "scalameta" % "1.1.0"
diff --git a/test/test.scala b/test/test.scala
index 55ce205..9cb7fd9 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -242,6 +242,35 @@ object Main{
ScaffoldTest.main(Array())
+ Seq(
+ "1.0" -> "1.0",
+ "1.0-M1" -> "1.0-M1",
+ "1.0.0" -> "1.0.0",
+ "[1.0.0]" -> "1.0.0",
+ "[1.0.0)" -> "1.0.0",
+ "(1.0.0]" -> "1.0.0",
+ "(1.0.0)" -> "1.0.0",
+ "(,1.0.0]" -> "1.0.0",
+ "[,1.0.0]" -> "1.0.0",
+ "[,1.0.0)" -> "1.0.0",
+ "(,1.0.0)" -> "1.0.0",
+ "(1.0.0,]" -> "1.0.0",
+ "[1.0.0,]" -> "1.0.0",
+ "[1.0.0,)" -> "1.0.0",
+ "(1.0.0,)" -> "1.0.0",
+ "(1.0.0,1.0.1]" -> "1.0.0",
+ "[1.0.0,1.0.1]" -> "1.0.0",
+ "[1.0.0,1.0.1)" -> "1.0.0",
+ "(1.0.0,1.0.1)" -> "1.0.0"
+ ).foreach{
+ case (input, expected) =>
+ val actual = BoundMavenDependency.extractVersion(input)
+ assert(
+ expected === actual,
+ s"for $input expected $expected got $actual"
+ )
+ }
+
usage("nothing")
compile("nothing")
//clean("nothing")