From 6d08ced648ba996c1416b5eb903e688e885c8498 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 1 Jun 2017 09:56:23 +0200 Subject: [PATCH 1/4] Switch to sbt 1.0.0-M6 --- project/Settings.scala | 2 +- .../src/main/scala/coursier/Tasks.scala | 111 ++++++++++-------- 2 files changed, 63 insertions(+), 50 deletions(-) diff --git a/project/Settings.scala b/project/Settings.scala index 3dbf960fd..d35bae7bc 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -199,7 +199,7 @@ object Settings { sbtVersion := { scalaBinaryVersion.value match { case "2.10" => "0.13.8" - case "2.12" => "1.0.0-M5" + case "2.12" => "1.0.0-M6" case _ => sbtVersion.value } }, diff --git a/sbt-coursier/src/main/scala/coursier/Tasks.scala b/sbt-coursier/src/main/scala/coursier/Tasks.scala index 56fd43808..5df60ba81 100644 --- a/sbt-coursier/src/main/scala/coursier/Tasks.scala +++ b/sbt-coursier/src/main/scala/coursier/Tasks.scala @@ -499,15 +499,20 @@ object Tasks { // Downloads are already parallel, no need to parallelize further anyway synchronized { - lazy val cm = coursierSbtClassifiersModule.value + val cm = coursierSbtClassifiersModule.value - lazy val projectName = thisProjectRef.value.project + val projectName = thisProjectRef.value.project + val baseConfigGraphs = coursierConfigGraphs.value + + val sv = scalaVersion.value + val sbv = scalaBinaryVersion.value + + val proj = coursierProject.value + val publications = coursierPublications.value + val fallbackDeps = coursierFallbackDependencies.value val (currentProject, fallbackDependencies, configGraphs) = if (sbtClassifiers) { - val sv = scalaVersion.value - val sbv = scalaBinaryVersion.value - val proj = FromSbt.project( cm.id, cm.modules, @@ -523,12 +528,8 @@ object Tasks { ) (proj, fallbackDeps, Vector(cm.configurations.map(_.name).toSet)) - } else { - val proj = coursierProject.value - val publications = coursierPublications.value - val fallbackDeps = coursierFallbackDependencies.value - (proj.copy(publications = publications), fallbackDeps, coursierConfigGraphs.value) - } + } else + (proj.copy(publications = publications), fallbackDeps, baseConfigGraphs) val interProjectDependencies = coursierInterProjectDependencies.value @@ -543,18 +544,19 @@ object Tasks { // are these always defined? (e.g. for Java only projects?) val so = scalaOrganization.value - val sv = scalaVersion.value - val sbv = scalaBinaryVersion.value val userForceVersions = dependencyOverrides.value.map( FromSbt.moduleVersion(_, sv, sbv) ).toMap + val sbtResolvers = coursierSbtResolvers.value + val defaultResolvers = coursierRecursiveResolvers.value + val resolvers = if (sbtClassifiers) - coursierSbtResolvers.value + sbtResolvers else - coursierRecursiveResolvers.value.distinct + defaultResolvers.distinct val parentProjectCache: ProjectCache = coursierParentProjectCache.value .get(resolvers) @@ -600,11 +602,11 @@ object Tasks { ) ++ sys.props val useSbtCredentials = coursierUseSbtCredentials.value + val sbtCreds = sbt.Keys.credentials.value val authenticationByHost = if (useSbtCredentials) - sbt.Keys.credentials - .value + sbtCreds .flatMap { case dc: sbt.DirectCredentials => List(dc) case fc: sbt.FileCredentials => @@ -861,11 +863,16 @@ object Tasks { val verbosityLevel = coursierVerbosity.value + val classifiersRes = coursierSbtClassifiersResolution.value + val mainRes = coursierResolutions.value + val res = if (withClassifiers && sbtClassifiers) - Seq(coursierSbtClassifiersResolution.value) + Seq(classifiersRes) else - coursierResolutions.value.values.toVector + mainRes.values.toVector + + val trClassifiers = transitiveClassifiers.value val classifiers = if (withClassifiers) @@ -873,7 +880,7 @@ object Tasks { if (sbtClassifiers) cm.classifiers else - transitiveClassifiers.value + trClassifiers } else None @@ -1047,13 +1054,16 @@ object Tasks { internalSbtScalaProvider.jars() ) - lazy val cm = coursierSbtClassifiersModule.value + val cm = coursierSbtClassifiersModule.value + + val sv = scalaVersion.value + val sbv = scalaBinaryVersion.value + + val proj = coursierProject.value + val publications = coursierPublications.value val currentProject = - if (sbtClassifiers) { - val sv = scalaVersion.value - val sbv = scalaBinaryVersion.value - + if (sbtClassifiers) FromSbt.project( cm.id, cm.modules, @@ -1061,22 +1071,21 @@ object Tasks { sv, sbv ) - } else { - val proj = coursierProject.value - val publications = coursierPublications.value + else proj.copy(publications = publications) - } val log = streams.value.log val verbosityLevel = coursierVerbosity.value + val classifiersRes = coursierSbtClassifiersResolution.value + val mainRes = coursierResolutions.value + val res = - if (withClassifiers && sbtClassifiers) { - val r = coursierSbtClassifiersResolution.value - Map(cm.configurations.map(c => c.name).toSet -> r) - } else - coursierResolutions.value + if (withClassifiers && sbtClassifiers) + Map(cm.configurations.map(c => c.name).toSet -> classifiersRes) + else + mainRes val configResolutions = res.flatMap { case (configs, r) => @@ -1117,13 +1126,15 @@ object Tasks { log.info(repr.split('\n').map(" " + _).mkString("\n")) } + val trClassifiers = transitiveClassifiers.value + val classifiers = if (withClassifiers) Some { if (sbtClassifiers) cm.classifiers else - transitiveClassifiers.value + trClassifiers } else None @@ -1203,12 +1214,15 @@ object Tasks { lazy val projectName = thisProjectRef.value.project - val currentProject = - if (sbtClassifiers) { - val cm = coursierSbtClassifiersModule.value - val sv = scalaVersion.value - val sbv = scalaBinaryVersion.value + val cm = coursierSbtClassifiersModule.value + val sv = scalaVersion.value + val sbv = scalaBinaryVersion.value + val proj = coursierProject.value + val publications = coursierPublications.value + + val currentProject = + if (sbtClassifiers) FromSbt.project( cm.id, cm.modules, @@ -1216,18 +1230,17 @@ object Tasks { sv, sbv ) - } else { - val proj = coursierProject.value - val publications = coursierPublications.value + else proj.copy(publications = publications) - } + + val classifiersRes = coursierSbtClassifiersResolution.value + val mainRes = coursierResolutions.value val resolutions = - if (sbtClassifiers) { - val r = coursierSbtClassifiersResolution.value - Map(currentProject.configurations.keySet -> r) - } else - coursierResolutions.value + if (sbtClassifiers) + Map(currentProject.configurations.keySet -> classifiersRes) + else + mainRes val config = configuration.value.name val configs = coursierConfigurations.value From b964497f1c105cc39e6984725d5dac3e344b5ffd Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 7 Jun 2017 14:41:14 +0200 Subject: [PATCH 2/4] Add workaround for sbt 1.0.0-M6 --- project/Settings.scala | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/project/Settings.scala b/project/Settings.scala index d35bae7bc..9a7b09dee 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -178,11 +178,70 @@ object Settings { ) } + lazy val scripted100M6Workaround = { + + // see https://github.com/sbt/sbt/issues/3245#issuecomment-306045952 + + ScriptedPlugin.scripted := Def.inputTask { + + val args = ScriptedPlugin + .asInstanceOf[{ + def scriptedParser(f: File): complete.Parser[Seq[String]] + }] + .scriptedParser(sbtTestDirectory.value) + .parsed + + val prereq: Unit = scriptedDependencies.value + val scriptedTests = ScriptedPlugin.scriptedTests.value + + try { + if(sbtVersion.in(pluginCrossBuild).value == "1.0.0-M6") + scriptedTests.asInstanceOf[{ + def run( + x1: File, + x2: Boolean, + x3: Array[String], + x4: File, + x5: Array[String], + x6: java.util.List[File] + ): Unit + }].run( + sbtTestDirectory.value, + scriptedBufferLog.value, + args.toArray, + sbtLauncher.value, + scriptedLaunchOpts.value.toArray, + new java.util.ArrayList() + ) + else + scriptedTests.asInstanceOf[{ + def run( + x1: File, + x2: Boolean, + x3: Array[String], + x4: File, + x5: Array[String] + ): Unit + }].run( + sbtTestDirectory.value, + scriptedBufferLog.value, + args.toArray, + sbtLauncher.value, + scriptedLaunchOpts.value.toArray + ) + } catch { + case e: java.lang.reflect.InvocationTargetException => + throw e.getCause + } + }.evaluated + } + lazy val plugin = javaScalaPluginShared ++ divertThingsPlugin ++ withScriptedTests ++ Seq( + scripted100M6Workaround, scriptedLaunchOpts ++= Seq( "-Xmx1024M", "-Dplugin.version=" + version.value, From 8106a1837f13f84ee433de8ccee2ca4820dc2e5e Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 13 Jun 2017 17:51:50 +0200 Subject: [PATCH 3/4] Ensure scripted finds its launcher Meh --- project/Settings.scala | 53 +++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/project/Settings.scala b/project/Settings.scala index 9a7b09dee..632978d07 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -194,8 +194,16 @@ object Settings { val prereq: Unit = scriptedDependencies.value val scriptedTests = ScriptedPlugin.scriptedTests.value + val testDir = sbtTestDirectory.value + val log = scriptedBufferLog.value + val args0 = args.toArray + val launcher = sbtLauncher.value + val opts = scriptedLaunchOpts.value.toArray + + val sbtv = sbtVersion.in(pluginCrossBuild).value + try { - if(sbtVersion.in(pluginCrossBuild).value == "1.0.0-M6") + if(sbtv == "1.0.0-M6") scriptedTests.asInstanceOf[{ def run( x1: File, @@ -205,14 +213,7 @@ object Settings { x5: Array[String], x6: java.util.List[File] ): Unit - }].run( - sbtTestDirectory.value, - scriptedBufferLog.value, - args.toArray, - sbtLauncher.value, - scriptedLaunchOpts.value.toArray, - new java.util.ArrayList() - ) + }].run(testDir, log, args0, launcher, opts, new java.util.ArrayList) else scriptedTests.asInstanceOf[{ def run( @@ -222,13 +223,7 @@ object Settings { x4: File, x5: Array[String] ): Unit - }].run( - sbtTestDirectory.value, - scriptedBufferLog.value, - args.toArray, - sbtLauncher.value, - scriptedLaunchOpts.value.toArray - ) + }].run(testDir, log, args0, launcher, opts) } catch { case e: java.lang.reflect.InvocationTargetException => throw e.getCause @@ -241,6 +236,32 @@ object Settings { divertThingsPlugin ++ withScriptedTests ++ Seq( + sbtLauncher := { + + val rep = update + .value + .configuration(ScriptedPlugin.scriptedLaunchConf.name) + .getOrElse(sys.error(s"Configuration ${ScriptedPlugin.scriptedLaunchConf.name} not found")) + + val org = "org.scala-sbt" + val name = "sbt-launch" + + val (_, jar) = rep + .modules + .find { modRep => + modRep.module.organization == org && modRep.module.name == name + } + .getOrElse { + sys.error(s"Module $org:$name not found in configuration ${ScriptedPlugin.scriptedLaunchConf.name}") + } + .artifacts + .headOption + .getOrElse { + sys.error(s"No artifacts found for module $org:$name in configuration ${ScriptedPlugin.scriptedLaunchConf.name}") + } + + jar + }, scripted100M6Workaround, scriptedLaunchOpts ++= Seq( "-Xmx1024M", From f83a377bb538fefb2cf0b075c259317f8c4ab416 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 15 Jun 2017 13:16:31 +0200 Subject: [PATCH 4/4] Fix scripted tests for sbt 1.0.0-M6 --- .../sbt-test/sbt-coursier/exclude-dependencies/build.sbt | 2 +- .../project/src/main/scala-2.10/Compatibility.scala | 1 + .../project/src/main/scala-2.12/Compatibility.scala | 5 +++++ .../src/sbt-test/sbt-coursier/no-pom-artifact/build.sbt | 4 +++- .../publish-local-sources-javadoc-conf/build.sbt | 6 ++++-- .../src/sbt-test/sbt-shading/exclude-dependencies/build.sbt | 2 +- .../project/src/main/scala-2.10/Compatibility.scala | 1 + .../project/src/main/scala-2.12/Compatibility.scala | 5 +++++ .../src/sbt-test/sbt-shading/shade-namespace/build.sbt | 2 +- 9 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala create mode 100644 sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala create mode 100644 sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/build.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/build.sbt index 6c0d86ed7..cedd2fa55 100644 --- a/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/build.sbt +++ b/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/build.sbt @@ -1,6 +1,6 @@ // for SbtExclusionRule with sbt 1.0 -import sbt.internal.librarymanagement._ +import Compatibility._ scalaVersion := "2.11.8" diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala b/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala new file mode 100644 index 000000000..19835e1be --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala @@ -0,0 +1 @@ +object Compatibility diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala b/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala new file mode 100644 index 000000000..53962be7a --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala @@ -0,0 +1,5 @@ +object Compatibility { + + val SbtExclusionRule = sbt.ExclusionRule + +} diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/no-pom-artifact/build.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/no-pom-artifact/build.sbt index 372da643b..274b6a675 100644 --- a/sbt-coursier/src/sbt-test/sbt-coursier/no-pom-artifact/build.sbt +++ b/sbt-coursier/src/sbt-test/sbt-coursier/no-pom-artifact/build.sbt @@ -3,6 +3,8 @@ lazy val noPomCheck = TaskKey[Unit]("noPomCheck") noPomCheck := { + val log = streams.value.log + val configReport = update.value .configuration("compile") .getOrElse { @@ -22,7 +24,7 @@ noPomCheck := { } for (a <- pomArtifacts) - streams.value.log.error(s"Found POM artifact $a") + log.error(s"Found POM artifact $a") assert(pomArtifacts.isEmpty) } diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/publish-local-sources-javadoc-conf/build.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/publish-local-sources-javadoc-conf/build.sbt index 0bae35eb6..83b642554 100644 --- a/sbt-coursier/src/sbt-test/sbt-coursier/publish-local-sources-javadoc-conf/build.sbt +++ b/sbt-coursier/src/sbt-test/sbt-coursier/publish-local-sources-javadoc-conf/build.sbt @@ -20,6 +20,8 @@ lazy val shared = Seq( scalaVersion := "2.11.8", confCheck := { + val log = streams.value.log + val updateReport = update.value val updateClassifiersReport = updateClassifiers.value @@ -41,12 +43,12 @@ lazy val shared = Seq( a } - streams.value.log.info( + log.info( s"Found ${artifacts.length} artifacts for config $config / classifier $classifier" + (if (useClassifiersReport) " in classifiers report" else "") ) for (a <- artifacts) - streams.value.log.info(" " + a) + log.info(" " + a) artifacts } diff --git a/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/build.sbt b/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/build.sbt index 2a1f71f12..ebf7f80c8 100644 --- a/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/build.sbt +++ b/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/build.sbt @@ -1,6 +1,6 @@ // for SbtExclusionRule with sbt 1.0 -import sbt.internal.librarymanagement._ +import Compatibility._ enablePlugins(coursier.ShadingPlugin) shadingNamespace := "test.shaded" diff --git a/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala b/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala new file mode 100644 index 000000000..19835e1be --- /dev/null +++ b/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.10/Compatibility.scala @@ -0,0 +1 @@ +object Compatibility diff --git a/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala b/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala new file mode 100644 index 000000000..53962be7a --- /dev/null +++ b/sbt-shading/src/sbt-test/sbt-shading/exclude-dependencies/project/src/main/scala-2.12/Compatibility.scala @@ -0,0 +1,5 @@ +object Compatibility { + + val SbtExclusionRule = sbt.ExclusionRule + +} diff --git a/sbt-shading/src/sbt-test/sbt-shading/shade-namespace/build.sbt b/sbt-shading/src/sbt-test/sbt-shading/shade-namespace/build.sbt index a68e32723..167d55b76 100644 --- a/sbt-shading/src/sbt-test/sbt-shading/shade-namespace/build.sbt +++ b/sbt-shading/src/sbt-test/sbt-shading/shade-namespace/build.sbt @@ -19,9 +19,9 @@ lazy val checkToShadeClasses = TaskKey[Unit]("check-to-shade-classes") checkToShadeClasses := { val toShadeClasses0 = toShadeClasses.in(Shading).value + val log = streams.value.log if (toShadeClasses0.nonEmpty) { - val log = streams.value.log log.error(s"Found ${toShadeClasses0.length} classes to be explicitly shaded") for (name <- toShadeClasses0) log.error(" " + name)