Add support for relocation

This commit is contained in:
Alexandre Archambault 2017-04-21 16:46:50 +02:00
parent 13da5e871f
commit ec0ed108e1
4 changed files with 52 additions and 4 deletions

View File

@ -249,7 +249,7 @@ final case class MavenRepository(
for {
xml <- \/.fromEither(compatibility.xmlParse(str))
_ <- if (xml.label == "project") \/-(()) else -\/("Project definition not found")
proj <- Pom.project(xml)
proj <- Pom.project(xml, relocationAsDependency = true)
} yield proj
def artifactFor(url: String) =

View File

@ -140,7 +140,13 @@ object Pom {
def packagingOpt(pom: Node): Option[String] =
text(pom, "packaging", "").toOption
def project(pom: Node): String \/ Project = {
def project(pom: Node): String \/ Project =
project(pom, relocationAsDependency = false)
def project(
pom: Node,
relocationAsDependency: Boolean
): String \/ Project = {
import Scalaz._
for {
@ -242,10 +248,41 @@ object Pom {
case \/-(d) => d
}
val finalProjModule = projModule.copy(organization = groupId)
val relocationDependencyOpt =
if (relocationAsDependency)
pom.children
.find(_.label == "distributionManagement")
.flatMap(_.children.find(_.label == "relocation"))
.map { n =>
// see https://maven.apache.org/guides/mini/guide-relocation.html
val relocatedGroupId = text(n, "groupId", "").getOrElse(finalProjModule.organization)
val relocatedArtifactId = text(n, "artifactId", "").getOrElse(finalProjModule.name)
val relocatedVersion = text(n, "version", "").getOrElse(version)
"" -> Dependency(
finalProjModule.copy(
organization = relocatedGroupId,
name = relocatedArtifactId
),
relocatedVersion,
"",
Set(),
Attributes("", ""),
optional = false,
transitive = true
)
}
else
None
Project(
projModule.copy(organization = groupId),
finalProjModule,
version,
deps.map {
(relocationDependencyOpt.toList ::: deps).map {
case (config, dep0) =>
val dep = extraAttrsMap.get(dep0.moduleVersion).fold(dep0)(attrs =>
dep0.copy(module = dep0.module.copy(attributes = attrs))

View File

@ -0,0 +1,4 @@
bouncycastle:bctsp-jdk14:138:compile
org.bouncycastle:bcmail-jdk14:1.38:compile
org.bouncycastle:bcprov-jdk14:1.38:compile
org.bouncycastle:bctsp-jdk14:1.38:compile

View File

@ -586,6 +586,13 @@ object CentralTests extends TestSuite {
"0.9.19"
)
}
'relocation - {
resolutionCheck(
Module("bouncycastle", "bctsp-jdk14"),
"138"
)
}
}
}