From 77310ac2b6bb3e354fa6073f82ed92ab18ef203b Mon Sep 17 00:00:00 2001 From: "Brendan W. McAdams" Date: Thu, 28 Feb 2013 14:11:07 -0800 Subject: [PATCH] Resolves #645: Added 'xml:space="preserve"' attribute to extraDependencyAttributes XML Block * This will keep PrettyPrinter from clobbering and breaking pom files for plugins dependent on other plugins --- ivy/src/main/scala/sbt/MakePom.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ivy/src/main/scala/sbt/MakePom.scala b/ivy/src/main/scala/sbt/MakePom.scala index 639400db0..cbfb0a5a1 100644 --- a/ivy/src/main/scala/sbt/MakePom.scala +++ b/ivy/src/main/scala/sbt/MakePom.scala @@ -10,7 +10,7 @@ package sbt import java.io.File // Node needs to be renamed to XNode because the task subproject contains a Node type that will shadow // scala.xml.Node when generating aggregated API documentation -import scala.xml.{Elem, Node => XNode, NodeSeq, PrettyPrinter} +import scala.xml.{Elem, Node => XNode, NodeSeq, PrettyPrinter, PrefixedAttribute} import Configurations.Optional import org.apache.ivy.{core, plugins, Ivy} @@ -105,11 +105,20 @@ class MakePom(val log: Logger) val allExtra = if(depExtra.isEmpty) extra else extra.updated(CustomPomParser.ExtraAttributesKey, depExtra) if(allExtra.isEmpty) NodeSeq.Empty else makeProperties(allExtra) } - def makeProperties(extra: Map[String,String]): NodeSeq = + def makeProperties(extra: Map[String,String]): NodeSeq = { + def _extraAttributes(k: String) = if (k == CustomPomParser.ExtraAttributesKey) xmlSpacePreserve else scala.xml.Null { for( (key,value) <- extra ) yield - ({value}).copy(label = key) + ({value}).copy(label = key, attributes = _extraAttributes(key)) } + } + + /** + * Attribute tag that PrettyPrinter won't ignore, saying "don't mess with my spaces" + * Without this, PrettyPrinter will flatten multiple entries for ExtraDependencyAttributes and make them + * unparseable. (e.g. a plugin that depends on multiple plugins will fail) + */ + def xmlSpacePreserve = new PrefixedAttribute("xml", "space", "preserve", scala.xml.Null) def description(d: String) = if((d eq null) || d.isEmpty) NodeSeq.Empty else {d} def licenses(ls: Array[License]) = if(ls == null || ls.isEmpty) NodeSeq.Empty else {ls.map(license)}