Permalink
Browse files

Move local repositories definitions to coursier.cache.LocalRepositories

not sure this should live in the coursier.cache namespace…
  • Loading branch information...
alexarchambault committed Dec 4, 2018
1 parent c6c0df8 commit f92a81b1123021055ee6423428ee2782a1c8bfec
@@ -60,7 +60,7 @@ assert(!start.isDone)
In order for the resolution to go on, we'll need things from a few repositories,
```scala mdoc:silent
val repositories = Seq(
Cache.ivy2Local,
coursier.cache.LocalRepositories.ivy2Local,
MavenRepository("https://repo1.maven.org/maven2")
)
```
@@ -21,7 +21,7 @@ import coursier.{ Cache => _, _ }
```scala mdoc:passthrough
object Cache {
val ivy2LocalIsIvy = coursier.Cache.ivy2Local match {
val ivy2LocalIsIvy = coursier.cache.LocalRepositories.ivy2Local match {
case _: coursier.ivy.IvyRepository => true
case _ => false
}
@@ -7,7 +7,6 @@ import java.util.concurrent.{ConcurrentHashMap, ExecutorService}
import java.util.regex.Pattern
import coursier.core.Authentication
import coursier.ivy.IvyRepository
import coursier.paths.CachePath
import scala.annotation.tailrec
@@ -1041,40 +1040,6 @@ object Cache {
}
}
private lazy val ivy2HomeUri = {
val path =
sys.props.get("coursier.ivy.home")
.orElse(sys.props.get("ivy.home"))
.getOrElse(sys.props("user.home") + "/.ivy2/")
// a bit touchy on Windows... - don't try to manually write down the URI with s"file://..."
val str = new File(path).toURI.toString
if (str.endsWith("/"))
str
else
str + "/"
}
lazy val ivy2Local = IvyRepository.fromPattern(
(ivy2HomeUri + "local/") +: coursier.ivy.Pattern.default,
dropInfoAttributes = true
)
lazy val ivy2Cache = IvyRepository.parse(
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
).right.getOrElse(
throw new Exception("Cannot happen")
)
private val urlLocks = new ConcurrentHashMap[String, Object]
var bufferSize = 1024*1024
@@ -1089,26 +1054,4 @@ object Cache {
}
}
object Dangerous {
/**
* m2 local isn't guaranteed to always work fine with coursier (it sometimes has only the
* metadata of some dependencies, and coursier isn't fine with that - coursier requires
* both the metadata and the JARs to be in the same repo)
* see https://github.com/coursier/coursier/pull/868#issuecomment-398779799
*/
lazy val maven2Local = {
// TODO Add a small unit test for that repo…
// 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")).toURI.toString
val homeUri =
if (str.endsWith("/"))
str
else
str + "/"
MavenRepository(homeUri + ".m2/repository")
}
}
}
@@ -2,6 +2,7 @@ package coursier
import java.net.MalformedURLException
import coursier.cache.LocalRepositories
import coursier.core.Authentication
import coursier.ivy.IvyRepository
import coursier.util.{Parse, ValidationNel}
@@ -11,9 +12,9 @@ object CacheParse {
def repository(s: String): Either[String, Repository] =
if (s == "ivy2local" || s == "ivy2Local")
Right(Cache.ivy2Local)
Right(LocalRepositories.ivy2Local)
else if (s == "ivy2cache" || s == "ivy2Cache")
Right(Cache.ivy2Cache)
Right(LocalRepositories.ivy2Cache)
else {
val repo = Parse.repository(s)
@@ -0,0 +1,69 @@
package coursier.cache
import java.io.File
import coursier.ivy.IvyRepository
import coursier.maven.MavenRepository
// not sure this should live in the coursier.cache namespace…
object LocalRepositories {
private lazy val ivy2HomeUri = {
val path =
sys.props.get("coursier.ivy.home")
.orElse(sys.props.get("ivy.home"))
.getOrElse(sys.props("user.home") + "/.ivy2/")
// a bit touchy on Windows... - don't try to manually write down the URI with s"file://..."
val str = new File(path).toURI.toString
if (str.endsWith("/"))
str
else
str + "/"
}
lazy val ivy2Local = IvyRepository.fromPattern(
(ivy2HomeUri + "local/") +: coursier.ivy.Pattern.default,
dropInfoAttributes = true
)
lazy val ivy2Cache = IvyRepository.parse(
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
).right.getOrElse(
throw new Exception("Cannot happen")
)
object Dangerous {
/**
* m2 local isn't guaranteed to always work fine with coursier (it sometimes has only the
* metadata of some dependencies, and coursier isn't fine with that - coursier requires
* both the metadata and the JARs to be in the same repo)
* see https://github.com/coursier/coursier/pull/868#issuecomment-398779799
*/
lazy val maven2Local = {
// TODO Add a small unit test for that repo…
// 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")).toURI.toString
val homeUri =
if (str.endsWith("/"))
str
else
str + "/"
MavenRepository(homeUri + ".m2/repository")
}
}
}
@@ -5,7 +5,7 @@ import java.io.{File, OutputStreamWriter, PrintWriter}
import java.net.{URL, URLClassLoader, URLDecoder}
import java.util.jar.{Manifest => JManifest}
import coursier.cache.CacheDefaults
import coursier.cache.{CacheDefaults, LocalRepositories}
import coursier.cli.options.{CommonOptions, IsolatedLoaderOptions}
import coursier.cli.scaladex.Scaladex
import coursier.cli.util.{JsonElem, JsonPrintRequirement, JsonReport}
@@ -95,7 +95,7 @@ class Helper(
val ec = ExecutionContext.fromExecutorService(pool)
val defaultRepositories = Seq(
Cache.ivy2Local,
LocalRepositories.ivy2Local,
MavenRepository("https://repo1.maven.org/maven2")
)
@@ -1,7 +1,8 @@
package coursier.cli.params.shared
import cats.data.{NonEmptyList, Validated, ValidatedNel}
import coursier.{Cache, CacheParse}
import coursier.cache.LocalRepositories
import coursier.CacheParse
import coursier.cli.options.shared.RepositoryOptions
import coursier.core.Repository
import coursier.ivy.IvyRepository
@@ -11,7 +12,7 @@ import coursier.maven.MavenRepository
object RepositoryParams {
private val defaultRepositories = Seq(
Cache.ivy2Local,
LocalRepositories.ivy2Local,
MavenRepository("https://repo1.maven.org/maven2")
)
@@ -1,7 +1,8 @@
package coursier.test
import coursier.cache.LocalRepositories
import coursier.core.{Classifier, Type}
import coursier.{Cache, Dependency, Module, moduleNameString, moduleString, organizationString}
import coursier.{Dependency, moduleString}
import coursier.test.compatibility._
import scala.async.Async.{async, await}
@@ -16,7 +17,7 @@ object IvyLocalTests extends TestSuite {
val module = mod"io.get-coursier:coursier-core_2.11"
val version = coursier.util.Properties.version
val extraRepos = Seq(Cache.ivy2Local)
val extraRepos = Seq(LocalRepositories.ivy2Local)
// Assuming this module (and the sub-projects it depends on) is published locally
'resolution - runner.resolutionCheck(

0 comments on commit f92a81b

Please sign in to comment.