mirror of https://github.com/sbt/sbt.git
Better handling of attributes from SBT
This commit is contained in:
parent
d188cb0b1a
commit
5d32358c2e
|
|
@ -30,6 +30,8 @@ case class CommonOptions(
|
||||||
repository: List[String],
|
repository: List[String],
|
||||||
@HelpMessage("Do not add default repositories (~/.ivy2/local, and Central)")
|
@HelpMessage("Do not add default repositories (~/.ivy2/local, and Central)")
|
||||||
noDefault: Boolean = false,
|
noDefault: Boolean = false,
|
||||||
|
@HelpMessage("Modify names in Maven repository paths for SBT plugins")
|
||||||
|
sbtPluginHack: Boolean = false,
|
||||||
@HelpMessage("Force module version")
|
@HelpMessage("Force module version")
|
||||||
@ValueDescription("organization:name:forcedVersion")
|
@ValueDescription("organization:name:forcedVersion")
|
||||||
@ExtraName("V")
|
@ExtraName("V")
|
||||||
|
|
|
||||||
|
|
@ -114,10 +114,19 @@ class Helper(
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
}
|
}
|
||||||
|
|
||||||
val repositories =
|
val repositories1 =
|
||||||
(if (common.noDefault) Nil else defaultRepositories) ++
|
(if (common.noDefault) Nil else defaultRepositories) ++
|
||||||
repositories0.collect { case Right(r) => r }
|
repositories0.collect { case Right(r) => r }
|
||||||
|
|
||||||
|
val repositories =
|
||||||
|
if (common.sbtPluginHack)
|
||||||
|
repositories1.map {
|
||||||
|
case m: MavenRepository => m.copy(sbtAttrStub = true)
|
||||||
|
case other => other
|
||||||
|
}
|
||||||
|
else
|
||||||
|
repositories1
|
||||||
|
|
||||||
val (rawDependencies, extraArgs) = {
|
val (rawDependencies, extraArgs) = {
|
||||||
val idxOpt = Some(remainingArgs.indexOf("--")).filter(_ >= 0)
|
val idxOpt = Some(remainingArgs.indexOf("--")).filter(_ >= 0)
|
||||||
idxOpt.fold((remainingArgs, Seq.empty[String])) { idx =>
|
idxOpt.fold((remainingArgs, Seq.empty[String])) { idx =>
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,9 @@ object MavenRepository {
|
||||||
case class MavenRepository(
|
case class MavenRepository(
|
||||||
root: String,
|
root: String,
|
||||||
ivyLike: Boolean = false,
|
ivyLike: Boolean = false,
|
||||||
changing: Option[Boolean] = None
|
changing: Option[Boolean] = None,
|
||||||
|
/** Hackish hack for sbt plugins mainly - what this does really sucks */
|
||||||
|
sbtAttrStub: Boolean = false
|
||||||
) extends Repository {
|
) extends Repository {
|
||||||
|
|
||||||
import Repository._
|
import Repository._
|
||||||
|
|
@ -58,6 +60,17 @@ case class MavenRepository(
|
||||||
val root0 = if (root.endsWith("/")) root else root + "/"
|
val root0 = if (root.endsWith("/")) root else root + "/"
|
||||||
val source = MavenSource(root0, ivyLike)
|
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
|
||||||
|
|
||||||
def projectArtifact(
|
def projectArtifact(
|
||||||
module: Module,
|
module: Module,
|
||||||
version: String,
|
version: String,
|
||||||
|
|
@ -68,7 +81,7 @@ case class MavenRepository(
|
||||||
if (ivyLike)
|
if (ivyLike)
|
||||||
ivyLikePath(
|
ivyLikePath(
|
||||||
module.organization,
|
module.organization,
|
||||||
module.name,
|
dirModuleName(module), // maybe not what we should do here, don't know
|
||||||
versioningValue getOrElse version,
|
versioningValue getOrElse version,
|
||||||
"poms",
|
"poms",
|
||||||
"",
|
"",
|
||||||
|
|
@ -76,7 +89,7 @@ case class MavenRepository(
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
module.organization.split('.').toSeq ++ Seq(
|
module.organization.split('.').toSeq ++ Seq(
|
||||||
module.name,
|
dirModuleName(module),
|
||||||
version,
|
version,
|
||||||
s"${module.name}-${versioningValue getOrElse version}.pom"
|
s"${module.name}-${versioningValue getOrElse version}.pom"
|
||||||
)
|
)
|
||||||
|
|
@ -98,7 +111,7 @@ case class MavenRepository(
|
||||||
else {
|
else {
|
||||||
val path = (
|
val path = (
|
||||||
module.organization.split('.').toSeq ++ Seq(
|
module.organization.split('.').toSeq ++ Seq(
|
||||||
module.name,
|
dirModuleName(module),
|
||||||
"maven-metadata.xml"
|
"maven-metadata.xml"
|
||||||
)
|
)
|
||||||
) .map(encodeURIComponent)
|
) .map(encodeURIComponent)
|
||||||
|
|
@ -125,7 +138,7 @@ case class MavenRepository(
|
||||||
else {
|
else {
|
||||||
val path = (
|
val path = (
|
||||||
module.organization.split('.').toSeq ++ Seq(
|
module.organization.split('.').toSeq ++ Seq(
|
||||||
module.name,
|
dirModuleName(module),
|
||||||
version,
|
version,
|
||||||
"maven-metadata.xml"
|
"maven-metadata.xml"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ object FromSbt {
|
||||||
} yield (from, to)
|
} yield (from, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def attributes(attr: Map[String, String]): Map[String, String] =
|
||||||
|
attr.map { case (k, v) =>
|
||||||
|
k.stripPrefix("e:") -> v
|
||||||
|
}
|
||||||
|
|
||||||
def dependencies(
|
def dependencies(
|
||||||
module: ModuleID,
|
module: ModuleID,
|
||||||
scalaVersion: String,
|
scalaVersion: String,
|
||||||
|
|
@ -39,7 +44,7 @@ object FromSbt {
|
||||||
val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion)
|
val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion)
|
||||||
|
|
||||||
val dep = Dependency(
|
val dep = Dependency(
|
||||||
Module(module.organization, fullName, module.extraAttributes),
|
Module(module.organization, fullName, FromSbt.attributes(module.extraAttributes)),
|
||||||
module.revision,
|
module.revision,
|
||||||
exclusions = module.exclusions.map { rule =>
|
exclusions = module.exclusions.map { rule =>
|
||||||
// FIXME Other `rule` fields are ignored here
|
// FIXME Other `rule` fields are ignored here
|
||||||
|
|
@ -82,7 +87,7 @@ object FromSbt {
|
||||||
Module(
|
Module(
|
||||||
projectID.organization,
|
projectID.organization,
|
||||||
sbtModuleIdName(projectID, scalaVersion, scalaBinaryVersion),
|
sbtModuleIdName(projectID, scalaVersion, scalaBinaryVersion),
|
||||||
projectID.extraAttributes
|
FromSbt.attributes(projectID.extraAttributes)
|
||||||
),
|
),
|
||||||
projectID.revision,
|
projectID.revision,
|
||||||
deps,
|
deps,
|
||||||
|
|
@ -102,7 +107,7 @@ object FromSbt {
|
||||||
case sbt.MavenRepository(_, root) =>
|
case sbt.MavenRepository(_, root) =>
|
||||||
if (root.startsWith("http://") || root.startsWith("https://")) {
|
if (root.startsWith("http://") || root.startsWith("https://")) {
|
||||||
val root0 = if (root.endsWith("/")) root else root + "/"
|
val root0 = if (root.endsWith("/")) root else root + "/"
|
||||||
Some(MavenRepository(root0))
|
Some(MavenRepository(root0, sbtAttrStub = true))
|
||||||
} else {
|
} else {
|
||||||
Console.err.println(s"Warning: unrecognized Maven repository protocol in $root, ignoring it")
|
Console.err.println(s"Warning: unrecognized Maven repository protocol in $root, ignoring it")
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue