This is an automated email from the ASF dual-hosted git repository.

engelen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-grpc.git


The following commit(s) were added to refs/heads/main by this push:
     new 2b510d40 fix: codegen: java: nested protobuf message types (#331)
2b510d40 is described below

commit 2b510d40169fff80e836cc8247336e05ddf5bd79
Author: Arnout Engelen <[email protected]>
AuthorDate: Mon Jun 17 11:02:17 2024 +0200

    fix: codegen: java: nested protobuf message types (#331)
    
    Fixes #328
---
 .../org/apache/pekko/grpc/gen/javadsl/Method.scala |  5 ++++-
 .../sbt-test/gen-java/06-nested-message/build.sbt  | 12 +++++++++++
 .../gen-java/06-nested-message/project/plugins.sbt | 10 ++++++++++
 .../service/v1/impl/TestGrpcsServiceImpl.java      | 23 ++++++++++++++++++++++
 .../06-nested-message/src/main/protobuf/test.proto | 20 +++++++++++++++++++
 .../src/sbt-test/gen-java/06-nested-message/test   |  5 +++++
 6 files changed, 74 insertions(+), 1 deletion(-)

diff --git 
a/codegen/src/main/scala/org/apache/pekko/grpc/gen/javadsl/Method.scala 
b/codegen/src/main/scala/org/apache/pekko/grpc/gen/javadsl/Method.scala
index e8ef2e8e..f92391a1 100644
--- a/codegen/src/main/scala/org/apache/pekko/grpc/gen/javadsl/Method.scala
+++ b/codegen/src/main/scala/org/apache/pekko/grpc/gen/javadsl/Method.scala
@@ -95,7 +95,10 @@ object Method {
     "_root_." + t.getFile.getOptions.getJavaPackage + "." + 
Service.protoName(t.getFile) + "." + t.getName
 
   /** Java API */
-  def getMessageType(t: Descriptor) = {
+  def getMessageType(t: Descriptor): String = {
+    if (t.getContainingType != null)
+      return getMessageType(t.getContainingType) + "." + t.getName
+
     val packageName =
       if (t.getFile.getOptions.hasJavaPackage) 
t.getFile.getOptions.getJavaPackage
       else t.getFile.getPackage
diff --git a/sbt-plugin/src/sbt-test/gen-java/06-nested-message/build.sbt 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/build.sbt
new file mode 100644
index 00000000..3357c9c5
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/build.sbt
@@ -0,0 +1,12 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+enablePlugins(PekkoGrpcPlugin)
+
+pekkoGrpcGeneratedLanguages := Seq(PekkoGrpc.Java)
diff --git 
a/sbt-plugin/src/sbt-test/gen-java/06-nested-message/project/plugins.sbt 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/project/plugins.sbt
new file mode 100644
index 00000000..5eb2b655
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/project/plugins.sbt
@@ -0,0 +1,10 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+addSbtPlugin("org.apache.pekko" % "pekko-grpc-sbt-plugin" % 
sys.props("project.version"))
diff --git 
a/sbt-plugin/src/sbt-test/gen-java/06-nested-message/src/main/java/org/example/service/v1/impl/TestGrpcsServiceImpl.java
 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/src/main/java/org/example/service/v1/impl/TestGrpcsServiceImpl.java
new file mode 100644
index 00000000..be525597
--- /dev/null
+++ 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/src/main/java/org/example/service/v1/impl/TestGrpcsServiceImpl.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+package org.example.service.v1.impl;
+
+import org.apache.pekko.NotUsed;
+import org.apache.pekko.stream.javadsl.Source;
+
+import org.example.service.v1.TestGrpcsService;
+import org.example.service.v1.Test.EnvelopeTest.RequestTest;
+import org.example.service.v1.Test.EnvelopeTest.ResponseTest;
+
+class TestGrpcsServiceImpl implements TestGrpcsService {
+  public Source<ResponseTest, NotUsed> transceive(RequestTest request) {
+    throw new UnsupportedOperationException();
+  }
+}
diff --git 
a/sbt-plugin/src/sbt-test/gen-java/06-nested-message/src/main/protobuf/test.proto
 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/src/main/protobuf/test.proto
new file mode 100644
index 00000000..1e10d9f5
--- /dev/null
+++ 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/src/main/protobuf/test.proto
@@ -0,0 +1,20 @@
+syntax = "proto3";
+
+option java_generate_equals_and_hash = true;
+option java_package = "org.example.service.v1";
+
+message EnvelopeTest {
+  oneof type
+  {
+    RequestTest request = 4;
+    ResponseTest response = 6;
+  }
+  message RequestTest {
+  }
+  message ResponseTest {
+  }
+}
+
+service TestGrpcsService {
+  rpc Transceive(EnvelopeTest.RequestTest) returns (stream 
EnvelopeTest.ResponseTest) {}
+}
diff --git a/sbt-plugin/src/sbt-test/gen-java/06-nested-message/test 
b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/test
new file mode 100644
index 00000000..5d6fcad1
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/gen-java/06-nested-message/test
@@ -0,0 +1,5 @@
+> compile
+
+$ exists target/scala-2.12/pekko-grpc
+$ exists 
target/scala-2.12/pekko-grpc/main/org/example/service/v1/TestGrpcsServiceClient.java
+$ exists 
target/scala-2.12/classes/org/example/service/v1/impl/TestGrpcsServiceImpl.class


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to