From 6eeeb8cb66394b8997f12a313d9add5809c9e414 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Thu, 16 Feb 2017 21:47:11 -0800 Subject: [PATCH] Trim the whitespaces in pom.xml's properties Maven trims the whitespaces around pom.xml's properties by default. Fixes #408 --- .../src/main/scala/coursier/maven/Pom.scala | 11 ++++++++- .../resteasy-jaxrs/3.0.9.Final | 10 ++++++++ .../scala/coursier/test/CentralTests.scala | 7 ++++++ .../scala/coursier/test/PomParsingTests.scala | 23 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/shared/src/test/resources/resolutions/org.jboss.resteasy/resteasy-jaxrs/3.0.9.Final diff --git a/core/shared/src/main/scala/coursier/maven/Pom.scala b/core/shared/src/main/scala/coursier/maven/Pom.scala index cfadb7664..268375234 100644 --- a/core/shared/src/main/scala/coursier/maven/Pom.scala +++ b/core/shared/src/main/scala/coursier/maven/Pom.scala @@ -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") } diff --git a/tests/shared/src/test/resources/resolutions/org.jboss.resteasy/resteasy-jaxrs/3.0.9.Final b/tests/shared/src/test/resources/resolutions/org.jboss.resteasy/resteasy-jaxrs/3.0.9.Final new file mode 100644 index 000000000..ec200d135 --- /dev/null +++ b/tests/shared/src/test/resources/resolutions/org.jboss.resteasy/resteasy-jaxrs/3.0.9.Final @@ -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 diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 49f51f127..c6269e0e0 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -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, diff --git a/tests/shared/src/test/scala/coursier/test/PomParsingTests.scala b/tests/shared/src/test/scala/coursier/test/PomParsingTests.scala index b443d309e..0d2eadeca 100644 --- a/tests/shared/src/test/scala/coursier/test/PomParsingTests.scala +++ b/tests/shared/src/test/scala/coursier/test/PomParsingTests.scala @@ -194,6 +194,29 @@ object PomParsingTests extends TestSuite { assert(result == expected) } + 'propertyWithSpaces{ + val profileNode =""" + + profile1 + + value1 + + + """ + + 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._