From 2a5804caecf2b45f415bbd892ec9c81b9910189f Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 19 Sep 2018 10:55:18 +0200 Subject: [PATCH 1/8] nitpicking --- .../src/main/scala/coursier/core/Definitions.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/shared/src/main/scala/coursier/core/Definitions.scala b/core/shared/src/main/scala/coursier/core/Definitions.scala index 859c9e565..d21ae5a9c 100644 --- a/core/shared/src/main/scala/coursier/core/Definitions.scala +++ b/core/shared/src/main/scala/coursier/core/Definitions.scala @@ -73,18 +73,19 @@ final case class Attributes( `type`: String, classifier: String ) { - def packaging: String = if (`type`.isEmpty) + def packaging: String = + if (`type`.isEmpty) "jar" else `type` - def packagingAndClassifier: String = if (isEmpty) { + def packagingAndClassifier: String = + if (isEmpty) "" - } else if (classifier.isEmpty) { + else if (classifier.isEmpty) packaging - } else { + else s"$packaging:$classifier" - } def publication(name: String, ext: String): Publication = Publication(name, `type`, ext, classifier) From 2775ef396b52b16ef71ff1e5d84e61410f62e2d2 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 19 Sep 2018 15:04:52 +0200 Subject: [PATCH 2/8] Stop relying on non-optional artifacts in tests Once we don't rely on directory listings anymore, most JARs will be marked as optional. Also, attributes have to be set beforehand to get artifacts with specific types, as available artifacts cannot be listed beforehand. --- .../coursier/test/DirectoryListingTests.scala | 65 ++----- .../test/scala/coursier/test/IvyTests.scala | 48 ++--- .../test/scala/coursier/test/MavenTests.scala | 12 +- .../scala/coursier/test/CentralTests.scala | 166 ++++++------------ 4 files changed, 91 insertions(+), 200 deletions(-) diff --git a/tests/jvm/src/it/scala/coursier/test/DirectoryListingTests.scala b/tests/jvm/src/it/scala/coursier/test/DirectoryListingTests.scala index 024d574f7..6a62b444b 100644 --- a/tests/jvm/src/it/scala/coursier/test/DirectoryListingTests.scala +++ b/tests/jvm/src/it/scala/coursier/test/DirectoryListingTests.scala @@ -9,62 +9,35 @@ object DirectoryListingTests extends TestSuite { val user = "user" val password = "pass" - val withListingRepo = MavenRepository( + val repo = MavenRepository( "http://localhost:8080", authentication = Some(Authentication(user, password)) ) - val withoutListingRepo = MavenRepository( - "http://localhost:8081", - authentication = Some(Authentication(user, password)) - ) - val module = Module("com.abc", "test") val version = "0.1" val tests = Tests { - 'withListing - { - 'jar - CentralTests.withArtifacts( - module, - version, - "jar", - extraRepos = Seq(withListingRepo) - ) { - artifacts => - assert(artifacts.length == 1) - } - - 'jarFoo - CentralTests.withArtifacts( - module, - version, - "jar-foo", - extraRepos = Seq(withListingRepo) - ) { - artifacts => - assert(artifacts.length == 1) - } + 'jar - CentralTests.withArtifacts( + module, + version, + attributes = Attributes("jar"), + extraRepos = Seq(repo) + ) { + artifacts => + assert(artifacts.length == 1) + assert(artifacts.headOption.exists(_.url.endsWith(".jar"))) } - 'withoutListing - { - 'jar - CentralTests.withArtifacts( - module, - version, - "jar", - extraRepos = Seq(withoutListingRepo) - ) { - artifacts => - assert(artifacts.length == 1) - } - - 'jarFoo - CentralTests.withArtifacts( - module, - version, - "jar-foo", - extraRepos = Seq(withoutListingRepo) - ) { - artifacts => - assert(artifacts.length == 0) - } + 'jarFoo - CentralTests.withArtifacts( + module, + version, + attributes = Attributes("jar-foo"), + extraRepos = Seq(repo) + ) { + artifacts => + assert(artifacts.length == 1) + assert(artifacts.headOption.exists(_.url.endsWith(".jar-foo"))) } } diff --git a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala index 094a09931..f8a075244 100644 --- a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala +++ b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala @@ -46,8 +46,8 @@ object IvyTests extends TestSuite { extraRepos = Seq(sbtRepo) ) - * - CentralTests.withArtifact(mod, ver, "jar", extraRepos = Seq(sbtRepo)) { artifact => - assert(artifact.url == expectedArtifactUrl) + * - CentralTests.withArtifacts(mod, ver, Attributes("jar"), extraRepos = Seq(sbtRepo)) { artifacts => + assert(artifacts.exists(_.url == expectedArtifactUrl)) } } @@ -71,11 +71,9 @@ object IvyTests extends TestSuite { val testJarUrl = repoBase + "com.example/a_2.11/0.1.0-SNAPSHOT/jars/a_2.11-tests.jar" "no conf or classifier" - CentralTests.withArtifacts( - dep = dep, - artifactType = "jar", + dep = dep.copy(attributes = Attributes("jar")), extraRepos = Seq(repo), - classifierOpt = None, - optional = true + classifierOpt = None ) { case Seq(artifact) => assert(artifact.url == mainJarUrl) @@ -85,19 +83,12 @@ object IvyTests extends TestSuite { "test conf" - CentralTests.withArtifacts( dep = dep.copy(configuration = "test"), - artifactType = "jar", extraRepos = Seq(repo), - classifierOpt = None, - optional = true - ) { - case Seq(artifact1, artifact2) => - val urls = Set( - artifact1.url, - artifact2.url - ) - assert(urls == Set(mainJarUrl, testJarUrl)) - case other => - throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}") + classifierOpt = None + ) { artifacts => + val urls = artifacts.map(_.url).toSet + assert(urls(mainJarUrl)) + assert(urls(testJarUrl)) } "tests classifier" - { @@ -105,27 +96,18 @@ object IvyTests extends TestSuite { * - CentralTests.withArtifacts( deps = Set(dep, testsDep), - artifactType = "jar", extraRepos = Seq(repo), - classifierOpt = None, - optional = true - ) { - case Seq(artifact1, artifact2) => - val urls = Set( - artifact1.url, - artifact2.url - ) - assert(urls == Set(mainJarUrl, testJarUrl)) - case other => - throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}") + classifierOpt = None + ) { artifacts => + val urls = artifacts.map(_.url).toSet + assert(urls(mainJarUrl)) + assert(urls(testJarUrl)) } * - CentralTests.withArtifacts( dep = testsDep, - artifactType = "jar", extraRepos = Seq(repo), - classifierOpt = None, - optional = true + classifierOpt = None ) { case Seq(artifact) => assert(artifact.url == testJarUrl) diff --git a/tests/jvm/src/test/scala/coursier/test/MavenTests.scala b/tests/jvm/src/test/scala/coursier/test/MavenTests.scala index 7f039180d..ef01fa569 100644 --- a/tests/jvm/src/test/scala/coursier/test/MavenTests.scala +++ b/tests/jvm/src/test/scala/coursier/test/MavenTests.scala @@ -26,11 +26,9 @@ object MavenTests extends TestSuite { val sourcesJarUrl = repoBase + "com/abc/test-snapshot-special/0.1.0-SNAPSHOT/test-snapshot-special-0.1.0-20170421.034426-82-sources.jar" * - CentralTests.withArtifacts( - dep = dep, - artifactType = "jar", + dep = dep.copy(attributes = Attributes("jar")), extraRepos = Seq(repo), - classifierOpt = None, - optional = true + classifierOpt = None ) { case Seq(artifact) => assert(artifact.url == mainJarUrl) @@ -39,11 +37,9 @@ object MavenTests extends TestSuite { } * - CentralTests.withArtifacts( - dep = dep, - artifactType = "src", + dep = dep.copy(attributes = Attributes("src")), extraRepos = Seq(repo), - classifierOpt = Some("sources"), - optional = true + classifierOpt = Some("sources") ) { case Seq(artifact) => assert(artifact.url == sourcesJarUrl) diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 30de96a15..339847209 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -126,58 +126,33 @@ abstract class CentralTests extends TestSuite { assert(result == expected) } - def withArtifact[T]( - module: Module, - version: String, - artifactType: String, - attributes: Attributes = Attributes(), - extraRepos: Seq[Repository] = Nil - )( - f: Artifact => T - ): Future[T] = - withArtifacts(module, version, artifactType, attributes, extraRepos) { - case Seq(artifact) => - f(artifact) - case other => - throw new Exception( - s"Unexpected artifact list size: ${other.size}\n" + - "Artifacts:\n" + other.map(" " + _).mkString("\n") - ) - } - def withArtifacts[T]( module: Module, version: String, - artifactType: String, attributes: Attributes = Attributes(), extraRepos: Seq[Repository] = Nil, classifierOpt: Option[String] = None, - transitive: Boolean = false, - optional: Boolean = true + transitive: Boolean = false )( f: Seq[Artifact] => T ): Future[T] = { val dep = Dependency(module, version, transitive = transitive, attributes = attributes) - withArtifacts(dep, artifactType, extraRepos, classifierOpt, optional)(f) + withArtifacts(dep, extraRepos, classifierOpt)(f) } def withArtifacts[T]( dep: Dependency, - artifactType: String, extraRepos: Seq[Repository], - classifierOpt: Option[String], - optional: Boolean + classifierOpt: Option[String] )( f: Seq[Artifact] => T ): Future[T] = - withArtifacts(Set(dep), artifactType, extraRepos, classifierOpt, optional)(f) + withArtifacts(Set(dep), extraRepos, classifierOpt)(f) def withArtifacts[T]( deps: Set[Dependency], - artifactType: String, extraRepos: Seq[Repository], - classifierOpt: Option[String], - optional: Boolean + classifierOpt: Option[String] )( f: Seq[Artifact] => T ): Future[T] = async { @@ -191,13 +166,8 @@ abstract class CentralTests extends TestSuite { assert(isDone) val artifacts = classifierOpt - .fold(res.dependencyArtifacts(withOptional = optional))(c => res.dependencyClassifiersArtifacts(Seq(c))) + .fold(res.dependencyArtifacts(withOptional = true))(c => res.dependencyClassifiersArtifacts(Seq(c))) .map(_._2) - .filter { - if (artifactType == "*") _ => true - else - _.`type` == artifactType - } f(artifacts) } @@ -205,13 +175,12 @@ abstract class CentralTests extends TestSuite { def ensureHasArtifactWithExtension( module: Module, version: String, - artifactType: String, extension: String, attributes: Attributes = Attributes(), extraRepos: Seq[Repository] = Nil ): Future[Unit] = - withArtifact(module, version, artifactType, attributes = attributes, extraRepos = extraRepos) { artifact => - assert(artifact.url.endsWith("." + extension)) + withArtifacts(module, version, attributes = attributes, extraRepos = extraRepos) { artifacts => + assert(artifacts.exists(_.url.endsWith("." + extension))) } val tests = Tests { @@ -305,7 +274,7 @@ abstract class CentralTests extends TestSuite { mod, version, "jar", - "jar", + Attributes("jar"), extraRepos = Seq(extraRepo) ) } @@ -409,8 +378,8 @@ abstract class CentralTests extends TestSuite { * - resolutionCheck(mod, version) - * - withArtifact(mod, version, "jar") { artifact => - assert(artifact.url == expectedArtifactUrl) + * - withArtifacts(mod, version, Attributes("jar")) { artifacts => + assert(artifacts.exists(_.url == expectedArtifactUrl)) } } @@ -438,7 +407,8 @@ abstract class CentralTests extends TestSuite { Dependency( Module("org.scala-lang", "scala-compiler"), "2.11.8", configuration = config, - transitive = false + transitive = false, + attributes = Attributes("jar") ) withArtifacts( @@ -446,10 +416,8 @@ abstract class CentralTests extends TestSuite { intransitiveCompiler("default"), intransitiveCompiler("optional") ), - "jar", extraRepos = Nil, - classifierOpt = None, - optional = true + classifierOpt = None ) { case Seq() => throw new Exception("Expected one JAR") @@ -471,7 +439,6 @@ abstract class CentralTests extends TestSuite { module, version, tpe, - tpe, attributes = Attributes(tpe) ) @@ -480,7 +447,6 @@ abstract class CentralTests extends TestSuite { ensureHasArtifactWithExtension( module, version, - tpe, tpe ) } @@ -491,7 +457,6 @@ abstract class CentralTests extends TestSuite { * - ensureHasArtifactWithExtension( Module("com.google.guava", "guava"), "17.0", - "bundle", "jar" ) @@ -500,7 +465,6 @@ abstract class CentralTests extends TestSuite { * - ensureHasArtifactWithExtension( Module("com.google.guava", "guava"), "17.0", - "bundle", "jar", attributes = Attributes("jar") ) @@ -511,8 +475,8 @@ abstract class CentralTests extends TestSuite { ensureHasArtifactWithExtension( Module("org.bytedeco", "javacpp"), "1.1", - "maven-plugin", - "jar" + "jar", + Attributes("maven-plugin") ) } } @@ -530,7 +494,7 @@ abstract class CentralTests extends TestSuite { ) ) val res = await(resolve(deps, extraRepos = Seq(extraRepo))) - val filenames: Set[String] = res.artifacts.map(_.url.split("/").last).toSet + val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet assert(filenames.contains("avro-1.8.1.jar")) assert(!filenames.contains("avro-1.8.1-tests.jar")) } @@ -544,7 +508,7 @@ abstract class CentralTests extends TestSuite { ) ) val res = await(resolve(deps, extraRepos = Seq(extraRepo))) - val filenames: Set[String] = res.artifacts.map(_.url.split("/").last).toSet + val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet assert(!filenames.contains("avro-1.8.1.jar")) assert(filenames.contains("avro-1.8.1-tests.jar")) } @@ -561,7 +525,7 @@ abstract class CentralTests extends TestSuite { ) ) val res = await(resolve(deps, extraRepos = Seq(extraRepo))) - val filenames: Set[String] = res.artifacts.map(_.url.split("/").last).toSet + val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet assert(filenames.contains("avro-1.8.1.jar")) assert(filenames.contains("avro-1.8.1-tests.jar")) } @@ -589,7 +553,7 @@ abstract class CentralTests extends TestSuite { assert(conflicts.isEmpty) assert(isDone) - val artifacts = res.artifacts + val artifacts = res.artifacts(withOptional = true) val map = artifacts.groupBy(a => a) @@ -640,7 +604,6 @@ abstract class CentralTests extends TestSuite { val zookeeperTestArtifact = zookeeperTestArtifacts.head - assert(!isActualCentral || !zookeeperTestArtifact.isOptional) assert(zookeeperTestArtifact.attributes.`type` == "test-jar") assert(zookeeperTestArtifact.attributes.classifier == "tests") zookeeperTestArtifact.url.endsWith("-tests.jar") @@ -703,30 +666,21 @@ abstract class CentralTests extends TestSuite { * - resolutionCheck(mod, version) val mainTarGzUrl = s"$centralBase/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.tar.gz" - val expectedTarGzArtifactUrls = Set( - mainTarGzUrl, - s"$centralBase/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-bin.tar.gz" - ) - val mainZipUrl = s"$centralBase/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip" - val expectedZipArtifactUrls = Set( - mainZipUrl, - s"$centralBase/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-bin.zip" - ) 'tarGz - { * - { if (isActualCentral) - withArtifacts(mod, version, "tar.gz", classifierOpt = Some("bin"), transitive = true) { artifacts => - assert(artifacts.length == 2) + withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), transitive = true) { artifacts => + assert(artifacts.nonEmpty) val urls = artifacts.map(_.url).toSet - assert(urls == expectedTarGzArtifactUrls) + assert(urls.contains(mainTarGzUrl)) } else Future.successful(()) } * - { - withArtifacts(mod, version, "tar.gz", attributes = Attributes("tar.gz", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts => + withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts => assert(artifacts.nonEmpty) val urls = artifacts.map(_.url).toSet assert(urls.contains(mainTarGzUrl)) @@ -737,16 +691,16 @@ abstract class CentralTests extends TestSuite { 'zip - { * - { if (isActualCentral) - withArtifacts(mod, version, "zip", classifierOpt = Some("bin"), transitive = true) { artifacts => - assert(artifacts.length == 2) + withArtifacts(mod, version, attributes = Attributes("zip", "bin"), transitive = true) { artifacts => + assert(artifacts.nonEmpty) val urls = artifacts.map(_.url).toSet - assert(urls == expectedZipArtifactUrls) + assert(urls.contains(mainZipUrl)) } else Future.successful(()) } * - { - withArtifacts(mod, version, "zip", attributes = Attributes("zip", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts => + withArtifacts(mod, version, attributes = Attributes("zip", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts => assert(artifacts.nonEmpty) val urls = artifacts.map(_.url).toSet assert(urls.contains(mainZipUrl)) @@ -776,9 +730,8 @@ abstract class CentralTests extends TestSuite { * - resolutionCheck(mod, ver) - * - withArtifacts(mod, ver, "jar", transitive = true) { artifacts => - assert(artifacts.length == 1) - assert(artifacts.head.url == expectedUrl) + * - withArtifacts(mod, ver, transitive = true) { artifacts => + assert(artifacts.exists(_.url == expectedUrl)) } } } @@ -812,33 +765,32 @@ abstract class CentralTests extends TestSuite { def hasSha1(a: Artifact) = a.checksumUrls.contains("SHA-1") def hasMd5(a: Artifact) = a.checksumUrls.contains("MD5") def hasSig(a: Artifact) = a.extra.contains("sig") - def sigHasSig(a: Artifact) = a.extra.get("sig").exists(hasSig) * - resolutionCheck(mod, ver) - * - withArtifacts(mod, ver, "*") { artifacts => + * - withArtifacts(mod, ver, Attributes("bundle")) { artifacts => val jarOpt = artifacts.find(_.`type` == "bundle").orElse(artifacts.find(_.`type` == "jar")) - val pomOpt = artifacts.find(_.`type` == "pom") assert(jarOpt.nonEmpty) assert(jarOpt.forall(hasSha1)) assert(jarOpt.forall(hasMd5)) assert(jarOpt.forall(hasSig)) + } - if (isActualCentral) { - if (artifacts.length != 2 || jarOpt.isEmpty || pomOpt.isEmpty) - artifacts.foreach(println) + * - { + if (isActualCentral) + withArtifacts(mod, ver, Attributes("pom")) { artifacts => - assert(jarOpt.forall(_.`type` == "bundle")) - assert(artifacts.length == 2) - assert(pomOpt.nonEmpty) - assert(pomOpt.forall(hasSha1)) - assert(pomOpt.forall(hasMd5)) - assert(pomOpt.forall(hasSig)) - assert(jarOpt.forall(sigHasSig)) - assert(pomOpt.forall(sigHasSig)) - } + val pomOpt = artifacts.find(_.`type` == "pom") + + assert(pomOpt.nonEmpty) + assert(pomOpt.forall(hasSha1)) + assert(pomOpt.forall(hasMd5)) + assert(pomOpt.forall(hasSig)) + } + else + Future.successful(()) } } @@ -877,40 +829,28 @@ abstract class CentralTests extends TestSuite { val mod = Module("io.monix", "monix_2.12") val ver = "2.3.0" - val mainUrl = "https://repo1.maven.org/maven2/io/monix/monix_2.12/2.3.0/monix_2.12-2.3.0.jar" + val mainUrl = s"$centralBase/io/monix/monix_2.12/2.3.0/monix_2.12-2.3.0.jar" * - resolutionCheck(mod, ver) - * - { - if (isActualCentral) - withArtifacts(mod, ver, "jar") { artifacts => - val mainArtifactOpt = artifacts.find(_.url == mainUrl) - assert(mainArtifactOpt.nonEmpty) - assert(mainArtifactOpt.forall(_.isOptional)) - } - else - Future.successful(()) - } - - * - withArtifacts(mod, ver, "jar", optional = false) { artifacts => + * - withArtifacts(mod, ver, Attributes("jar")) { artifacts => val mainArtifactOpt = artifacts.find(_.url == mainUrl) - assert(mainArtifactOpt.isEmpty) + assert(mainArtifactOpt.nonEmpty) + assert(mainArtifactOpt.forall(_.isOptional)) } * - { if (isActualCentral) - withArtifacts(Module("com.lihaoyi", "scalatags_2.12"), "0.6.2", "jar", transitive = true, optional = false) { artifacts => - - assert(artifacts.forall(!_.isOptional)) + withArtifacts(Module("com.lihaoyi", "scalatags_2.12"), "0.6.2", Attributes("jar"), transitive = true) { artifacts => val urls = artifacts.map(_.url).toSet - val expectedUrls = Set( + val expectedUrls = Seq( "https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.0/scala-library-2.12.0.jar", "https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3.jar", "https://repo1.maven.org/maven2/com/lihaoyi/scalatags_2.12/0.6.2/scalatags_2.12-0.6.2.jar" ) - assert(urls == expectedUrls) + assert(expectedUrls.forall(urls)) } else Future.successful(()) @@ -925,7 +865,7 @@ abstract class CentralTests extends TestSuite { * - resolutionCheck(mod, ver, extraRepos = Seq(extraRepo)) - * - withArtifacts(mod, ver, "*", extraRepos = Seq(extraRepo), transitive = true) { artifacts => + * - withArtifacts(mod, ver, Attributes("aar"), extraRepos = Seq(extraRepo), transitive = true) { artifacts => val urls = artifacts.map(_.url).toSet val expectedUrls = Set( "https://maven.google.com/com/android/support/support-fragment/25.3.1/support-fragment-25.3.1.aar", @@ -964,7 +904,7 @@ abstract class CentralTests extends TestSuite { * - { if (isActualCentral) - withArtifacts(mod, ver, "*", extraRepos = extraRepos, transitive = true) { artifacts => + withArtifacts(mod, ver, Attributes("jar"), extraRepos = extraRepos, transitive = true) { artifacts => val urls = artifacts.map(_.url).toSet val expectedUrls = Set( "https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/com/cedarsoftware/json-io/4.9.9-TALEND/json-io-4.9.9-TALEND.jar", From 9968a12d10c85248dce8901bf8a1861a2e51c2a4 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 19 Sep 2018 15:34:54 +0200 Subject: [PATCH 3/8] Tweak Ivy repositories artifact handling --- .../scala/coursier/ivy/IvyRepository.scala | 9 ++++-- .../test/scala/coursier/test/IvyTests.scala | 28 +++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala b/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala index 05192d1b5..09239a120 100644 --- a/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala +++ b/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala @@ -79,9 +79,12 @@ final case class IvyRepository( } else if (dependency.attributes.`type`.nonEmpty) project.publications.collect { - case (_, p) - if p.classifier.isEmpty && ( - p.`type` == dependency.attributes.`type` || + case (conf, p) + if (conf == "*" || + conf == dependency.configuration || + project.allConfigurations.getOrElse(dependency.configuration, Set.empty).contains(conf)) && + ( + p.`type` == dependency.attributes.`type` || (p.ext == dependency.attributes.`type` && project.packagingOpt.toSeq.contains(p.`type`)) // wow ) => p diff --git a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala index f8a075244..ebebdc142 100644 --- a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala +++ b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala @@ -81,14 +81,26 @@ object IvyTests extends TestSuite { throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}") } - "test conf" - CentralTests.withArtifacts( - dep = dep.copy(configuration = "test"), - extraRepos = Seq(repo), - classifierOpt = None - ) { artifacts => - val urls = artifacts.map(_.url).toSet - assert(urls(mainJarUrl)) - assert(urls(testJarUrl)) + "test conf" - { + "no attributes" - CentralTests.withArtifacts( + dep = dep.copy(configuration = "test"), + extraRepos = Seq(repo), + classifierOpt = None + ) { artifacts => + val urls = artifacts.map(_.url).toSet + assert(urls(mainJarUrl)) + assert(urls(testJarUrl)) + } + + "attributes" - CentralTests.withArtifacts( + dep = dep.copy(configuration = "test", attributes = Attributes("jar")), + extraRepos = Seq(repo), + classifierOpt = None + ) { artifacts => + val urls = artifacts.map(_.url).toSet + assert(urls(mainJarUrl)) + assert(urls(testJarUrl)) + } } "tests classifier" - { From 48c58d1e96f4474b9b7e7fad6d7161db138d6737 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 19 Sep 2018 15:22:27 +0200 Subject: [PATCH 4/8] Don't rely on directory listings anymore --- .../coursier/maven/MavenRepository.scala | 103 +--------- .../scala/coursier/maven/MavenSource.scala | 192 +----------------- tests/metadata | 2 +- 3 files changed, 15 insertions(+), 282 deletions(-) diff --git a/core/shared/src/main/scala/coursier/maven/MavenRepository.scala b/core/shared/src/main/scala/coursier/maven/MavenRepository.scala index 4268e61fb..35cedf994 100644 --- a/core/shared/src/main/scala/coursier/maven/MavenRepository.scala +++ b/core/shared/src/main/scala/coursier/maven/MavenRepository.scala @@ -316,110 +316,21 @@ final case class MavenRepository( proj <- Pom.project(xml, relocationAsDependency = true).right } yield proj - def isArtifact(fileName: String, prefix: String): Option[(String, String)] = - // TODO There should be a regex for that... - if (fileName.startsWith(prefix)) { - val end = fileName.stripPrefix(prefix) - val idx = end.indexOf('.') - if (idx >= 0) { - val ext = end.drop(idx + 1) - val rem = end.take(idx) - if (rem.isEmpty) - Some(("", ext)) - else if (rem.startsWith("-")) - Some((rem.drop(1), ext)) - else - None - } else - None - } else - None - val projectArtifact0 = projectArtifact(module, version, versioningValue) - val listFilesUrl = urlFor(moduleVersionPath(module, version)) + "/" - - val changing0 = changing.getOrElse(isSnapshot(version)) - - val listFilesArtifact = - Artifact( - listFilesUrl, - Map.empty, - Map( - "metadata" -> projectArtifact0 - ), - Attributes("", ""), - changing = changing0, - authentication - ) - - val requiringDirListingProjectArtifact = projectArtifact0 - .copy( - extra = projectArtifact0.extra + ( - // In LocalUpdate and LocalUpdateChanging mode, makes getting the POM fail if the POM - // is in cache, but no info about the directory listing is (directory listing not in cache and no kept error - // for it). - "required" -> listFilesArtifact - ) - ) - for { - str <- fetch(requiringDirListingProjectArtifact) - rawListFilesPageOpt <- EitherT(F.map(fetch(artifactFor(listFilesUrl, changing0)).run) { - e => Right(e.right.toOption): Either[String, Option[String]] - }) + str <- fetch(projectArtifact0) proj0 <- EitherT(F.point[Either[String, Project]](parseRawPom(str))) - } yield { - - val foundPublications = - rawListFilesPageOpt match { - case Some(rawListFilesPage) => - - val files = WebPage.listFiles(listFilesUrl, rawListFilesPage) - - val prefix = s"${module.name}-${versioningValue.getOrElse(version)}" - - val packagingTpeMap = proj0.packagingOpt - .filter(_ != Pom.relocatedPackaging) - .map { packaging => - (MavenSource.typeDefaultClassifier(packaging), MavenSource.typeExtension(packaging)) -> packaging - } - .toMap - - files - .flatMap(isArtifact(_, prefix)) - .map { - case (classifier, ext) => - val tpe = packagingTpeMap.getOrElse( - (classifier, ext), - MavenSource.classifierExtensionDefaultTypeOpt(classifier, ext).getOrElse(ext) - ) - val config = MavenSource.typeDefaultConfig(tpe).getOrElse("compile") - config -> Publication( - module.name, - tpe, - ext, - classifier - ) - } - - case None => - // Publications can't be listed - MavenSource then handles that - Nil - } - - val proj = Pom.addOptionalDependenciesInConfig( - proj0.copy(configurations = defaultConfigurations), + } yield + Pom.addOptionalDependenciesInConfig( + proj0.copy( + actualVersionOpt = Some(version), + configurations = defaultConfigurations + ), Set("", "default"), "optional" ) - - proj.copy( - actualVersionOpt = Some(version), - publications = foundPublications - ) - } } def find[F[_]]( diff --git a/core/shared/src/main/scala/coursier/maven/MavenSource.scala b/core/shared/src/main/scala/coursier/maven/MavenSource.scala index 4ca7ae071..2fcccfa10 100644 --- a/core/shared/src/main/scala/coursier/maven/MavenSource.scala +++ b/core/shared/src/main/scala/coursier/maven/MavenSource.scala @@ -32,7 +32,11 @@ final case class MavenSource( val versioning = project .snapshotVersioning .flatMap(versioning => - mavenVersioning(versioning, publication.classifier, publication.`type`) + mavenVersioning( + versioning, + publication.classifier, + MavenSource.typeExtension(publication.`type`) + ) ) val path = dependency.module.organization.split('.').toSeq ++ Seq( @@ -52,6 +56,7 @@ final case class MavenSource( authentication = authentication ) .withDefaultChecksums + .withDefaultSignature if (publication.ext == "jar") artifact = artifact.withDefaultSignature @@ -133,142 +138,6 @@ final case class MavenSource( .map(artifactWithExtra) } - private val types = Map("sha1" -> "SHA-1", "sha256" -> "SHA-256", "md5" -> "MD5", "asc" -> "sig") - - private def artifactsKnownPublications( - dependency: Dependency, - project: Project, - overrideClassifiers: Option[Seq[String]] - ): Seq[Artifact] = { - - final case class EnrichedPublication( - publication: Publication, - extra: Map[String, EnrichedPublication] - ) { - def artifact: Artifact = - artifact(publication.`type`) - def artifact(versioningType: String): Artifact = { - - val versioningExtension = MavenSource.typeExtensions.getOrElse(versioningType, versioningType) - - val versioning = project - .snapshotVersioning - .flatMap(versioning => - mavenVersioning(versioning, publication.classifier, versioningExtension) - ) - - val path = dependency.module.organization.split('.').toSeq ++ Seq( - MavenRepository.dirModuleName(dependency.module, sbtAttrStub), - project.actualVersion, - s"${dependency.module.name}-${versioning getOrElse project.actualVersion}${Some(publication.classifier).filter(_.nonEmpty).map("-" + _).mkString}.${publication.ext}" - ) - - val changing0 = changing.getOrElse(isSnapshot(project.actualVersion)) - - val extra0 = extra.mapValues(_.artifact(versioningType)).iterator.toMap - - Artifact( - root + path.mkString("/"), - extra0.filterKeys(MavenSource.checksumTypes).mapValues(_.url).iterator.toMap, - extra0, - publication.attributes, - changing = changing0, - authentication = authentication - ) - } - } - - def groupedEnrichedPublications(publications: Seq[Publication]): Seq[EnrichedPublication] = { - - def helper(publications: Seq[Publication]): Seq[EnrichedPublication] = { - - var publications0 = publications - .map { pub => - pub.ext -> EnrichedPublication(pub, Map()) - } - .toMap - - val byLength = publications0.toVector.sortBy(-_._1.length) - - for { - (ext, _) <- byLength - idx = ext.lastIndexOf('.') - if idx >= 0 - subExt = ext.substring(idx + 1) - baseExt = ext.substring(0, idx) - tpe <- types.get(subExt) - mainPub <- publications0.get(baseExt) - } { - val pub = publications0(ext) - publications0 += baseExt -> mainPub.copy( - extra = mainPub.extra + (tpe -> pub) - ) - publications0 -= ext - } - - publications0.values.toVector - } - - publications - .groupBy(p => (p.name, p.classifier)) - .mapValues(helper) - .values - .toVector - .flatten - } - - val enrichedPublications = groupedEnrichedPublications(project.publications.map(_._2)) - - val metadataArtifactOpt = enrichedPublications.collectFirst { - case pub if pub.publication.name == dependency.module.name && - pub.publication.ext == "pom" && - pub.publication.classifier.isEmpty => - pub.artifact - } - - def withMetadataExtra(artifact: Artifact) = - metadataArtifactOpt.fold(artifact) { metadataArtifact => - artifact.copy( - extra = artifact.extra + ("metadata" -> metadataArtifact) - ) - } - - val res = overrideClassifiers match { - case Some(classifiers) => - val classifiersSet = classifiers.toSet - - enrichedPublications.collect { - case p if classifiersSet(p.publication.classifier) => - p.artifact - } - - case None => - - if (dependency.attributes.classifier.nonEmpty) - // FIXME We're ignoring dependency.attributes.`type` in this case - enrichedPublications.collect { - case p if p.publication.classifier == dependency.attributes.classifier => - p.artifact - } - else if (dependency.attributes.`type`.nonEmpty) - enrichedPublications.collect { - case p - if (p.publication.classifier.isEmpty || p.publication.classifier == MavenSource.typeDefaultClassifier(dependency.attributes.`type`)) && ( - p.publication.`type` == dependency.attributes.`type` || - (p.publication.ext == dependency.attributes.`type` && project.packagingOpt.toSeq.contains(p.publication.`type`)) // wow - ) => - p.artifact - } - else - enrichedPublications.collect { - case p if p.publication.classifier.isEmpty => - p.artifact - } - } - - res.map(withMetadataExtra) - } - private val dummyArtifact = Artifact("", Map(), Map(), Attributes("", ""), changing = false, None) def artifacts( @@ -285,52 +154,13 @@ final case class MavenSource( extra = a.extra.mapValues(makeOptional).iterator.toMap + (Artifact.optionalKey -> dummyArtifact) ) - def merge(a: Artifact, other: Artifact): Artifact = { - - assert(a.url == other.url, s"Merging artifacts with different URLs (${a.url}, ${other.url})") - - val extra = - a.extra.map { - case (k, v) => - k -> other.extra.get(k).fold(v)(merge(v, _)) - } ++ - other.extra - .filterKeys(k => !a.extra.contains(k) && k != Artifact.optionalKey) - - a.copy( - checksumUrls = other.checksumUrls ++ a.checksumUrls, - extra = extra - ) - } - - val defaultPublications = artifactsUnknownPublications(dependency, project, overrideClassifiers) + artifactsUnknownPublications(dependency, project, overrideClassifiers) .map(makeOptional) - - if (project.publications.isEmpty) - defaultPublications - else { - val listedPublications = artifactsKnownPublications(dependency, project, overrideClassifiers) - val listedUrls = listedPublications.map(_.url).toSet - val defaultPublicationsMap = defaultPublications - .map(a => a.url -> a) - .toMap - val listedPublications0 = listedPublications.map { a => - defaultPublicationsMap - .get(a.url) - .fold(a)(merge(a, _)) - } - val extraPublications = defaultPublications - .filter(a => !listedUrls(a.url)) - - listedPublications0 ++ extraPublications - } } } object MavenSource { - private val checksumTypes = Set("MD5", "SHA-1", "SHA-256") - val typeExtensions: Map[String, String] = Map( "eclipse-plugin" -> "jar", "maven-plugin" -> "jar", @@ -373,12 +203,4 @@ object MavenSource { def classifierExtensionDefaultTypeOpt(classifier: String, ext: String): Option[String] = classifierExtensionDefaultTypes.get((classifier, ext)) - val typeDefaultConfigs: Map[String, String] = Map( - "doc" -> "docs", - "src" -> "sources" - ) - - def typeDefaultConfig(`type`: String): Option[String] = - typeDefaultConfigs.get(`type`) - } diff --git a/tests/metadata b/tests/metadata index ed446075a..cdad75ba7 160000 --- a/tests/metadata +++ b/tests/metadata @@ -1 +1 @@ -Subproject commit ed446075ace7914af71a39ac7b00f17fa5d9190b +Subproject commit cdad75ba739422d2f110e0e70093e21c4cb0e6d6 From 25234fa9717ebf31f8d3edec9572dd4b74db09b1 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 19 Sep 2018 15:23:57 +0200 Subject: [PATCH 5/8] Run more tests against mirror repositories --- .../scala/coursier/test/CentralTests.scala | 137 +++++++----------- 1 file changed, 56 insertions(+), 81 deletions(-) diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 339847209..e6a3e1a5f 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -341,6 +341,8 @@ abstract class CentralTests extends TestSuite { 'versionInterval - { if (isActualCentral) + // that one involves version intervals, thus changing versions, so only + // running it against our cached Central stuff resolutionCheck( Module("org.webjars.bower", "malihu-custom-scrollbar-plugin"), "3.1.5" @@ -442,14 +444,11 @@ abstract class CentralTests extends TestSuite { attributes = Attributes(tpe) ) - * - { - if (isActualCentral) - ensureHasArtifactWithExtension( - module, - version, - tpe - ) - } + * - ensureHasArtifactWithExtension( + module, + version, + tpe + ) } 'bundle - { @@ -483,9 +482,6 @@ abstract class CentralTests extends TestSuite { 'classifier - { - // Adding extra repo so it's agnostic from nexus which only has the poms - val extraRepo = MavenRepository("https://repo1.maven.org/maven2") - 'vanilla - { async { val deps = Set( @@ -493,7 +489,7 @@ abstract class CentralTests extends TestSuite { Module("org.apache.avro", "avro"), "1.8.1" ) ) - val res = await(resolve(deps, extraRepos = Seq(extraRepo))) + val res = await(resolve(deps)) val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet assert(filenames.contains("avro-1.8.1.jar")) assert(!filenames.contains("avro-1.8.1-tests.jar")) @@ -507,7 +503,7 @@ abstract class CentralTests extends TestSuite { Module("org.apache.avro", "avro"), "1.8.1", attributes = Attributes("", "tests") ) ) - val res = await(resolve(deps, extraRepos = Seq(extraRepo))) + val res = await(resolve(deps)) val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet assert(!filenames.contains("avro-1.8.1.jar")) assert(filenames.contains("avro-1.8.1-tests.jar")) @@ -524,7 +520,7 @@ abstract class CentralTests extends TestSuite { Module("org.apache.avro", "avro"), "1.8.1", attributes = Attributes("", "tests") ) ) - val res = await(resolve(deps, extraRepos = Seq(extraRepo))) + val res = await(resolve(deps)) val filenames: Set[String] = res.artifacts(withOptional = true).map(_.url.split("/").last).toSet assert(filenames.contains("avro-1.8.1.jar")) assert(filenames.contains("avro-1.8.1-tests.jar")) @@ -670,14 +666,11 @@ abstract class CentralTests extends TestSuite { 'tarGz - { * - { - if (isActualCentral) - withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), transitive = true) { artifacts => - assert(artifacts.nonEmpty) - val urls = artifacts.map(_.url).toSet - assert(urls.contains(mainTarGzUrl)) - } - else - Future.successful(()) + withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), transitive = true) { artifacts => + assert(artifacts.nonEmpty) + val urls = artifacts.map(_.url).toSet + assert(urls.contains(mainTarGzUrl)) + } } * - { withArtifacts(mod, version, attributes = Attributes("tar.gz", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts => @@ -690,14 +683,11 @@ abstract class CentralTests extends TestSuite { 'zip - { * - { - if (isActualCentral) - withArtifacts(mod, version, attributes = Attributes("zip", "bin"), transitive = true) { artifacts => - assert(artifacts.nonEmpty) - val urls = artifacts.map(_.url).toSet - assert(urls.contains(mainZipUrl)) - } - else - Future.successful(()) + withArtifacts(mod, version, attributes = Attributes("zip", "bin"), transitive = true) { artifacts => + assert(artifacts.nonEmpty) + val urls = artifacts.map(_.url).toSet + assert(urls.contains(mainZipUrl)) + } } * - { withArtifacts(mod, version, attributes = Attributes("zip", "bin"), classifierOpt = Some("bin"), transitive = true) { artifacts => @@ -778,19 +768,14 @@ abstract class CentralTests extends TestSuite { assert(jarOpt.forall(hasSig)) } - * - { - if (isActualCentral) - withArtifacts(mod, ver, Attributes("pom")) { artifacts => + * - withArtifacts(mod, ver, Attributes("pom")) { artifacts => - val pomOpt = artifacts.find(_.`type` == "pom") + val pomOpt = artifacts.find(_.`type` == "pom") - assert(pomOpt.nonEmpty) - assert(pomOpt.forall(hasSha1)) - assert(pomOpt.forall(hasMd5)) - assert(pomOpt.forall(hasSig)) - } - else - Future.successful(()) + assert(pomOpt.nonEmpty) + assert(pomOpt.forall(hasSha1)) + assert(pomOpt.forall(hasMd5)) + assert(pomOpt.forall(hasSig)) } } @@ -839,21 +824,16 @@ abstract class CentralTests extends TestSuite { assert(mainArtifactOpt.forall(_.isOptional)) } - * - { - if (isActualCentral) - withArtifacts(Module("com.lihaoyi", "scalatags_2.12"), "0.6.2", Attributes("jar"), transitive = true) { artifacts => + * - withArtifacts(Module("com.lihaoyi", "scalatags_2.12"), "0.6.2", Attributes("jar"), transitive = true) { artifacts => - val urls = artifacts.map(_.url).toSet + val urls = artifacts.map(_.url).toSet - val expectedUrls = Seq( - "https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.0/scala-library-2.12.0.jar", - "https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3.jar", - "https://repo1.maven.org/maven2/com/lihaoyi/scalatags_2.12/0.6.2/scalatags_2.12-0.6.2.jar" - ) - assert(expectedUrls.forall(urls)) - } - else - Future.successful(()) + val expectedUrls = Seq( + s"$centralBase/org/scala-lang/scala-library/2.12.0/scala-library-2.12.0.jar", + s"$centralBase/com/lihaoyi/sourcecode_2.12/0.1.3/sourcecode_2.12-0.1.3.jar", + s"$centralBase/com/lihaoyi/scalatags_2.12/0.6.2/scalatags_2.12-0.6.2.jar" + ) + assert(expectedUrls.forall(urls)) } } @@ -902,34 +882,29 @@ abstract class CentralTests extends TestSuite { * - resolutionCheck(mod, ver, extraRepos = extraRepos) - * - { - if (isActualCentral) - withArtifacts(mod, ver, Attributes("jar"), extraRepos = extraRepos, transitive = true) { artifacts => - val urls = artifacts.map(_.url).toSet - val expectedUrls = Set( - "https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/com/cedarsoftware/json-io/4.9.9-TALEND/json-io-4.9.9-TALEND.jar", - "https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/org/talend/daikon/daikon/0.19.0-SNAPSHOT/daikon-0.19.0-20171201.100416-43.jar", - "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.5.3/jackson-annotations-2.5.3.jar", - "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.5.3/jackson-core-2.5.3.jar", - "https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.5.3/jackson-databind-2.5.3.jar", - "https://repo1.maven.org/maven2/com/thoughtworks/paranamer/paranamer/2.7/paranamer-2.7.jar", - "https://repo1.maven.org/maven2/commons-codec/commons-codec/1.6/commons-codec-1.6.jar", - "https://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar", - "https://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar", - "https://repo1.maven.org/maven2/org/apache/avro/avro/1.8.1/avro-1.8.1.jar", - "https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar", - "https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar", - "https://repo1.maven.org/maven2/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar", - "https://repo1.maven.org/maven2/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar", - "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar", - "https://repo1.maven.org/maven2/org/tukaani/xz/1.5/xz-1.5.jar", - "https://repo1.maven.org/maven2/org/xerial/snappy/snappy-java/1.1.1.3/snappy-java-1.1.1.3.jar" - ) + * - withArtifacts(mod, ver, Attributes("jar"), extraRepos = extraRepos, transitive = true) { artifacts => + val urls = artifacts.map(_.url).toSet + val expectedUrls = Set( + "https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/com/cedarsoftware/json-io/4.9.9-TALEND/json-io-4.9.9-TALEND.jar", + "https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/org/talend/daikon/daikon/0.19.0-SNAPSHOT/daikon-0.19.0-20171201.100416-43.jar", + s"$centralBase/com/fasterxml/jackson/core/jackson-annotations/2.5.3/jackson-annotations-2.5.3.jar", + s"$centralBase/com/fasterxml/jackson/core/jackson-core/2.5.3/jackson-core-2.5.3.jar", + s"$centralBase/com/fasterxml/jackson/core/jackson-databind/2.5.3/jackson-databind-2.5.3.jar", + s"$centralBase/com/thoughtworks/paranamer/paranamer/2.7/paranamer-2.7.jar", + s"$centralBase/commons-codec/commons-codec/1.6/commons-codec-1.6.jar", + s"$centralBase/javax/inject/javax.inject/1/javax.inject-1.jar", + s"$centralBase/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar", + s"$centralBase/org/apache/avro/avro/1.8.1/avro-1.8.1.jar", + s"$centralBase/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar", + s"$centralBase/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar", + s"$centralBase/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar", + s"$centralBase/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar", + s"$centralBase/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar", + s"$centralBase/org/tukaani/xz/1.5/xz-1.5.jar", + s"$centralBase/org/xerial/snappy/snappy-java/1.1.1.3/snappy-java-1.1.1.3.jar" + ) - assert(expectedUrls.forall(urls)) - } - else - Future.successful(()) + assert(expectedUrls.forall(urls)) } } } From fd6e56f2f8aa4f267c7b217f535c5064bb3504e4 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 19 Sep 2018 16:52:57 +0200 Subject: [PATCH 6/8] Silence slf4j in proxy tests --- build.sbt | 3 ++- project/Deps.scala | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 506a7fa97..0fe94d8ad 100644 --- a/build.sbt +++ b/build.sbt @@ -71,7 +71,8 @@ lazy val `proxy-tests` = project coursierPrefix, libs ++= Seq( Deps.dockerClient, - Deps.scalaAsync.value + Deps.scalaAsync.value, + Deps.slf4JNop ), utest, sharedTestResources diff --git a/project/Deps.scala b/project/Deps.scala index 1ffbc9914..f88639cc1 100644 --- a/project/Deps.scala +++ b/project/Deps.scala @@ -45,4 +45,6 @@ object Deps { def scalaNativeNir = "org.scala-native" %% "nir" % SharedVersions.scalaNative def scalaNativeTools = "org.scala-native" %% "tools" % SharedVersions.scalaNative def scalaNativeUtil = "org.scala-native" %% "util" % SharedVersions.scalaNative + + def slf4JNop = "org.slf4j" % "slf4j-nop" % "1.7.25" } From 32747ab1958352135048b5114b046b5d30040c06 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 20 Sep 2018 15:15:47 +0200 Subject: [PATCH 7/8] Tweaking --- .../main/scala/coursier/core/Repository.scala | 15 ++++++++--- .../scala/coursier/maven/MavenSource.scala | 25 ++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/shared/src/main/scala/coursier/core/Repository.scala b/core/shared/src/main/scala/coursier/core/Repository.scala index 955b35f7d..6afcfec04 100644 --- a/core/shared/src/main/scala/coursier/core/Repository.scala +++ b/core/shared/src/main/scala/coursier/core/Repository.scala @@ -1,8 +1,8 @@ package coursier.core import coursier.Fetch - import coursier.core.compatibility.encodeURIComponent +import coursier.maven.MavenSource import coursier.util.{EitherT, Monad} trait Repository extends Product with Serializable { @@ -24,19 +24,28 @@ object Repository { "SHA-1" -> (underlying.url + ".sha1"), "SHA-256" -> (underlying.url + ".sha256") )) - def withDefaultSignature: Artifact = + def withDefaultSignature: Artifact = { + + val underlyingExt = + if (underlying.attributes.`type`.isEmpty) + "jar" + else + // TODO move MavenSource.typeExtension elsewhere + MavenSource.typeExtension(underlying.attributes.`type`) + underlying.copy(extra = underlying.extra ++ Seq( "sig" -> Artifact( underlying.url + ".asc", Map.empty, Map.empty, - Attributes("asc", ""), + Attributes(s"$underlyingExt.asc", ""), changing = underlying.changing, authentication = underlying.authentication ) .withDefaultChecksums )) + } } } diff --git a/core/shared/src/main/scala/coursier/maven/MavenSource.scala b/core/shared/src/main/scala/coursier/maven/MavenSource.scala index 2fcccfa10..1f6d9c53c 100644 --- a/core/shared/src/main/scala/coursier/maven/MavenSource.scala +++ b/core/shared/src/main/scala/coursier/maven/MavenSource.scala @@ -46,22 +46,17 @@ final case class MavenSource( ) val changing0 = changing.getOrElse(isSnapshot(project.actualVersion)) - var artifact = - Artifact( - root + path.mkString("/"), - Map.empty, - Map.empty, - publication.attributes, - changing = changing0, - authentication = authentication - ) - .withDefaultChecksums - .withDefaultSignature - if (publication.ext == "jar") - artifact = artifact.withDefaultSignature - - artifact + Artifact( + root + path.mkString("/"), + Map.empty, + Map.empty, + publication.attributes, + changing = changing0, + authentication = authentication + ) + .withDefaultChecksums + .withDefaultSignature } val metadataArtifact = artifactOf(Publication(dependency.module.name, "pom", "pom", "")) From b0a7c92e27a2ead4c78d9c3f563c313bedbcda14 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 20 Sep 2018 15:17:23 +0200 Subject: [PATCH 8/8] Clean-up --- sbt-pgp-coursier/src/sbt-test/sbt-pgp-coursier/simple/build.sbt | 1 - 1 file changed, 1 deletion(-) diff --git a/sbt-pgp-coursier/src/sbt-test/sbt-pgp-coursier/simple/build.sbt b/sbt-pgp-coursier/src/sbt-test/sbt-pgp-coursier/simple/build.sbt index 58f1430f7..39544745e 100644 --- a/sbt-pgp-coursier/src/sbt-test/sbt-pgp-coursier/simple/build.sbt +++ b/sbt-pgp-coursier/src/sbt-test/sbt-pgp-coursier/simple/build.sbt @@ -16,7 +16,6 @@ check := { sys.error("No configuration report found for configuration 'compile'") } val moduleReports = configReport.modules - val artifacts = moduleReports.flatMap(_.artifacts.map(_._1)) val signatures = moduleReports .flatMap(_.artifacts) .filter(_._1.extension == "jar.asc")