From a258d4f3b5e15c6d9e3f4fbcfe4f17dabee081f1 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 26 Aug 2011 23:27:03 -0400 Subject: [PATCH] clean up optional dependency handling for make-pom. fixes #162 --- ivy/MakePom.scala | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/ivy/MakePom.scala b/ivy/MakePom.scala index 939ee92bb..76d891330 100644 --- a/ivy/MakePom.scala +++ b/ivy/MakePom.scala @@ -9,6 +9,7 @@ package sbt; import java.io.{BufferedWriter, File, OutputStreamWriter, FileOutputStream} import scala.xml.{Node => XNode, NodeSeq, PrettyPrinter, XML} +import Configurations.Optional import org.apache.ivy.{core, plugins, Ivy} import core.settings.IvySettings @@ -123,32 +124,37 @@ class MakePom {mrid.getOrganisation} {mrid.getName} {mrid.getRevision} - { scope(dependency)} - { optional(dependency) } + { scopeAndOptional(dependency)} } - def scope(dependency: DependencyDescriptor): NodeSeq = - scope(getScope(dependency.getModuleConfigurations)) - def scope(scope: String): NodeSeq = if(scope ne null) {scope} else NodeSeq.Empty - def optional(dependency: DependencyDescriptor) = - if(isOptional(dependency.getModuleConfigurations)) true else NodeSeq.Empty + def scopeAndOptional(dependency: DependencyDescriptor): NodeSeq = + { + val (scope, opt) = getScopeAndOptional(dependency.getModuleConfigurations) + scopeElem(scope) ++ optionalElem(opt) + } + def scopeElem(scope: Option[String]): NodeSeq = scope match { + case Some(s) => {s} + case None => NodeSeq.Empty + } + def optionalElem(opt: Boolean) = if(opt) true else NodeSeq.Empty def moduleDescriptor(module: ModuleDescriptor) = module.getModuleRevisionId - def getScope(confs: Array[String]) = + def getScopeAndOptional(confs: Array[String]): (Option[String], Boolean) = { - Configurations.defaultMavenConfigurations.find(conf => confs.contains(conf.name)) match + val (opt, notOptional) = confs.partition(_ == Optional.name) + val defaultNotOptional = Configurations.defaultMavenConfigurations.find(notOptional contains _.name) + val scope = defaultNotOptional match { - case Some(conf) => conf.name + case Some(conf) => Some(conf.name) case None => - if(confs.isEmpty || confs(0) == Configurations.Default.name) - null + if(notOptional.isEmpty || notOptional(0) == Configurations.Default.name) + None else - confs(0) + Option(notOptional(0)) } + (scope, !opt.isEmpty) } - def isOptional(confs: Array[String]) = confs.isEmpty || (confs.length == 1 && confs(0) == Configurations.Optional.name) - def makeRepositories(settings: IvySettings, includeAll: Boolean, filterRepositories: MavenRepository => Boolean) = {