diff options
-rw-r--r-- | stage1/logger.scala | 2 | ||||
-rw-r--r-- | stage1/resolver.scala | 42 | ||||
-rw-r--r-- | test/simple/build/build.scala | 4 |
3 files changed, 38 insertions, 10 deletions
diff --git a/stage1/logger.scala b/stage1/logger.scala index b1d80a3..5e8858a 100644 --- a/stage1/logger.scala +++ b/stage1/logger.scala @@ -29,6 +29,7 @@ case class Logger(enabledLoggers: Set[String]) { final def resolver(msg: => String) = logGuarded(names.resolver, msg) final def lib(msg: => String) = logGuarded(names.lib, msg) final def test(msg: => String) = logGuarded(names.test, msg) + final def pom(msg: => String) = logGuarded(names.pom, msg) private object names{ val stage1 = "stage1" @@ -39,6 +40,7 @@ case class Logger(enabledLoggers: Set[String]) { val composition = "composition" val lib = "lib" val test = "test" + val pom = "pom" } private def logGuarded(name: String, msg: => String) = { diff --git a/stage1/resolver.scala b/stage1/resolver.scala index 3ec806b..85eb248 100644 --- a/stage1/resolver.scala +++ b/stage1/resolver.scala @@ -273,32 +273,56 @@ case class JavaDependency( )(logger) } } + + lazy val properties: Map[String, String] = ( + pomParents.flatMap(_.properties) ++ { + val props = (pomXml \ "properties").flatMap(_.child).map{ + tag => tag.label -> tag.text + } + logger.pom(s"Found properties in $pom: $props") + props + } + ).toMap + + lazy val dependencyVersions: Map[(String,String), String] = + pomParents.flatMap( + p => + p.dependencyVersions + ++ + (p.pomXml \ "dependencyManagement" \ "dependencies" \ "dependency").map{ + xml => + val groupId = p.lookup(xml,_ \ "groupId").get + val artifactId = p.lookup(xml,_ \ "artifactId").get + val version = p.lookup(xml,_ \ "version").get + (groupId, artifactId) -> version + } + ).toMap + def dependencies: Seq[JavaDependency] = { if(classifier == Classifier.sources) Seq() else (pomXml \ "dependencies" \ "dependency").collect{ case xml if (xml \ "scope").text == "" && (xml \ "optional").text != "true" => + val groupId = lookup(xml,_ \ "groupId").get + val artifactId = lookup(xml,_ \ "artifactId").get JavaDependency( - lookup(xml,_ \ "groupId").get, - lookup(xml,_ \ "artifactId").get, - lookup(xml,_ \ "version").get, + groupId, + artifactId, + lookup(xml,_ \ "version").getOrElse( dependencyVersions(groupId, artifactId) ), Classifier( Some( (xml \ "classifier").text ).filterNot(_ == "").filterNot(_ == null) ) )(logger) }.toVector } def lookup( xml: Node, accessor: Node => NodeSeq ): Option[String] = { //println("lookup in "++pomUrl) - val Substitution = "\\$\\{([a-z0-9\\.]++)\\}".r + val Substitution = "\\$\\{([^\\}]+)\\}".r accessor(xml).headOption.flatMap{v => //println("found: "++v.text) v.text match { - case Substitution(path) => + case Substitution(path) => Option(properties(path)) //println("lookup "++path ++ ": "++(pomXml\path).text) - lookup(pomXml, _ \ "properties" \ path) case value => Option(value) } - }.orElse( - pomParents.map(p => p.lookup(p.pomXml, accessor)).flatten.headOption - ) + } } } object JavaDependency{ diff --git a/test/simple/build/build.scala b/test/simple/build/build.scala index 3f7633b..37de2e4 100644 --- a/test/simple/build/build.scala +++ b/test/simple/build/build.scala @@ -4,6 +4,8 @@ import java.io.File class Build(context: cbt.Context) extends BasicBuild(context){ override def dependencies = Seq( ScalaDependency("com.typesafe.play", "play-json", "2.4.4"), - JavaDependency("joda-time", "joda-time", "2.9.2") + JavaDependency("joda-time", "joda-time", "2.9.2"), + // the below tests pom inheritance with dependencyManagement and variable substitution + JavaDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r") ) ++ super.dependencies } |