From 8d27ab7150ad1f8ba72ce6d4b5b9850be8d486b8 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 18 Jun 2015 00:25:17 +0200 Subject: [PATCH] Better properties substitution --- .../main/scala/coursier/core/Resolver.scala | 27 ++++++++++--------- .../scala/coursier/test/CentralTests.scala | 26 ++++++++++++++++-- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/core/src/main/scala/coursier/core/Resolver.scala b/core/src/main/scala/coursier/core/Resolver.scala index 428e3d6c1..651dfa89b 100644 --- a/core/src/main/scala/coursier/core/Resolver.scala +++ b/core/src/main/scala/coursier/core/Resolver.scala @@ -350,21 +350,22 @@ object Resolver { // Here, we're substituting properties also in dependencies that come from parents // or dependency management. This may not be the right thing to do. + val properties = mergeProperties( + project.properties, + Map( + "project.groupId" -> project.module.organization, + "project.artifactId" -> project.module.name, + "project.version" -> project.module.version + ) + ) + val deps = withExclusions( - withProperties( - depsWithDependencyManagement( - project.dependencies, - project.dependencyManagement - ), - mergeProperties( - project.properties, - Map( - "project.groupId" -> project.module.organization, - "project.artifactId" -> project.module.name, - "project.version" -> project.module.version - ) - ) + depsWithDependencyManagement( + // important: properties have to be applied to both, so that dep mgmt can be matched properly + // See the added test with org.ow2.asm:asm-commons:5.0.2 + withProperties(project.dependencies, properties), + withProperties(project.dependencyManagement, properties) ), from.exclusions ) diff --git a/core/src/test/scala/coursier/test/CentralTests.scala b/core/src/test/scala/coursier/test/CentralTests.scala index ec8d65721..6699d2f0d 100644 --- a/core/src/test/scala/coursier/test/CentralTests.scala +++ b/core/src/test/scala/coursier/test/CentralTests.scala @@ -21,8 +21,7 @@ object CentralTests extends TestSuite { .runF) val res = res0.copy( - projectsCache = Map.empty, errors = Map.empty, // No validating these here - dependencies = res0.dependencies.filter(dep => dep.scope == Scope.Compile && !dep.optional) + projectsCache = Map.empty, errors = Map.empty // No validating these here ) val expected = Resolution( @@ -34,6 +33,29 @@ object CentralTests extends TestSuite { ) ) + assert(res == expected) + } + } + 'asm{ + async { + val dep = Dependency(Module("org.ow2.asm", "asm-commons", "5.0.2")) + val res0 = + await(resolve(Set(dep), fetchFrom(repositories)) + .runF) + + val res = res0.copy( + projectsCache = Map.empty, errors = Map.empty // No validating these here + ) + + val expected = Resolution( + rootDependencies = Set(dep.withCompileScope), + dependencies = Set( + dep.withCompileScope, + Dependency(Module("org.ow2.asm", "asm-tree", "5.0.2")).withCompileScope, + Dependency(Module("org.ow2.asm", "asm", "5.0.2")).withCompileScope + ) + ) + assert(res == expected) } }