From 2c3db4e1ed46059736440e494fe400dcb2f50e9f Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Thu, 22 Jun 2017 00:19:08 -0400 Subject: add basic support for maven version ranges --- stage1/resolver.scala | 15 ++++++++++++++- test/simple/build/build.scala | 15 ++++++++------- test/test.scala | 29 +++++++++++++++++++++++++++++ 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") -- cgit v1.2.3