Skip to content

Commit

Permalink
Parse homepage attribute in ivy.xml (#1433)
Browse files Browse the repository at this point in the history
This extracts the [`homepage`](https://ant.apache.org/ivy/history/latest-milestone/ivyfile/description.html)
attribute from the `description` element in `ivy.xml` files and sets it
as `homePage` in `Info`.

My goal is to use this in Scala Steward for linking to home pages and
release notes of sbt plugins.
  • Loading branch information
fthomas authored and alexarchambault committed Nov 13, 2019
1 parent 5e08e30 commit 7d805d5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/core/shared/src/main/scala/coursier/ivy/IvyXml.scala
Expand Up @@ -184,11 +184,14 @@ object IvyXml {

val publicationsOpt = publicationsNodeOpt.map(publications)

val description = infoNode.children
.find(_.label == "description")
val descriptionNodeOpt = infoNode.children.find(_.label == "description")

val description = descriptionNodeOpt
.map(_.textContent.trim)
.getOrElse("")

val homePage = descriptionNodeOpt.flatMap(_.attribute("homepage").right.toOption).getOrElse("")

val licenses = infoNode.children
.filter(_.label == "license")
.flatMap { n =>
Expand Down Expand Up @@ -229,7 +232,7 @@ object IvyXml {
},
Info(
description,
"",
homePage,
licenses,
Nil,
publicationDate,
Expand Down
@@ -0,0 +1,49 @@
package coursier
package test

import coursier.core.Versions
import coursier.core.compatibility._
import coursier.ivy.IvyXml
import utest._

object IvyXmlParsingTests extends TestSuite {
val tests = Tests {
'infoWithHomePage {
// slice of https://dl.bintray.com/sbt/sbt-plugin-releases/com.github.gseitz/sbt-release/scala_2.12/sbt_1.0/1.0.12/ivys/ivy.xml
val node = """
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.github.gseitz" module="sbt-release" revision="1.0.12" status="release" publication="20191016122629" e:sbtVersion="1.0" e:scalaVersion="2.12">
<license name="Apache-2.0" url="http://www.apache.org/licenses/LICENSE-2.0"/>
<description homepage="https://github.com/sbt/sbt-release">
sbt-release
</description>
</info>
</ivy-module>
"""

val result = IvyXml.project(xmlParseDom(node).right.get).right.map(_.info)
val expected = Right(Info("sbt-release", "https://github.com/sbt/sbt-release",
List(("Apache-2.0", Some("http://www.apache.org/licenses/LICENSE-2.0"))), Nil,
Some(Versions.DateTime(2019, 10, 16, 12, 26, 29)), None))

assert(result == expected)
}

'infoWithoutHomePage {
val node = """
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.github.gseitz" module="sbt-release" revision="1.0.12" status="release" e:sbtVersion="1.0" e:scalaVersion="2.12">
<description>
sbt-release
</description>
</info>
</ivy-module>
"""

val result = IvyXml.project(xmlParseDom(node).right.get).right.map(_.info)
val expected = Right(Info("sbt-release", "", Nil, Nil, None, None))

assert(result == expected)
}
}
}

0 comments on commit 7d805d5

Please sign in to comment.