Add support for ~/.ivy2/cache as a repository

This commit is contained in:
Alexandre Archambault 2016-01-14 00:47:53 +01:00
parent c476b08f32
commit a9f3403520
3 changed files with 43 additions and 5 deletions

View File

@ -467,13 +467,33 @@ object Cache {
}
}
private lazy val ivy2HomeUri = {
// a bit touchy on Windows... - don't try to manually write down the URI with s"file://..."
val str = new File(sys.props("user.home") + "/.ivy2/").toURI.toString
if (str.endsWith("/"))
str
else
str + "/"
}
lazy val ivy2Local = IvyRepository(
// a bit touchy on Windows... - don't try to get the URI manually like s"file://..."
new File(sys.props("user.home") + "/.ivy2/local/").toURI.toString +
ivy2HomeUri + "local/" +
"[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/" +
"[artifact](-[classifier]).[ext]"
)
lazy val ivy2Cache = IvyRepository(
ivy2HomeUri + "cache/" +
"(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]",
metadataPatternOpt = Some(
ivy2HomeUri + "cache/" +
"(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[organisation]/[module]/[type]-[revision](-[classifier]).[ext]"
),
withChecksums = false,
withSignatures = false,
dropInfoAttributes = true
)
lazy val defaultBase = new File(
sys.env.getOrElse(
"COURSIER_CACHE",

View File

@ -10,6 +10,8 @@ object CacheParse {
def repository(s: String): Validation[String, Repository] =
if (s == "ivy2local" || s == "ivy2Local")
Cache.ivy2Local.success
else if (s == "ivy2cache" || s == "ivy2Cache")
Cache.ivy2Cache.success
else {
val repo = Parse.repository(s)

View File

@ -12,7 +12,9 @@ case class IvyRepository(
properties: Map[String, String] = Map.empty,
withChecksums: Boolean = true,
withSignatures: Boolean = true,
withArtifacts: Boolean = true
withArtifacts: Boolean = true,
// hack for SBT putting infos in properties
dropInfoAttributes: Boolean = false
) extends Repository {
def metadataPattern: String = metadataPatternOpt.getOrElse(pattern)
@ -138,14 +140,28 @@ case class IvyRepository(
for {
artifact <- EitherT(F.point(eitherArtifact))
ivy <- fetch(artifact)
proj <- EitherT(F.point {
proj0 <- EitherT(F.point {
for {
xml <- \/.fromEither(compatibility.xmlParse(ivy))
_ <- if (xml.label == "ivy-module") \/-(()) else -\/("Module definition not found")
proj <- IvyXml.project(xml)
} yield proj
})
} yield (source, proj)
} yield {
val proj =
if (dropInfoAttributes)
proj0.copy(
module = proj0.module.copy(
attributes = proj0.module.attributes.filter {
case (k, _) => !k.startsWith("info.")
}
)
)
else
proj0
(source, proj)
}
}
}