Merge pull request #96 from alexarchambault/topic/better-ivy-local

Better ~/.ivy2/local
This commit is contained in:
Alexandre Archambault 2016-01-02 14:29:54 +01:00
commit be912e8891
6 changed files with 67 additions and 107 deletions

View File

@ -6,6 +6,8 @@ import java.nio.file.{ StandardCopyOption, Files => NioFiles }
import java.security.MessageDigest import java.security.MessageDigest
import java.util.concurrent.{ConcurrentHashMap, Executors, ExecutorService} import java.util.concurrent.{ConcurrentHashMap, Executors, ExecutorService}
import coursier.ivy.IvyRepository
import scala.annotation.tailrec import scala.annotation.tailrec
import scalaz._ import scalaz._
import scalaz.concurrent.{ Task, Strategy } import scalaz.concurrent.{ Task, Strategy }
@ -464,9 +466,11 @@ object Cache {
} }
} }
lazy val ivy2Local = MavenRepository( lazy val ivy2Local = IvyRepository(
new File(sys.props("user.home") + "/.ivy2/local/").toURI.toString, // a bit touchy on Windows... - don't try to get the URI manually like s"file://..."
ivyLike = true new File(sys.props("user.home") + "/.ivy2/local/").toURI.toString +
"[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/" +
"[artifact](-[classifier]).[ext]"
) )
val defaultConcurrentDownloadCount = 6 val defaultConcurrentDownloadCount = 6

View File

