From fde55bad50b74dbfe8d219bb6f6e503d26c1ad01 Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Wed, 7 Aug 2024 22:21:44 +0300 Subject: [PATCH] fix: include logging3 into tofu aggregted modules Fixes artifacts publishing for scala3. Also fixes test for logstash-logback module. --- build.sbt | 85 +++++++++++-------- .../logging/TofuLoggingProviderSuite.scala | 9 +- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/build.sbt b/build.sbt index 854f36939..7a918a86e 100644 --- a/build.sbt +++ b/build.sbt @@ -241,41 +241,58 @@ lazy val loggingEnumeratum = projectMatrix .jvmPlatform(scala2And3Versions) .dependsOn(loggingStr) -lazy val logging = projectMatrix - .in(modules / "logging") - .aggregate( - loggingStr, - loggingDer, - loggingLayout, - loggingShapeless, - loggingRefined, - loggingLog4Cats, - loggingLog4CatsLegacy, - loggingLogstashLogback, - ) - .settings( - defaultSettings, - name := "tofu-logging" - ) - .dependsOn(loggingStr, loggingDer, loggingLayout, loggingShapeless, loggingRefined, loggingLog4Cats) - .jvmPlatform(scala2Versions) +lazy val logging = { + def projectRefFromMatrix(pm: ProjectMatrix, scalaVersion: String): ProjectReference = { + val projects = pm.filterProjects(Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion(scalaVersion))) + projects.headOption match { + case Some(p) => p + case None => throw new Exception(s"Can't found $scalaVersion axis for ${pm}") + } + } -lazy val logging3 = projectMatrix - .in(modules / "logging") - .aggregate( - loggingStr, - loggingDer, - loggingLayout, - loggingRefined, - loggingLog4Cats, - loggingLogstashLogback, - ) - .settings( - defaultSettings, - name := "tofu-logging" - ) - .dependsOn(loggingStr, loggingDer, loggingLayout, loggingRefined, loggingLog4Cats) - .jvmPlatform(List(Version.scala3)) + val modulesSettings = + List( + // ($project, $haScala3, $dependsOn) + (loggingStr, true, true), + (loggingDer, true, true), + (loggingLayout, true, true), + (loggingShapeless, false, true), + (loggingRefined, true, true), + (loggingLog4Cats, true, true), + (loggingLogstashLogback, true, true), + ) + + val initial = ProjectMatrix("logging", modules / "logging") + scala2And3Versions.foldLeft(initial) { case (prMatrix, scalaVersionValue) => + val scalaAxis = VirtualAxis.scalaABIVersion(scalaVersionValue) + prMatrix.customRow( + autoScalaLibrary = true, + axisValues = Seq(VirtualAxis.jvm, scalaAxis), + process = (pr: Project) => { + val filterScala = + if (scalaVersionValue.startsWith("3")) identity[Boolean](_) + else (_: Boolean) => true + val (aggModules, dependsOnModules) = + modulesSettings.foldLeft((List.empty[ProjectReference], List.empty[ClasspathDependency])) { + case ((agg, dependsOn), (prM, hasScala3, isInDependsOn)) if filterScala(hasScala3) => + val ref = projectRefFromMatrix(prM, scalaVersionValue) + val nextAgg = ref :: agg + val nextDependsOn = if (isInDependsOn) ClasspathDependency(ref, None) :: dependsOn else dependsOn + (nextAgg, nextDependsOn) + case (acc, _) => acc + } + + pr.aggregate(aggModules: _*) + .settings( + defaultSettings, + scalaVersion := scalaVersionValue, + name := "tofu-logging" + ) + .dependsOn(dependsOnModules: _*) + } + ) + } +} val util = modules / "util" diff --git a/modules/logging/interop/logstash-logback/src/test/scala/tofu/logging/TofuLoggingProviderSuite.scala b/modules/logging/interop/logstash-logback/src/test/scala/tofu/logging/TofuLoggingProviderSuite.scala index 3b70997db..3c62ffebc 100644 --- a/modules/logging/interop/logstash-logback/src/test/scala/tofu/logging/TofuLoggingProviderSuite.scala +++ b/modules/logging/interop/logstash-logback/src/test/scala/tofu/logging/TofuLoggingProviderSuite.scala @@ -6,7 +6,6 @@ import ch.qos.logback.classic.Logger import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.core.read.ListAppender import com.fasterxml.jackson.core.{JsonFactory, JsonGenerator} -import derevo.derive import org.scalatest.funsuite.AnyFunSuite import org.slf4j.LoggerFactory import tofu.Delay @@ -55,11 +54,15 @@ class TofuLoggingProviderSuite extends AnyFunSuite { } object TofuLoggingProviderSuite { - @derive(tofu.logging.derivation.loggable) final case class LoggingContext(inner: LoggingContextInner, what: String) + object LoggingContext { + implicit val loggable: Loggable[LoggingContext] = tofu.logging.derivation.loggable.instance + } - @derive(tofu.logging.derivation.loggable) final case class LoggingContextInner(keks: Int, shreks: Int) + object LoggingContextInner { + implicit val loggable: Loggable[LoggingContextInner] = tofu.logging.derivation.loggable.instance + } val ExampleCtx = LoggingContext(LoggingContextInner(2, 3), "swamp") }