From 20821a1cc7c17bb6a2bc611ac18adefae6fbfd8a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 12 Apr 2020 14:04:25 -0400 Subject: [PATCH] Add configure(...) --- .../scala/sbt/internal/ProjectMatrix.scala | 27 ++++++++++++++----- .../projectMatrix/jvm-with-scoping/build.sbt | 10 +++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/scala/sbt/internal/ProjectMatrix.scala b/src/main/scala/sbt/internal/ProjectMatrix.scala index 439930793..6094c8033 100644 --- a/src/main/scala/sbt/internal/ProjectMatrix.scala +++ b/src/main/scala/sbt/internal/ProjectMatrix.scala @@ -56,6 +56,12 @@ sealed trait ProjectMatrix extends CompositeProject { /** Disable the given plugins on this project. */ def disablePlugins(ps: AutoPlugin*): ProjectMatrix + /** + * Applies the given functions to this Project. + * The second function is applied to the result of applying the first to this Project and so on. + * The intended use is a convenience for applying default configuration provided by a plugin. + */ + def configure(transforms: (Project => Project)*): ProjectMatrix /** * If autoScalaLibrary is false, add non-Scala row. @@ -182,7 +188,8 @@ object ProjectMatrix { val dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]], val settings: Seq[Def.Setting[_]], val configurations: Seq[Configuration], - val plugins: Plugins + val plugins: Plugins, + val transforms: Seq[Project => Project], ) extends ProjectMatrix { self => lazy val resolvedMappings: ListMap[ProjectRow, Project] = resolveMappings private def resolveProjectIds: Map[ProjectRow, String] = { @@ -240,6 +247,7 @@ object ProjectMatrix { inConfig(Test)(makeSources(nonScalaDirSuffix, svDirSuffix)) ) .settings(self.settings) + .configure(transforms: _*) r -> r.process(p) }): _*) @@ -300,6 +308,9 @@ object ProjectMatrix { override def disablePlugins(ps: AutoPlugin*): ProjectMatrix = setPlugins(Plugins.and(plugins, Plugins.And(ps.map(p => Plugins.Exclude(p)).toList))) + override def configure(ts: (Project => Project)*): ProjectMatrix = + copy(transforms = transforms ++ ts) + def setPlugins(ns: Plugins): ProjectMatrix = copy(plugins = ns) override def jvmPlatform(scalaVersions: Seq[String]): ProjectMatrix = @@ -434,7 +445,8 @@ object ProjectMatrix { dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]] = dependencies, settings: Seq[Setting[_]] = settings, configurations: Seq[Configuration] = configurations, - plugins: Plugins = plugins + plugins: Plugins = plugins, + transforms: Seq[Project => Project] = transforms, ): ProjectMatrix = { val matrix = unresolved( id, @@ -445,7 +457,8 @@ object ProjectMatrix { dependencies, settings, configurations, - plugins + plugins, + transforms ) allMatrices(id) = matrix matrix @@ -454,7 +467,7 @@ object ProjectMatrix { // called by macro def apply(id: String, base: sbt.File): ProjectMatrix = { - val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty) + val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil) allMatrices(id) = matrix matrix } @@ -468,7 +481,8 @@ object ProjectMatrix { dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]], settings: Seq[Def.Setting[_]], configurations: Seq[Configuration], - plugins: Plugins + plugins: Plugins, + transforms: Seq[Project => Project] ): ProjectMatrix = new ProjectMatrixDef( id, @@ -479,7 +493,8 @@ object ProjectMatrix { dependencies, settings, configurations, - plugins + plugins, + transforms ) def lookupMatrix(local: LocalProjectMatrix): ProjectMatrix = { diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt b/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt index 07d3dbb3a..a7cbf2055 100644 --- a/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt @@ -17,9 +17,13 @@ lazy val core = (projectMatrix in file("core")) .settings( check := { assert(moduleName.value == "core", s"moduleName is ${moduleName.value}") + + val directs = libraryDependencies.value + assert(directs.size == 2, s"$directs") }, ) .jvmPlatform(scalaVersions = Seq("2.12.8", "2.11.12")) + .configure(addStuff) lazy val intf = (projectMatrix in file("intf")) .settings( @@ -30,3 +34,9 @@ lazy val intf = (projectMatrix in file("intf")) .jvmPlatform(autoScalaLibrary = false) lazy val core212 = core.jvm("2.12.8") + +def addStuff(p: Project): Project = { + p.settings( + libraryDependencies += "junit" % "junit" % "4.12" % Test + ) +}