@ -67,12 +67,9 @@ class Helper(
val pool = Executors.newFixedThreadPool(parallel, Strategy.DefaultDaemonThreadFactory) val pool = Executors.newFixedThreadPool(parallel, Strategy.DefaultDaemonThreadFactory)
val central = MavenRepository("https://repo1.maven.org/maven2/") val central = MavenRepository("https://repo1.maven.org/maven2/")
val ivy2Local = MavenRepository(
new File(sys.props("user.home") + "/.ivy2/local/").toURI.toString,
ivyLike = true
)
val defaultRepositories = Seq( val defaultRepositories = Seq(
ivy2Local, Cache.ivy2Local,
central central
) )
@ -81,7 +78,7 @@ class Helper(
if (repo0 == "central") if (repo0 == "central")
Right(central) Right(central)
else if (repo0 == "ivy2local") else if (repo0 == "ivy2local")
Right(ivy2Local) Right(Cache.ivy2Local)
else if (repo0.startsWith("sonatype:")) else if (repo0.startsWith("sonatype:"))
Right( Right(
MavenRepository(s"https://oss.sonatype.org/content/repositories/${repo.drop("sonatype:".length)}") MavenRepository(s"https://oss.sonatype.org/content/repositories/${repo.drop("sonatype:".length)}")
@ -91,12 +88,8 @@ class Helper(
if (repo.startsWith("ivy:")) { if (repo.startsWith("ivy:")) {
val url = repo.drop("ivy:".length) val url = repo.drop("ivy:".length)
(url, IvyRepository(url)) (url, IvyRepository(url))
} else if (repo.startsWith("ivy-like:")) { } else
val url = repo.drop("ivy-like:".length)
(url, MavenRepository(url, ivyLike = true))
} else {
(repo, MavenRepository(repo)) (repo, MavenRepository(repo))
}
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file:/")) if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file:/"))
Right(r) Right(r)

View File

@ -60,7 +60,6 @@ object MavenRepository {
case class MavenRepository( case class MavenRepository(
root: String, root: String,
ivyLike: Boolean = false,
changing: Option[Boolean] = None, changing: Option[Boolean] = None,
/** Hackish hack for sbt plugins mainly - what this does really sucks */ /** Hackish hack for sbt plugins mainly - what this does really sucks */
sbtAttrStub: Boolean = false sbtAttrStub: Boolean = false
@ -70,7 +69,7 @@ case class MavenRepository(
import MavenRepository._ import MavenRepository._
val root0 = if (root.endsWith("/")) root else root + "/" val root0 = if (root.endsWith("/")) root else root + "/"
val source = MavenSource(root0, ivyLike, changing, sbtAttrStub) val source = MavenSource(root0, changing, sbtAttrStub)
def projectArtifact( def projectArtifact(
module: Module, module: Module,
@ -78,27 +77,14 @@ case class MavenRepository(
versioningValue: Option[String] versioningValue: Option[String]
): Artifact = { ): Artifact = {
val path = ( val path = module.organization.split('.').toSeq ++ Seq(
if (ivyLike) dirModuleName(module, sbtAttrStub),
ivyLikePath( version,
module.organization, s"${module.name}-${versioningValue getOrElse version}.pom"
dirModuleName(module, sbtAttrStub), // maybe not what we should do here, don't know )
module.name,
versioningValue getOrElse version,
"poms",
"",
"pom"
)
else
module.organization.split('.').toSeq ++ Seq(
dirModuleName(module, sbtAttrStub),
version,
s"${module.name}-${versioningValue getOrElse version}.pom"
)
) .map(encodeURIComponent)
Artifact( Artifact(
root0 + path.mkString("/"), root0 + path.map(encodeURIComponent).mkString("/"),
Map.empty, Map.empty,
Map.empty, Map.empty,
Attributes("pom", ""), Attributes("pom", ""),
@ -108,57 +94,51 @@ case class MavenRepository(
.withDefaultSignature .withDefaultSignature
} }
def versionsArtifact(module: Module): Option[Artifact] = def versionsArtifact(module: Module): Option[Artifact] = {
if (ivyLike) None
else {
val path = (
module.organization.split('.').toSeq ++ Seq(
dirModuleName(module, sbtAttrStub),
"maven-metadata.xml"
)
) .map(encodeURIComponent)
val artifact = val path = module.organization.split('.').toSeq ++ Seq(
Artifact( dirModuleName(module, sbtAttrStub),
root0 + path.mkString("/"), "maven-metadata.xml"
Map.empty, )
Map.empty,
Attributes("pom", ""),
changing = true
)
.withDefaultChecksums
.withDefaultSignature
Some(artifact) val artifact =
} Artifact(
root0 + path.map(encodeURIComponent).mkString("/"),
Map.empty,
Map.empty,
Attributes("pom", ""),
changing = true
)
.withDefaultChecksums
.withDefaultSignature
Some(artifact)
}
def snapshotVersioningArtifact( def snapshotVersioningArtifact(
module: Module, module: Module,
version: String version: String
): Option[Artifact] = ): Option[Artifact] = {
if (ivyLike) None
else {
val path = (
module.organization.split('.').toSeq ++ Seq(
dirModuleName(module, sbtAttrStub),
version,
"maven-metadata.xml"
)
) .map(encodeURIComponent)
val artifact = val path = module.organization.split('.').toSeq ++ Seq(
Artifact( dirModuleName(module, sbtAttrStub),
root0 + path.mkString("/"), version,
Map.empty, "maven-metadata.xml"
Map.empty, )
Attributes("pom", ""),
changing = true
)
.withDefaultChecksums
.withDefaultSignature
Some(artifact) val artifact =
} Artifact(
root0 + path.map(encodeURIComponent).mkString("/"),
Map.empty,
Map.empty,
Attributes("pom", ""),
changing = true
)
.withDefaultChecksums
.withDefaultSignature
Some(artifact)
}
def versions[F[_]]( def versions[F[_]](
module: Module, module: Module,

View File

@ -4,7 +4,6 @@ import coursier.core._
case class MavenSource( case class MavenSource(
root: String, root: String,
ivyLike: Boolean,
changing: Option[Boolean] = None, changing: Option[Boolean] = None,
/** See doc on MavenRepository */ /** See doc on MavenRepository */
sbtAttrStub: Boolean sbtAttrStub: Boolean
@ -46,34 +45,18 @@ case class MavenSource(
): Seq[Artifact] = { ): Seq[Artifact] = {
def artifactOf(module: Module, publication: Publication) = { def artifactOf(module: Module, publication: Publication) = {
def ivyLikePath0(subDir: String, baseSuffix: String, ext: String) =
ivyLikePath( val versioning = project
module.organization, .snapshotVersioning
MavenRepository.dirModuleName(module, sbtAttrStub), .flatMap(versioning =>
module.name, mavenVersioning(versioning, publication.classifier, publication.`type`)
project.version,
subDir,
baseSuffix,
ext
) )
val path = val path = module.organization.split('.').toSeq ++ Seq(
if (ivyLike) MavenRepository.dirModuleName(module, sbtAttrStub),
ivyLikePath0(publication.`type` + "s", "", publication.ext) project.version,
else { s"${module.name}-${versioning getOrElse project.version}${Some(publication.classifier).filter(_.nonEmpty).map("-" + _).mkString}.${publication.ext}"
val versioning = )
project
.snapshotVersioning
.flatMap(versioning =>
mavenVersioning(versioning, publication.classifier, publication.`type`)
)
module.organization.split('.').toSeq ++ Seq(
MavenRepository.dirModuleName(module, sbtAttrStub),
project.version,
s"${module.name}-${versioning getOrElse project.version}${Some(publication.classifier).filter(_.nonEmpty).map("-" + _).mkString}.${publication.ext}"
)
}
val changing0 = changing.getOrElse(project.version.contains("-SNAPSHOT")) val changing0 = changing.getOrElse(project.version.contains("-SNAPSHOT"))
var artifact = var artifact =

View File

@ -221,7 +221,7 @@ object Tasks {
val interProjectRepo = InterProjectRepository(projects) val interProjectRepo = InterProjectRepository(projects)
val ivyProperties = Map( val ivyProperties = Map(
"ivy.home" -> s"${sys.props("user.home")}/.ivy2" "ivy.home" -> (new File(sys.props("user.home")).toURI.getPath + "/.ivy2")
) ++ sys.props ) ++ sys.props
val repositories = Seq(globalPluginsRepo, interProjectRepo) ++ resolvers.flatMap(FromSbt.repository(_, ivyProperties)) val repositories = Seq(globalPluginsRepo, interProjectRepo) ++ resolvers.flatMap(FromSbt.repository(_, ivyProperties))

View File

@ -378,7 +378,7 @@ object App {
)), )),
<.td(Seq[Seq[TagMod]]( <.td(Seq[Seq[TagMod]](
res.projectCache.get(dep.moduleVersion) match { res.projectCache.get(dep.moduleVersion) match {
case Some((source: MavenSource, proj)) if !source.ivyLike => case Some((source: MavenSource, proj)) =>
// FIXME Maven specific, generalize with source.artifacts // FIXME Maven specific, generalize with source.artifacts
val version0 = finalVersionOpt getOrElse dep.version val version0 = finalVersionOpt getOrElse dep.version
val relPath = val relPath =