From ef21746c812466140786f465506dd227ddf14c6c Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 11 Apr 2017 14:38:20 +0200 Subject: [PATCH] Be fine with extensions / types with dots Like tar.gz --- .../coursier/maven/MavenRepository.scala | 2 +- .../test/scala/coursier/test/IvyTests.scala | 6 ++- .../org.apache.maven/apache-maven/3.3.9 | 44 +++++++++++++++++ .../scala/coursier/test/CentralTests.scala | 48 ++++++++++++++++--- 4 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 tests/shared/src/test/resources/resolutions/org.apache.maven/apache-maven/3.3.9 diff --git a/core/shared/src/main/scala/coursier/maven/MavenRepository.scala b/core/shared/src/main/scala/coursier/maven/MavenRepository.scala index d92d0b45a..680d69a36 100644 --- a/core/shared/src/main/scala/coursier/maven/MavenRepository.scala +++ b/core/shared/src/main/scala/coursier/maven/MavenRepository.scala @@ -266,7 +266,7 @@ final case class MavenRepository( // TODO There should be a regex for that... if (fileName.startsWith(prefix)) { val end = fileName.stripPrefix(prefix) - val idx = end.lastIndexOf('.') + val idx = end.indexOf('.') if (idx >= 0) { val ext = end.drop(idx + 1) val rem = end.take(idx) diff --git a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala index be7e3c2a1..e6c5e3192 100644 --- a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala +++ b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala @@ -73,7 +73,8 @@ object IvyTests extends TestSuite { * - CentralTests.withArtifacts( dep = dep, artifactType = "jar", - extraRepo = Some(repo) + extraRepo = Some(repo), + classifierOpt = None ) { case Seq(artifact) => assert(artifact.url == mainJarUrl) @@ -84,7 +85,8 @@ object IvyTests extends TestSuite { * - CentralTests.withArtifacts( dep = dep.copy(configuration = "test"), artifactType = "jar", - extraRepo = Some(repo) + extraRepo = Some(repo), + classifierOpt = None ) { case Seq(artifact1, artifact2) => val urls = Set( diff --git a/tests/shared/src/test/resources/resolutions/org.apache.maven/apache-maven/3.3.9 b/tests/shared/src/test/resources/resolutions/org.apache.maven/apache-maven/3.3.9 new file mode 100644 index 000000000..f6172836b --- /dev/null +++ b/tests/shared/src/test/resources/resolutions/org.apache.maven/apache-maven/3.3.9 @@ -0,0 +1,44 @@ +aopalliance:aopalliance:1.0:compile +com.google.guava:guava:18.0:compile +com.google.inject:guice:4.0:compile +commons-cli:commons-cli:1.2:compile +commons-io:commons-io:2.2:compile +commons-lang:commons-lang:2.6:compile +commons-logging:commons-logging:1.1.3:compile +javax.annotation:jsr250-api:1.0:compile +javax.enterprise:cdi-api:1.0:compile +javax.inject:javax.inject:1:compile +org.apache.commons:commons-lang3:3.4:compile +org.apache.maven:apache-maven:3.3.9:compile +org.apache.maven:maven-aether-provider:3.3.9:compile +org.apache.maven:maven-artifact:3.3.9:compile +org.apache.maven:maven-builder-support:3.3.9:compile +org.apache.maven:maven-compat:3.3.9:compile +org.apache.maven:maven-core:3.3.9:compile +org.apache.maven:maven-embedder:3.3.9:compile +org.apache.maven:maven-model:3.3.9:compile +org.apache.maven:maven-model-builder:3.3.9:compile +org.apache.maven:maven-plugin-api:3.3.9:compile +org.apache.maven:maven-repository-metadata:3.3.9:compile +org.apache.maven:maven-settings:3.3.9:compile +org.apache.maven:maven-settings-builder:3.3.9:compile +org.apache.maven.wagon:wagon-file:2.10:compile +org.apache.maven.wagon:wagon-http:2.10:compile +org.apache.maven.wagon:wagon-http-shared:2.10:compile +org.apache.maven.wagon:wagon-provider-api:2.10:compile +org.codehaus.plexus:plexus-classworlds:2.5.2:compile +org.codehaus.plexus:plexus-component-annotations:1.6:compile +org.codehaus.plexus:plexus-interpolation:1.21:compile +org.codehaus.plexus:plexus-utils:3.0.22:compile +org.eclipse.aether:aether-api:1.0.2.v20150114:compile +org.eclipse.aether:aether-connector-basic:1.0.2.v20150114:compile +org.eclipse.aether:aether-impl:1.0.2.v20150114:compile +org.eclipse.aether:aether-spi:1.0.2.v20150114:compile +org.eclipse.aether:aether-transport-wagon:1.0.2.v20150114:compile +org.eclipse.aether:aether-util:1.0.2.v20150114:compile +org.eclipse.sisu:org.eclipse.sisu.inject:0.3.2:compile +org.eclipse.sisu:org.eclipse.sisu.plexus:0.3.2:compile +org.jsoup:jsoup:1.7.2:compile +org.slf4j:slf4j-api:1.7.5:compile +org.sonatype.plexus:plexus-cipher:1.7:compile +org.sonatype.plexus:plexus-sec-dispatcher:1.3:compile diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 382395fdc..74edbdd48 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -121,27 +121,31 @@ object CentralTests extends TestSuite { version: String, artifactType: String, attributes: Attributes = Attributes(), - extraRepo: Option[Repository] = None + extraRepo: Option[Repository] = None, + classifierOpt: Option[String] = None, + transitive: Boolean = false )( f: Seq[Artifact] => T ): Future[T] = { - val dep = Dependency(module, version, transitive = false, attributes = attributes) - withArtifacts(dep, artifactType, extraRepo)(f) + val dep = Dependency(module, version, transitive = transitive, attributes = attributes) + withArtifacts(dep, artifactType, extraRepo, classifierOpt)(f) } def withArtifacts[T]( dep: Dependency, artifactType: String, - extraRepo: Option[Repository] + extraRepo: Option[Repository], + classifierOpt: Option[String] )( f: Seq[Artifact] => T ): Future[T] = - withArtifacts(Set(dep), artifactType, extraRepo)(f) + withArtifacts(Set(dep), artifactType, extraRepo, classifierOpt)(f) def withArtifacts[T]( deps: Set[Dependency], artifactType: String, - extraRepo: Option[Repository] + extraRepo: Option[Repository], + classifierOpt: Option[String] )( f: Seq[Artifact] => T ): Future[T] = async { @@ -151,7 +155,7 @@ object CentralTests extends TestSuite { assert(res.conflicts.isEmpty) assert(res.isDone) - val artifacts = res.dependencyArtifacts.map(_._2).filter { a => + val artifacts = classifierOpt.fold(res.dependencyArtifacts)(c => res.dependencyClassifiersArtifacts(Seq(c))).map(_._2).filter { a => a.`type` == artifactType } @@ -372,6 +376,7 @@ object CentralTests extends TestSuite { intransitiveCompiler("optional") ), "jar", + None, None ) { case Seq() => @@ -545,6 +550,35 @@ object CentralTests extends TestSuite { "0.8.0" ) } + + 'tarGzZipArtifacts - { + val mod = Module("org.apache.maven", "apache-maven") + val version = "3.3.9" + + * - resolutionCheck(mod, version) + + val expectedTarGzArtifactUrls = Set( + "https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.tar.gz", + "https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-bin.tar.gz" + ) + + val expectedZipArtifactUrls = Set( + "https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip", + "https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-bin.zip" + ) + + * - withArtifacts(mod, version, "tar.gz", classifierOpt = Some("bin"), transitive = true) { artifacts => + assert(artifacts.length == 2) + val urls = artifacts.map(_.url).toSet + assert(urls == expectedTarGzArtifactUrls) + } + + * - withArtifacts(mod, version, "zip", classifierOpt = Some("bin"), transitive = true) { artifacts => + assert(artifacts.length == 2) + val urls = artifacts.map(_.url).toSet + assert(urls == expectedZipArtifactUrls) + } + } } }