Trim the whitespaces in pom.xml's properties

Maven trims the whitespaces around pom.xml's properties by default.
Fixes #408
This commit is contained in:
Kazuyoshi Kato 2017-02-16 21:47:11 -08:00
parent 991b60ddbc
commit 6eeeb8cb66
4 changed files with 50 additions and 1 deletions

View File

@ -7,9 +7,18 @@ import scalaz._
object Pom {
import coursier.util.Xml._
/**
* Returns either a property's key-value pair or an error if the elem is not an element.
*
* This method trims all spaces, whereas Maven has an option to preserve them.
*
* @param elem a property element
* @return the key and the value of the property
* @see [[https://issues.apache.org/jira/browse/MNG-5380]]
*/
def property(elem: Node): String \/ (String, String) = {
// Not matching with Text, which fails on scala-js if the property value has xml comments
if (elem.isElement) \/-(elem.label -> elem.textContent)
if (elem.isElement) \/-(elem.label -> elem.textContent.trim)
else -\/(s"Can't parse property $elem")
}

View File

@ -0,0 +1,10 @@
commons-codec:commons-codec:1.6:compile
commons-io:commons-io:2.1:compile
commons-logging:commons-logging:1.1.1:compile
javax.activation:activation:1.1:compile
net.jcip:jcip-annotations:1.0:compile
org.apache.httpcomponents:httpclient:4.2.6:compile
org.apache.httpcomponents:httpcore:4.2.5:compile
org.jboss.resteasy:jaxrs-api:3.0.9.Final:compile
org.jboss.resteasy:resteasy-jaxrs:3.0.9.Final:compile
org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:1.0.1.Final:compile

View File

@ -455,6 +455,13 @@ object CentralTests extends TestSuite {
)
}
'ignoreWhitespaces - {
resolutionCheck(
Module("org.jboss.resteasy", "resteasy-jaxrs"),
"3.0.9.Final"
)
}
'nd4jNative - {
// In particular:
// - uses OS-based activation,

View File

@ -194,6 +194,29 @@ object PomParsingTests extends TestSuite {
assert(result == expected)
}
'propertyWithSpaces{
val profileNode ="""
<profile>
<id>profile1</id>
<properties>
<first.prop> value1 </first.prop>
</properties>
</profile>
"""
val expected = \/-(Profile(
"profile1",
None,
Profile.Activation(Nil),
Nil,
Nil,
Map("first.prop" -> "value1")
))
val result = Pom.profile(xmlParse(profileNode).right.get)
assert(result == expected)
}
'beFineWithCommentsInProperties{
import scalaz._, Scalaz._