From 14bc756b5bb4335af47e32fe011baa186712d702 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 30 Jan 2018 17:26:07 +0100 Subject: [PATCH] Allow to deactivate Maven profiles from the CLI And add extra tests for profile deactivation --- .../main/scala-2.11/coursier/cli/Helper.scala | 2 +- .../coursier/cli/CliIntegrationTest.scala | 18 +++ tests/metadata | 2 +- .../org.apache.spark/spark-core_2.10/2.1.1 | 136 ++++++++++++++++++ .../scala/coursier/test/CentralTests.scala | 10 +- 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 tests/shared/src/test/resources/resolutions/org.apache.spark/spark-core_2.10/2.1.1 diff --git a/cli/src/main/scala-2.11/coursier/cli/Helper.scala b/cli/src/main/scala-2.11/coursier/cli/Helper.scala index 1fb9afcd1..e35a826bf 100644 --- a/cli/src/main/scala-2.11/coursier/cli/Helper.scala +++ b/cli/src/main/scala-2.11/coursier/cli/Helper.scala @@ -319,7 +319,7 @@ class Helper( filter = Some(dep => keepOptional || !dep.optional), userActivations = if (userEnabledProfiles.isEmpty) None - else Some(userEnabledProfiles.iterator.map(_ -> true).toMap), + else Some(userEnabledProfiles.iterator.map(p => if (p.startsWith("!")) p.drop(1) -> false else p -> true).toMap), mapDependencies = if (typelevel) Some(Typelevel.swap(_)) else None ) diff --git a/cli/src/test/scala-2.11/coursier/cli/CliIntegrationTest.scala b/cli/src/test/scala-2.11/coursier/cli/CliIntegrationTest.scala index 7c017fb22..c751f1904 100644 --- a/cli/src/test/scala-2.11/coursier/cli/CliIntegrationTest.scala +++ b/cli/src/test/scala-2.11/coursier/cli/CliIntegrationTest.scala @@ -396,4 +396,22 @@ class CliIntegrationTest extends FlatSpec { } } } + + "profiles" should "be manually (de)activated" in withFile() { + (jsonFile, _) => + val commonOpt = CommonOptions( + jsonOutputFile = jsonFile.getPath, + profile = List("scala-2.10", "!scala-2.11") + ) + val fetchOpt = FetchOptions(common = commonOpt) + + val fetch = new Fetch(fetchOpt) with TestOnlyExtraArgsApp + fetch.setRemainingArgs(Seq("org.apache.spark:spark-core_2.10:2.2.1"), Seq()) + fetch.apply() + + val node = getReportFromJson(jsonFile) + + assert(node.dependencies.exists(_.coord.startsWith("org.scala-lang:scala-library:2.10."))) + assert(!node.dependencies.exists(_.coord.startsWith("org.scala-lang:scala-library:2.11."))) + } } diff --git a/tests/metadata b/tests/metadata index bca2ebce3..3ff24a70a 160000 --- a/tests/metadata +++ b/tests/metadata @@ -1 +1 @@ -Subproject commit bca2ebce3c28db5b6066f37d22007bf6ae048c2b +Subproject commit 3ff24a70a65a09243110905735cc67c87588ce4d diff --git a/tests/shared/src/test/resources/resolutions/org.apache.spark/spark-core_2.10/2.1.1 b/tests/shared/src/test/resources/resolutions/org.apache.spark/spark-core_2.10/2.1.1 new file mode 100644 index 000000000..59ac2fe98 --- /dev/null +++ b/tests/shared/src/test/resources/resolutions/org.apache.spark/spark-core_2.10/2.1.1 @@ -0,0 +1,136 @@ +aopalliance:aopalliance:1.0:compile +com.clearspring.analytics:stream:2.7.0:compile +com.esotericsoftware:kryo-shaded:3.0.3:compile +com.esotericsoftware:minlog:1.3.0:compile +com.fasterxml.jackson.core:jackson-annotations:2.6.5:compile +com.fasterxml.jackson.core:jackson-core:2.6.5:compile +com.fasterxml.jackson.core:jackson-databind:2.6.5:compile +com.fasterxml.jackson.module:jackson-module-paranamer:2.6.5:compile +com.fasterxml.jackson.module:jackson-module-scala_2.10:2.6.5:compile +com.google.code.findbugs:jsr305:1.3.9:compile +com.google.code.gson:gson:2.2.4:compile +com.google.guava:guava:16.0.1:compile +com.google.inject:guice:3.0:compile +com.google.protobuf:protobuf-java:2.5.0:compile +com.jamesmurty.utils:java-xmlbuilder:1.0:compile +com.ning:compress-lzf:1.0.3:compile +com.thoughtworks.paranamer:paranamer:2.6:compile +com.twitter:chill-java:0.8.0:compile +com.twitter:chill_2.10:0.8.0:compile +commons-beanutils:commons-beanutils:1.7.0:compile +commons-beanutils:commons-beanutils-core:1.8.0:compile +commons-cli:commons-cli:1.2:compile +commons-codec:commons-codec:1.8:compile +commons-collections:commons-collections:3.2.2:compile +commons-configuration:commons-configuration:1.6:compile +commons-digester:commons-digester:1.8:compile +commons-httpclient:commons-httpclient:3.1:compile +commons-io:commons-io:2.4:compile +commons-lang:commons-lang:2.6:compile +commons-net:commons-net:3.1:compile +io.dropwizard.metrics:metrics-core:3.1.2:compile +io.dropwizard.metrics:metrics-graphite:3.1.2:compile +io.dropwizard.metrics:metrics-json:3.1.2:compile +io.dropwizard.metrics:metrics-jvm:3.1.2:compile +io.netty:netty:3.8.0.Final:compile +io.netty:netty-all:4.0.42.Final:compile +javax.activation:activation:1.1.1:compile +javax.annotation:javax.annotation-api:1.2:compile +javax.inject:javax.inject:1:compile +javax.mail:mail:1.4.7:compile +javax.servlet:javax.servlet-api:3.1.0:compile +javax.validation:validation-api:1.1.0.Final:compile +javax.ws.rs:javax.ws.rs-api:2.0.1:compile +javax.xml.bind:jaxb-api:2.2.2:compile +javax.xml.stream:stax-api:1.0-2:compile +jline:jline:0.9.94:compile +log4j:log4j:1.2.17:compile +mx4j:mx4j:3.0.2:compile +net.iharder:base64:2.3.8:compile +net.java.dev.jets3t:jets3t:0.9.3:compile +net.jpountz.lz4:lz4:1.3.0:compile +net.razorvine:pyrolite:4.13:compile +net.sf.py4j:py4j:0.10.4:compile +org.apache.avro:avro:1.7.7:compile +org.apache.avro:avro-ipc:1.7.7:compile +org.apache.avro:avro-mapred:1.7.7:compile +org.apache.commons:commons-compress:1.4.1:compile +org.apache.commons:commons-crypto:1.0.0:compile +org.apache.commons:commons-lang3:3.5:compile +org.apache.commons:commons-math3:3.4.1:compile +org.apache.curator:curator-client:2.6.0:compile +org.apache.curator:curator-framework:2.6.0:compile +org.apache.curator:curator-recipes:2.6.0:compile +org.apache.directory.api:api-asn1-api:1.0.0-M20:compile +org.apache.directory.api:api-util:1.0.0-M20:compile +org.apache.directory.server:apacheds-i18n:2.0.0-M15:compile +org.apache.directory.server:apacheds-kerberos-codec:2.0.0-M15:compile +org.apache.hadoop:hadoop-annotations:2.6.4:compile +org.apache.hadoop:hadoop-auth:2.6.4:compile +org.apache.hadoop:hadoop-client:2.6.4:compile +org.apache.hadoop:hadoop-common:2.6.4:compile +org.apache.hadoop:hadoop-hdfs:2.6.4:compile +org.apache.hadoop:hadoop-mapreduce-client-app:2.6.4:compile +org.apache.hadoop:hadoop-mapreduce-client-common:2.6.4:compile +org.apache.hadoop:hadoop-mapreduce-client-core:2.6.4:compile +org.apache.hadoop:hadoop-mapreduce-client-jobclient:2.6.4:compile +org.apache.hadoop:hadoop-mapreduce-client-shuffle:2.6.4:compile +org.apache.hadoop:hadoop-yarn-api:2.6.4:compile +org.apache.hadoop:hadoop-yarn-client:2.6.4:compile +org.apache.hadoop:hadoop-yarn-common:2.6.4:compile +org.apache.hadoop:hadoop-yarn-server-common:2.6.4:compile +org.apache.hadoop:hadoop-yarn-server-nodemanager:2.6.4:compile +org.apache.httpcomponents:httpclient:4.3.6:compile +org.apache.httpcomponents:httpcore:4.3.3:compile +org.apache.ivy:ivy:2.4.0:compile +org.apache.spark:spark-core_2.10:2.1.1:compile +org.apache.spark:spark-launcher_2.10:2.1.1:compile +org.apache.spark:spark-network-common_2.10:2.1.1:compile +org.apache.spark:spark-network-shuffle_2.10:2.1.1:compile +org.apache.spark:spark-tags_2.10:2.1.1:compile +org.apache.spark:spark-unsafe_2.10:2.1.1:compile +org.apache.xbean:xbean-asm5-shaded:4.4:compile +org.apache.zookeeper:zookeeper:3.4.6:compile +org.bouncycastle:bcprov-jdk15on:1.51:compile +org.codehaus.jackson:jackson-core-asl:1.9.13:compile +org.codehaus.jackson:jackson-jaxrs:1.9.13:compile +org.codehaus.jackson:jackson-mapper-asl:1.9.13:compile +org.codehaus.jackson:jackson-xc:1.9.13:compile +org.codehaus.jettison:jettison:1.1:compile +org.fusesource.leveldbjni:leveldbjni-all:1.8:compile +org.glassfish.hk2:hk2-api:2.4.0-b34:compile +org.glassfish.hk2:hk2-locator:2.4.0-b34:compile +org.glassfish.hk2:hk2-utils:2.4.0-b34:compile +org.glassfish.hk2:osgi-resource-locator:1.0.1:compile +org.glassfish.hk2.external:aopalliance-repackaged:2.4.0-b34:compile +org.glassfish.hk2.external:javax.inject:2.4.0-b34:compile +org.glassfish.jersey.bundles.repackaged:jersey-guava:2.22.2:compile +org.glassfish.jersey.containers:jersey-container-servlet:2.22.2:compile +org.glassfish.jersey.containers:jersey-container-servlet-core:2.22.2:compile +org.glassfish.jersey.core:jersey-client:2.22.2:compile +org.glassfish.jersey.core:jersey-common:2.22.2:compile +org.glassfish.jersey.core:jersey-server:2.22.2:compile +org.glassfish.jersey.media:jersey-media-jaxb:2.22.2:compile +org.htrace:htrace-core:3.0.4:compile +org.javassist:javassist:3.18.1-GA:compile +org.json4s:json4s-ast_2.10:3.2.11:compile +org.json4s:json4s-core_2.10:3.2.11:compile +org.json4s:json4s-jackson_2.10:3.2.11:compile +org.mortbay.jetty:jetty-util:6.1.26:compile +org.objenesis:objenesis:2.1:compile +org.roaringbitmap:RoaringBitmap:0.5.11:compile +org.scala-lang:scala-compiler:2.10.0:compile +org.scala-lang:scala-library:2.10.6:compile +org.scala-lang:scala-reflect:2.10.6:compile +org.scala-lang:scalap:2.10.0:compile +org.slf4j:jcl-over-slf4j:1.7.16:compile +org.slf4j:jul-to-slf4j:1.7.16:compile +org.slf4j:slf4j-api:1.7.16:compile +org.slf4j:slf4j-log4j12:1.7.16:compile +org.spark-project.spark:unused:1.0.0:compile +org.tukaani:xz:1.0:compile +org.xerial.snappy:snappy-java:1.1.2.6:compile +oro:oro:2.0.8:compile +xerces:xercesImpl:2.9.1:compile +xml-apis:xml-apis:1.3.04:compile +xmlenc:xmlenc:0.52:compile \ No newline at end of file diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 266bbf0e8..3e9b2c6ed 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -39,7 +39,7 @@ abstract class CentralTests extends TestSuite { Resolution( deps, filter = filter, - userActivations = profiles.map(_.iterator.map(_ -> true).toMap) + userActivations = profiles.map(_.iterator.map(p => if (p.startsWith("!")) p.drop(1) -> false else p -> true).toMap) ) .process .run(fetch0) @@ -262,11 +262,17 @@ abstract class CentralTests extends TestSuite { } 'spark - { - resolutionCheck( + * - resolutionCheck( Module("org.apache.spark", "spark-core_2.11"), "1.3.1", profiles = Some(Set("hadoop-2.2")) ) + + 'scala210 - resolutionCheck( + Module("org.apache.spark", "spark-core_2.10"), + "2.1.1", + profiles = Some(Set("hadoop-2.6", "scala-2.10", "!scala-2.11")) + ) } 'argonautShapeless - {