From b25fc2bd00a809d78fbb13f93837e96274688327 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 3 Mar 2014 12:10:37 -0500 Subject: [PATCH 1/2] Fix #1136 - Ivy's `+` dependencies not converted to maven style syntax. * Attempt to convert dependencies that end in `+` into maven-style version range * if a failure occurs, just use the original version (could be bad...). --- ivy/src/main/scala/sbt/MakePom.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ivy/src/main/scala/sbt/MakePom.scala b/ivy/src/main/scala/sbt/MakePom.scala index 5e49243d3..4c4b7c8d0 100644 --- a/ivy/src/main/scala/sbt/MakePom.scala +++ b/ivy/src/main/scala/sbt/MakePom.scala @@ -188,7 +188,7 @@ class MakePom(val log: Logger) {mrid.getOrganisation} {mrid.getName} - {mrid.getRevision} + {makeDependencyVersion(mrid.getRevision)} { scopeElem(scope) } { optionalElem(optional) } { classifierElem(classifier) } @@ -197,6 +197,25 @@ class MakePom(val log: Logger) } + + + def makeDependencyVersion(revision: String): String = { + if(revision endsWith "+") try { + // TODO - this is the slowest possible implementation. + val beforePlus = revision.reverse.dropWhile(_ != '.').drop(1).reverse + val lastVersion = beforePlus.reverse.takeWhile(_ != '.').reverse + val lastVersionInt = lastVersion.toInt + val prefixVersion = beforePlus.reverse.dropWhile(_ != '.').drop(1).reverse + s"[$beforePlus, ${prefixVersion}.${lastVersionInt+1})" + } catch { + case e: NumberFormatException => + // TODO - if the version deosn't meet our expectations, maybe we just issue a hard + // error instead of softly ignoring the attempt to rewrite. + //sys.error(s"Could not fix version [$revision] into maven style version") + revision + } else revision + } + @deprecated("No longer used and will be removed.", "0.12.1") def classifier(dependency: DependencyDescriptor, includeTypes: Set[String]): NodeSeq = { From ee28011dfc9d755d61f58840cd90e097abfc1c8b Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 5 Mar 2014 19:14:21 -0500 Subject: [PATCH 2/2] Pull in @cunei's suggestion for a more complete Ivy->Maven dynamic revision convertor. We attempt to convert these constructs to maven: * 1.+ * ]1,2] * [2,3[ * 1+ - Albeit this one is a heuristic for accuracy. This should help ivy users which prefer the nicer 1.2.+ syntax. Also adds tests/improves exisitng tests. --- ivy/src/main/scala/sbt/MakePom.scala | 43 ++++++++++++++++++++-------- ivy/src/test/scala/MakePomTest.scala | 29 +++++++++++++++++++ 2 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 ivy/src/test/scala/MakePomTest.scala diff --git a/ivy/src/main/scala/sbt/MakePom.scala b/ivy/src/main/scala/sbt/MakePom.scala index 4c4b7c8d0..16ec28333 100644 --- a/ivy/src/main/scala/sbt/MakePom.scala +++ b/ivy/src/main/scala/sbt/MakePom.scala @@ -200,20 +200,39 @@ class MakePom(val log: Logger) def makeDependencyVersion(revision: String): String = { - if(revision endsWith "+") try { - // TODO - this is the slowest possible implementation. - val beforePlus = revision.reverse.dropWhile(_ != '.').drop(1).reverse - val lastVersion = beforePlus.reverse.takeWhile(_ != '.').reverse + def plusRange(s:String, shift:Int = 0) = { + def pow(i:Int):Int = if (i>0) 10 * pow(i-1) else 1 + val (prefixVersion, lastVersion) = (s+"0"*shift).reverse.split("\\.",2) match { + case Array(revLast,revRest) => + ( revRest.reverse + ".", revLast.reverse ) + case Array(revLast) => ("", revLast.reverse) + } val lastVersionInt = lastVersion.toInt - val prefixVersion = beforePlus.reverse.dropWhile(_ != '.').drop(1).reverse - s"[$beforePlus, ${prefixVersion}.${lastVersionInt+1})" + s"[${prefixVersion}${lastVersion},${prefixVersion}${lastVersionInt+pow(shift)})" + } + val startSym=Set(']','[','(') + val stopSym=Set(']','[',')') + try { + if (revision endsWith ".+") { + plusRange(revision.substring(0,revision.length-2)) + } else if (revision endsWith "+") { + val base = revision.take(revision.length-1) + // 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. + (0 to 5).map(plusRange(base,_)).mkString(",") + } else if (startSym(revision(0)) && stopSym(revision(revision.length-1))) { + val start = revision(0) + val stop = revision(revision.length-1) + val mid = revision.substring(1,revision.length-1) + (if (start == ']') "(" else start) + mid + (if (stop == '[') ")" else stop) + } else revision } catch { - case e: NumberFormatException => - // TODO - if the version deosn't meet our expectations, maybe we just issue a hard - // error instead of softly ignoring the attempt to rewrite. - //sys.error(s"Could not fix version [$revision] into maven style version") - revision - } else revision + case e: NumberFormatException => + // TODO - if the version doesn't meet our expectations, maybe we just issue a hard + // error instead of softly ignoring the attempt to rewrite. + //sys.error(s"Could not fix version [$revision] into maven style version") + revision + } } @deprecated("No longer used and will be removed.", "0.12.1") diff --git a/ivy/src/test/scala/MakePomTest.scala b/ivy/src/test/scala/MakePomTest.scala new file mode 100644 index 000000000..1341b207d --- /dev/null +++ b/ivy/src/test/scala/MakePomTest.scala @@ -0,0 +1,29 @@ +package sbt + +import java.io.File +import org.specs2._ +import mutable.Specification + +object MakePomTest extends Specification +{ + val mp = new MakePom(ConsoleLogger()) + import mp.{makeDependencyVersion=>v} + "MakePom makeDependencyVersion" should { + "Handle .+ in versions" in { + v("1.+") must_== "[1,2)" + v("1.2.3.4.+") must_== "[1.2.3.4,1.2.3.5)" + v("12.31.42.+") must_== "[12.31.42,12.31.43)" + } + /* TODO - do we care about this case? + * 1+ --> [1,2),[10,20),[100,200),[1000,2000),[10000,20000),[100000,200000) + */ + "Handle ]* bracket in version ranges" in { + v("]1,3]") must_== "(1,3]" + v("]1.1,1.3]") must_== "(1.1,1.3]" + } + "Handle *[ bracket in version ranges" in { + v("[1,3[") must_== "[1,3)" + v("[1.1,1.3[") must_== "[1.1,1.3)" + } + } +}