From 64c5eb9188999754b1939d7faaef73c03b91dea7 Mon Sep 17 00:00:00 2001 From: kczulko Date: Tue, 6 Feb 2024 10:48:00 +0100 Subject: [PATCH] Enable scala3_sources --- .../scala/org/apache/pekko/grpc/gen/ProtocSettings.scala | 3 ++- .../apache/pekko/grpc/gen/scaladsl/ScalaCodeGenerator.scala | 1 + .../scala/org/apache/pekko/grpc/gen/scaladsl/Service.scala | 6 ++++-- .../src/main/twirl/templates/ScalaClient/Client.scala.txt | 2 +- .../src/main/twirl/templates/ScalaCommon/ApiTrait.scala.txt | 2 +- .../src/main/twirl/templates/ScalaServer/Handler.scala.txt | 2 +- project/plugins.sbt | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/codegen/src/main/scala/org/apache/pekko/grpc/gen/ProtocSettings.scala b/codegen/src/main/scala/org/apache/pekko/grpc/gen/ProtocSettings.scala index 00f7dad8..ac97ba2b 100644 --- a/codegen/src/main/scala/org/apache/pekko/grpc/gen/ProtocSettings.scala +++ b/codegen/src/main/scala/org/apache/pekko/grpc/gen/ProtocSettings.scala @@ -26,5 +26,6 @@ object ProtocSettings { "ascii_format_to_string", "no_lenses", "retain_source_code_info", - "grpc") + "grpc", + "scala3_sources") } diff --git a/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/ScalaCodeGenerator.scala b/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/ScalaCodeGenerator.scala index 65a61c0a..3aa7ea16 100644 --- a/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/ScalaCodeGenerator.scala +++ b/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/ScalaCodeGenerator.scala @@ -99,6 +99,7 @@ abstract class ScalaCodeGenerator extends CodeGenerator { case (p, "no_lenses") => p.copy(lenses = false) case (p, "retain_source_code_info") => p.copy(retainSourceCodeInfo = true) case (p, "grpc") => p.copy(grpc = true) + case (p, "scala3_sources") => p.copy(scala3Sources = true) case (x, _) => x } } diff --git a/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/Service.scala b/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/Service.scala index 94961807..00fe6f6e 100644 --- a/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/Service.scala +++ b/codegen/src/main/scala/org/apache/pekko/grpc/gen/scaladsl/Service.scala @@ -28,7 +28,8 @@ case class Service( serverPowerApi: Boolean, usePlayActions: Boolean, options: com.google.protobuf.DescriptorProtos.ServiceOptions, - comment: Option[String] = None) { + comment: Option[String] = None, + scalaCompatConstants: ScalaCompatConstants) { def serializers: Seq[Serializer] = (methods.map(_.deserializer) ++ methods.map(_.serializer)).distinct def packageDir = packageName.replace('.', '/') } @@ -56,6 +57,7 @@ object Service { serverPowerApi, usePlayActions, serviceDescriptor.getOptions, - serviceDescriptor.comment) + serviceDescriptor.comment, + new ScalaCompatConstants(fileDesc.emitScala3Sources)) } } diff --git a/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt b/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt index 312f0e18..e60fc962 100644 --- a/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt +++ b/codegen/src/main/twirl/templates/ScalaClient/Client.scala.txt @@ -59,7 +59,7 @@ object @{service.name}Client { new Default@{service.name}Client(channel, isChannelOwned = false) private class Default@{service.name}Client(channel: GrpcChannel, isChannelOwned: Boolean)(implicit sys: ClassicActorSystemProvider) extends @{service.name}Client { - import @{service.name}.MethodDescriptors._ + import @{service.name}.MethodDescriptors.@{service.scalaCompatConstants.WildcardImport} private implicit val ex: ExecutionContext = sys.classicSystem.dispatcher private val settings = channel.settings diff --git a/codegen/src/main/twirl/templates/ScalaCommon/ApiTrait.scala.txt b/codegen/src/main/twirl/templates/ScalaCommon/ApiTrait.scala.txt index 7de502e1..8ec7796c 100644 --- a/codegen/src/main/twirl/templates/ScalaCommon/ApiTrait.scala.txt +++ b/codegen/src/main/twirl/templates/ScalaCommon/ApiTrait.scala.txt @@ -58,7 +58,7 @@ object @{service.name} extends pekko.grpc.ServiceDescription { object MethodDescriptors { import pekko.grpc.internal.Marshaller import io.grpc.MethodDescriptor - import Serializers._ + import Serializers.@{service.scalaCompatConstants.WildcardImport} @for(method <- service.methods) { val @{method.name}Descriptor: MethodDescriptor[@method.inputTypeUnboxed, @method.outputTypeUnboxed] = diff --git a/codegen/src/main/twirl/templates/ScalaServer/Handler.scala.txt b/codegen/src/main/twirl/templates/ScalaServer/Handler.scala.txt index a5ce7393..697f8741 100644 --- a/codegen/src/main/twirl/templates/ScalaServer/Handler.scala.txt +++ b/codegen/src/main/twirl/templates/ScalaServer/Handler.scala.txt @@ -121,7 +121,7 @@ object @{serviceName}Handler { implicit val ec: ExecutionContext = mat.executionContext val spi = TelemetryExtension(system).spi - import @{service.name}.Serializers._ + import @{service.name}.Serializers.@{service.scalaCompatConstants.WildcardImport} def handle(request: model.HttpRequest, method: String): scala.concurrent.Future[model.HttpResponse] = GrpcMarshalling.negotiated(request, (reader, writer) => diff --git a/project/plugins.sbt b/project/plugins.sbt index 97de791a..9429feb2 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -51,4 +51,4 @@ libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.1.2022061 // scripted testing libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value -libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.13" +libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.15"