mirror of https://github.com/sbt/sbt.git
Fixup (better handling of sbt attributes)
This commit is contained in:
parent
5d32358c2e
commit
c42682ed60
|
|
@ -1,5 +1,7 @@
|
|||
package coursier
|
||||
|
||||
import coursier.maven.MavenSource
|
||||
|
||||
import scalaz._
|
||||
|
||||
object Fetch {
|
||||
|
|
@ -39,11 +41,21 @@ object Fetch {
|
|||
|
||||
val task = lookups.foldLeft[F[Seq[String] \/ (Artifact.Source, Project)]](F.point(-\/(Nil))) {
|
||||
case (acc, (repo, eitherProjTask)) =>
|
||||
val looseModuleValidation = repo match {
|
||||
case m: MavenRepository => m.sbtAttrStub // that sucks so much
|
||||
case _ => false
|
||||
}
|
||||
val moduleCmp = if (looseModuleValidation) module.copy(attributes = Map.empty) else module
|
||||
F.bind(acc) {
|
||||
case -\/(errors) =>
|
||||
F.map(eitherProjTask)(_.flatMap{case (source, project) =>
|
||||
if (project.module == module) \/-((source, project))
|
||||
else -\/(s"Wrong module returned (expected: $module, got: ${project.module})")
|
||||
val projModule =
|
||||
if (looseModuleValidation)
|
||||
project.module.copy(attributes = Map.empty)
|
||||
else
|
||||
project.module
|
||||
if (projModule == moduleCmp) \/-((source, project))
|
||||
else -\/(s"Wrong module returned (expected: $moduleCmp, got: ${project.module})")
|
||||
}.leftMap(error => error +: errors))
|
||||
|
||||
case res @ \/-(_) =>
|
||||
|
|
@ -52,8 +64,18 @@ object Fetch {
|
|||
}
|
||||
|
||||
EitherT(F.map(task)(_.leftMap(_.reverse)))
|
||||
.map {case x @ (_, proj) =>
|
||||
assert(proj.module == module)
|
||||
.map {case x @ (source, proj) =>
|
||||
val looseModuleValidation = source match {
|
||||
case m: MavenSource => m.sbtAttrStub // omfg
|
||||
case _ => false
|
||||
}
|
||||
val projModule =
|
||||
if (looseModuleValidation)
|
||||
proj.module.copy(attributes = Map.empty)
|
||||
else
|
||||
proj.module
|
||||
val moduleCmp = if (looseModuleValidation) module.copy(attributes = Map.empty) else module
|
||||
assert(projModule == moduleCmp)
|
||||
x
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ object MavenRepository {
|
|||
|
||||
def ivyLikePath(
|
||||
org: String,
|
||||
dirName: String,
|
||||
name: String,
|
||||
version: String,
|
||||
subDir: String,
|
||||
|
|
@ -19,7 +20,7 @@ object MavenRepository {
|
|||
) =
|
||||
Seq(
|
||||
org,
|
||||
name,
|
||||
dirName,
|
||||
version,
|
||||
subDir,
|
||||
s"$name$baseSuffix.$ext"
|
||||
|
|
@ -44,6 +45,17 @@ object MavenRepository {
|
|||
"test" -> Seq("runtime")
|
||||
)
|
||||
|
||||
def dirModuleName(module: Module, sbtAttrStub: Boolean): String =
|
||||
if (sbtAttrStub) {
|
||||
var name = module.name
|
||||
for (scalaVersion <- module.attributes.get("scalaVersion"))
|
||||
name = name + "_" + scalaVersion
|
||||
for (sbtVersion <- module.attributes.get("sbtVersion"))
|
||||
name = name + "_" + sbtVersion
|
||||
name
|
||||
} else
|
||||
module.name
|
||||
|
||||
}
|
||||
|
||||
case class MavenRepository(
|
||||
|
|
@ -58,18 +70,7 @@ case class MavenRepository(
|
|||
import MavenRepository._
|
||||
|
||||
val root0 = if (root.endsWith("/")) root else root + "/"
|
||||
val source = MavenSource(root0, ivyLike)
|
||||
|
||||
private def dirModuleName(module: Module): String =
|
||||
if (sbtAttrStub) {
|
||||
var name = module.name
|
||||
for (scalaVersion <- module.attributes.get("scalaVersion"))
|
||||
name = name + "_" + scalaVersion
|
||||
for (sbtVersion <- module.attributes.get("sbtVersion"))
|
||||
name = name + "_" + sbtVersion
|
||||
name
|
||||
} else
|
||||
module.name
|
||||
val source = MavenSource(root0, ivyLike, changing, sbtAttrStub)
|
||||
|
||||
def projectArtifact(
|
||||
module: Module,
|
||||
|
|
@ -81,7 +82,8 @@ case class MavenRepository(
|
|||
if (ivyLike)
|
||||
ivyLikePath(
|
||||
module.organization,
|
||||
dirModuleName(module), // maybe not what we should do here, don't know
|
||||
dirModuleName(module, sbtAttrStub), // maybe not what we should do here, don't know
|
||||
module.name,
|
||||
versioningValue getOrElse version,
|
||||
"poms",
|
||||
"",
|
||||
|
|
@ -89,7 +91,7 @@ case class MavenRepository(
|
|||
)
|
||||
else
|
||||
module.organization.split('.').toSeq ++ Seq(
|
||||
dirModuleName(module),
|
||||
dirModuleName(module, sbtAttrStub),
|
||||
version,
|
||||
s"${module.name}-${versioningValue getOrElse version}.pom"
|
||||
)
|
||||
|
|
@ -111,7 +113,7 @@ case class MavenRepository(
|
|||
else {
|
||||
val path = (
|
||||
module.organization.split('.').toSeq ++ Seq(
|
||||
dirModuleName(module),
|
||||
dirModuleName(module, sbtAttrStub),
|
||||
"maven-metadata.xml"
|
||||
)
|
||||
) .map(encodeURIComponent)
|
||||
|
|
@ -138,7 +140,7 @@ case class MavenRepository(
|
|||
else {
|
||||
val path = (
|
||||
module.organization.split('.').toSeq ++ Seq(
|
||||
dirModuleName(module),
|
||||
dirModuleName(module, sbtAttrStub),
|
||||
version,
|
||||
"maven-metadata.xml"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import coursier.core._
|
|||
case class MavenSource(
|
||||
root: String,
|
||||
ivyLike: Boolean,
|
||||
changing: Option[Boolean] = None
|
||||
changing: Option[Boolean] = None,
|
||||
/** See doc on MavenRepository */
|
||||
sbtAttrStub: Boolean
|
||||
) extends Artifact.Source {
|
||||
|
||||
import Repository._
|
||||
|
|
@ -47,6 +49,7 @@ case class MavenSource(
|
|||
def ivyLikePath0(subDir: String, baseSuffix: String, ext: String) =
|
||||
ivyLikePath(
|
||||
module.organization,
|
||||
MavenRepository.dirModuleName(module, sbtAttrStub),
|
||||
module.name,
|
||||
project.version,
|
||||
subDir,
|
||||
|
|
@ -66,7 +69,7 @@ case class MavenSource(
|
|||
)
|
||||
|
||||
module.organization.split('.').toSeq ++ Seq(
|
||||
module.name,
|
||||
MavenRepository.dirModuleName(module, sbtAttrStub),
|
||||
project.version,
|
||||
s"${module.name}-${versioning getOrElse project.version}${Some(publication.classifier).filter(_.nonEmpty).map("-" + _).mkString}.${publication.ext}"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue