Skip to content

Commit

Permalink
Merge pull request #1109 from coursier/develop
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
alexarchambault committed Apr 4, 2019
2 parents 2abcace + e9f93e2 commit 23027f1
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 26 deletions.
Expand Up @@ -150,7 +150,7 @@ object CacheUrl {
conn match {
case conn0: HttpURLConnection =>
val c = conn0.getResponseCode
if (c == 301 || c == 307 || c == 308)
if (c == 301 || c == 302 || c == 303 || c == 304 || c == 307 || c == 308)
Option(conn0.getHeaderField("Location"))
else
None
Expand Down
Expand Up @@ -71,6 +71,8 @@ final class FileCache[F[_]](private val params: FileCache.Params[F]) extends Cac
withParams(params.copy(checksums = checksums))
def withCredentials(credentials: Seq[Credentials]): FileCache[F] =
withParams(params.copy(credentials = credentials))
def noCredentials: FileCache[F] =
withParams(params.copy(credentials = Nil))
def addCredentials(credentials: Credentials*): FileCache[F] =
withParams(params.copy(credentials = params.credentials ++ credentials))
def addFileCredentials(credentialFile: File): FileCache[F] =
Expand Down
Expand Up @@ -5,5 +5,6 @@ import coursier.util.Task
abstract class PlatformCacheCompanion {

lazy val default: Cache[Task] = FileCache()
.noCredentials

}
Expand Up @@ -61,9 +61,24 @@ object FileCacheTests extends TestSuite {
else
BadRequest()

case GET -> Root / "self-redirect-301" =>
MovedPermanently("redirecting", Location(Uri(path = "/hello")))

case GET -> Root / "self-redirect-302" =>
Found("redirecting", Location(Uri(path = "/hello")))

case GET -> Root / "self-redirect-303" =>
SeeOther("redirecting", Location(Uri(path = "/hello")))

case GET -> Root / "self-redirect-304" =>
NotModified(Location(Uri(path = "/hello")))

case GET -> Root / "self-redirect" =>
TemporaryRedirect("redirecting", Location(Uri(path = "/hello")))

case GET -> Root / "self-redirect-308" =>
PermanentRedirect("redirecting", Location(Uri(path = "/hello")))

case GET -> Root / "self-auth-redirect" =>
TemporaryRedirect("redirecting", Location(Uri(path = "/auth/hello")))

Expand Down Expand Up @@ -193,6 +208,7 @@ object FileCacheTests extends TestSuite {
}

private def fileCache0() = FileCache()
.noCredentials
.withSslSocketFactory(clientSslContext.getSocketFactory)
.withHostnameVerifier(dummyHostnameVerifier)

Expand Down Expand Up @@ -232,7 +248,11 @@ object FileCacheTests extends TestSuite {
'redirections - {

'httpToHttp - {
expect(httpBaseUri / "self-redirect", "hello")
"301" - expect(httpBaseUri / "self-redirect-301", "hello")
"302" - expect(httpBaseUri / "self-redirect-302", "hello")
"302" - expect(httpBaseUri / "self-redirect-304", "hello")
"307" - expect(httpBaseUri / "self-redirect", "hello")
"308" - expect(httpBaseUri / "self-redirect-308", "hello")
}

'httpsToHttps - {
Expand Down
Expand Up @@ -35,13 +35,15 @@ object AuthenticationTests extends TestSuite {
* - {
val result = withTmpDir { dir =>
Resolve()
.noMirrors
.withRepositories(Seq(
MavenRepository(testRepo),
Repositories.central
))
.addDependencies(dep"com.abc:test:0.1".copy(transitive = false))
.withCache(
FileCache()
.noCredentials
.withLocation(dir.toFile)
.addCredentials(
DirectCredentials()
Expand Down
6 changes: 6 additions & 0 deletions modules/coursier/jvm/src/main/scala/coursier/Fetch.scala
Expand Up @@ -114,6 +114,12 @@ final class Fetch[F[_]] private (
def addRepositories(repositories: Repository*): Fetch[F] =
withResolveParams(resolveParams.copy(repositories = resolveParams.repositories ++ repositories))

def noMirrors: Fetch[F] =
withResolveParams(resolveParams.copy(
mirrors = Nil,
mirrorConfFiles = Nil
))

def withMirrors(mirrors: Seq[Mirror]): Fetch[F] =
withResolveParams(resolveParams.copy(mirrors = mirrors))
def addMirrors(mirrors: Mirror*): Fetch[F] =
Expand Down
Empty file.
@@ -0,0 +1,2 @@
jcenter.from=https://repo1.maven.org/maven2
jcenter.to=https://jcenter.bintray.com
Expand Up @@ -14,13 +14,15 @@ object ArtifactsTests extends TestSuite {

val res1 = await {
Resolve()
.noMirrors
.addDependencies(dep"io.argonaut:argonaut_2.12:6.2.2")
.withCache(cache)
.future()
}

val res2 = await {
Resolve()
.noMirrors
.addDependencies(dep"com.chuusai:shapeless_2.12:2.3.2")
.withCache(cache)
.future()
Expand Down Expand Up @@ -56,6 +58,7 @@ object ArtifactsTests extends TestSuite {

val res = await {
Resolve()
.noMirrors
.addDependencies(dep"com.chuusai:shapeless_2.12:2.3.2")
.withCache(cache)
.future()
Expand Down Expand Up @@ -92,6 +95,7 @@ object ArtifactsTests extends TestSuite {

val res = await {
Resolve()
.noMirrors
.addDependencies(dep"com.chuusai:shapeless_2.12:2.3.2")
.withCache(cache)
.future()
Expand Down
Expand Up @@ -57,9 +57,11 @@ object FetchCacheTests extends TestSuite {

def artifacts() =
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(
FileCache()
.noCredentials
.withLocation(tmpCache.toFile)
)
.withFetchCache(tmpFetchCache.toFile)
Expand Down
6 changes: 6 additions & 0 deletions modules/coursier/jvm/src/test/scala/coursier/FetchTests.scala
Expand Up @@ -15,6 +15,7 @@ object FetchTests extends TestSuite {

val (res, artifacts) = await {
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(cache)
.futureResult()
Expand All @@ -28,6 +29,7 @@ object FetchTests extends TestSuite {
val classifiers = Set(Classifier.sources)
val (res, artifacts) = await {
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(cache)
.withClassifiers(classifiers)
Expand All @@ -43,6 +45,7 @@ object FetchTests extends TestSuite {
val mainArtifacts = true
val (res, artifacts) = await {
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(cache)
.withClassifiers(classifiers)
Expand All @@ -58,6 +61,7 @@ object FetchTests extends TestSuite {
val classifiers = Set(Classifier.javadoc)
val (res, artifacts) = await {
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(cache)
.withClassifiers(classifiers)
Expand All @@ -73,6 +77,7 @@ object FetchTests extends TestSuite {
val mainArtifacts = true
val (res, artifacts) = await {
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(cache)
.withClassifiers(classifiers)
Expand All @@ -88,6 +93,7 @@ object FetchTests extends TestSuite {
val classifiers = Set(Classifier.javadoc, Classifier.sources)
val (res, artifacts) = await {
Fetch()
.noMirrors
.addDependencies(dep"io.get-coursier:coursier-cli_2.12:1.1.0-M8")
.withCache(cache)
.withClassifiers(classifiers)
Expand Down
Expand Up @@ -3,20 +3,53 @@ package coursier
import coursier.params.MirrorConfFile
import utest._

import scala.async.Async.{async, await}

object MirrorConfFileTests extends TestSuite {

import TestHelpers.{ec, cache, validateDependencies}

val tests = Tests {
'simple - {
val path = Option(getClass.getResource("/test-mirror.properties"))
'read - {
val path = Option(getClass.getResource("/empty-mirror.properties"))
.map(_.getPath)
.getOrElse {
throw new Exception("test-mirror.properties resource not found")
throw new Exception("empty-mirror.properties resource not found")
}
val f = MirrorConfFile(path)
val mirrors = f.mirrors()
val expectedMirrors = Seq()
assert(mirrors == expectedMirrors)
}


'resolve - {

def run(file: MirrorConfFile) = async {
val res = await {
Resolve()
.noMirrors
.withCache(cache)
.addMirrorConfFiles(file)
.addDependencies(dep"com.github.alexarchambault:argonaut-shapeless_6.2_2.12:1.2.0-M10")
.future()
}

await(validateDependencies(res))

val artifacts = res.artifacts()
assert(artifacts.forall(_.url.startsWith("https://jcenter.bintray.com")))
}

* - {
val mirrorFilePath = Option(getClass.getResource("/test-mirror.properties"))
.map(_.getPath)
.getOrElse {
throw new Exception("test-mirror.properties resource not found")
}
run(MirrorConfFile(mirrorFilePath))
}
}
}

}
60 changes: 39 additions & 21 deletions modules/coursier/shared/src/main/scala/coursier/Resolve.scala
Expand Up @@ -46,23 +46,20 @@ final class Resolve[F[_]] private[coursier] (private val params: Resolve.Params[
def S: Sync[F] =
params.S

def finalRepositories: Seq[Repository] = {

val repositories0 = repositories
val mirrors0 = mirrors

repositories0
.map { repo =>
val it = mirrors0
.iterator
.flatMap(_.matches(repo).iterator)
if (it.hasNext)
it.next()
else
repo
}
.distinct
}
def finalRepositories: F[Seq[Repository]] =
S.map(allMirrors) { mirrors0 =>
repositories
.map { repo =>
val it = mirrors0
.iterator
.flatMap(_.matches(repo).iterator)
if (it.hasNext)
it.next()
else
repo
}
.distinct
}

private def withParams(params: Resolve.Params[F]): Resolve[F] =
new Resolve(params)
Expand All @@ -78,6 +75,12 @@ final class Resolve[F[_]] private[coursier] (private val params: Resolve.Params[
def addRepositories(repositories: Repository*): Resolve[F] =
withParams(params.copy(repositories = params.repositories ++ repositories))

def noMirrors: Resolve[F] =
withParams(params.copy(
mirrors = Nil,
mirrorConfFiles = Nil
))

def withMirrors(mirrors: Seq[Mirror]): Resolve[F] =
withParams(params.copy(mirrors = mirrors))
def addMirrors(mirrors: Mirror*): Resolve[F] =
Expand Down Expand Up @@ -108,16 +111,25 @@ final class Resolve[F[_]] private[coursier] (private val params: Resolve.Params[
def withTransformFetcher(fOpt: Option[ResolutionProcess.Fetch[F] => ResolutionProcess.Fetch[F]]): Resolve[F] =
withParams(params.copy(transformFetcherOpt = fOpt))

private def allMirrors0 = {
val l = mirrors ++ mirrorConfFiles.flatMap(_.mirrors())
println(s"mirrorConfFiles=${mirrorConfFiles}")
println(s"allMirrors0=$l")
l
}

def allMirrors: F[Seq[Mirror]] =
S.delay(allMirrors0)


private def fetchVia: ResolutionProcess.Fetch[F] = {
private def fetchVia: F[ResolutionProcess.Fetch[F]] = {
val fetchs = params.cache.fetchs
ResolutionProcess.fetch(finalRepositories, fetchs.head, fetchs.tail: _*)(S)
S.map(finalRepositories)(r => ResolutionProcess.fetch(r, fetchs.head, fetchs.tail: _*)(S))
}

def ioWithConflicts: F[(Resolution, Seq[UnsatisfiedRule])] = {
private def ioWithConflicts0(fetch: ResolutionProcess.Fetch[F]): F[(Resolution, Seq[UnsatisfiedRule])] = {

val initialRes = Resolve.initialResolution(params.dependencies, params.resolutionParams)
val fetch = params.transformFetcher(fetchVia)

def run(res: Resolution): F[Resolution] = {
val t = Resolve.runProcess(res, fetch, params.resolutionParams.maxIterations, params.cache.loggerOpt)(S)
Expand Down Expand Up @@ -179,6 +191,12 @@ final class Resolve[F[_]] private[coursier] (private val params: Resolve.Params[
}
}

def ioWithConflicts: F[(Resolution, Seq[UnsatisfiedRule])] =
S.bind(fetchVia) { f =>
val fetchVia0 = params.transformFetcher(f)
ioWithConflicts0(fetchVia0)
}

def io: F[Resolution] =
S.map(ioWithConflicts)(_._1)

Expand Down
Expand Up @@ -13,6 +13,7 @@ object DependencyTests extends TestSuite {
'hadoopClient - async {
val res = await {
Resolve()
.noMirrors
.addDependencies(dep"org.apache.hadoop:hadoop-client:3.2.0")
.withCache(cache)
.future()
Expand Down

0 comments on commit 23027f1

Please sign in to comment.