You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2020/11/20 12:38:04 UTC
[camel-quarkus] 02/03: Leverage Quarkus plugin's generate-code mojo
instead of protobuf-maven-plugin to generate protobuf stubs
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit d8e024fcb616ab7e6a555b5d9acc369c02c05862
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Thu Nov 19 14:34:00 2020 +0100
Leverage Quarkus plugin's generate-code mojo instead of
protobuf-maven-plugin to generate protobuf stubs
---
.../ROOT/pages/reference/extensions/grpc.adoc | 27 ++++++++++
.../component/grpc/deployment/GrpcProcessor.java | 7 +++
.../grpc/runtime/src/main/doc/configuration.adoc | 27 ++++++++++
.../runtime/QuarkusBindableServiceFactory.java | 1 -
integration-tests/grpc/pom.xml | 63 ++--------------------
pom.xml | 2 -
poms/build-parent-it/pom.xml | 2 +
poms/build-parent/pom.xml | 10 ----
8 files changed, 67 insertions(+), 72 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/grpc.adoc b/docs/modules/ROOT/pages/reference/extensions/grpc.adoc
index b81be3f..4f646ef 100644
--- a/docs/modules/ROOT/pages/reference/extensions/grpc.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/grpc.adoc
@@ -42,3 +42,30 @@ endpoint configuration host / port mirror the Quarkus gRPC host / port property
The full list of Quarkus gRPC configuration options can be found at the https://quarkus.io/guides/grpc-service-implementation#server-configuration[Quarkus gRPC guide].
+Use the `generate-code` goal of `quarkus-maven-plugin` to generate Java classes from your `*.proto`
+service and message definitions stored in the `src/main/proto` directory:
+
+[source,xml]
+----
+<build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-code</goal>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+</build>
+----
+
+You may want to check the https://github.com/apache/camel-quarkus/tree/master/integration-tests/grpc[integration test]
+in our source tree as an example.
+
+
diff --git a/extensions/grpc/deployment/src/main/java/org/apache/camel/quarkus/component/grpc/deployment/GrpcProcessor.java b/extensions/grpc/deployment/src/main/java/org/apache/camel/quarkus/component/grpc/deployment/GrpcProcessor.java
index 9ea7dda..b752cbe 100644
--- a/extensions/grpc/deployment/src/main/java/org/apache/camel/quarkus/component/grpc/deployment/GrpcProcessor.java
+++ b/extensions/grpc/deployment/src/main/java/org/apache/camel/quarkus/component/grpc/deployment/GrpcProcessor.java
@@ -125,6 +125,13 @@ class GrpcProcessor {
if (!Modifier.isAbstract(service.flags())) {
continue;
}
+ if (service.name().withoutPackagePrefix().startsWith("Mutiny")) {
+ /* The generate-code goal of quarkus-maven-plugin generates also Mutiny service that we do not use
+ * Not skipping it here results in randomly registering the Mutiny one or the right one.
+ * In case the Mutiny service one is registered, the client throws something like
+ * io.grpc.StatusRuntimeException: UNIMPLEMENTED */
+ continue;
+ }
String superClassName = service.name().toString();
String generatedClassName = superClassName + "QuarkusMethodHandler";
diff --git a/extensions/grpc/runtime/src/main/doc/configuration.adoc b/extensions/grpc/runtime/src/main/doc/configuration.adoc
index f903be5..f02957e 100644
--- a/extensions/grpc/runtime/src/main/doc/configuration.adoc
+++ b/extensions/grpc/runtime/src/main/doc/configuration.adoc
@@ -4,3 +4,30 @@ and `quarkus.grpc.server.port` and thus the Camel gRPC endpoint configuration fo
endpoint configuration host / port mirror the Quarkus gRPC host / port property values to avoid confusion and ambiguity.
The full list of Quarkus gRPC configuration options can be found at the https://quarkus.io/guides/grpc-service-implementation#server-configuration[Quarkus gRPC guide].
+
+Use the `generate-code` goal of `quarkus-maven-plugin` to generate Java classes from your `*.proto`
+service and message definitions stored in the `src/main/proto` directory:
+
+[source,xml]
+----
+<build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-code</goal>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+</build>
+----
+
+You may want to check the https://github.com/apache/camel-quarkus/tree/master/integration-tests/grpc[integration test]
+in our source tree as an example.
+
diff --git a/extensions/grpc/runtime/src/main/java/org/apache/camel/quarkus/grpc/runtime/QuarkusBindableServiceFactory.java b/extensions/grpc/runtime/src/main/java/org/apache/camel/quarkus/grpc/runtime/QuarkusBindableServiceFactory.java
index 7ffd3fd..6f48f5c 100644
--- a/extensions/grpc/runtime/src/main/java/org/apache/camel/quarkus/grpc/runtime/QuarkusBindableServiceFactory.java
+++ b/extensions/grpc/runtime/src/main/java/org/apache/camel/quarkus/grpc/runtime/QuarkusBindableServiceFactory.java
@@ -56,7 +56,6 @@ public class QuarkusBindableServiceFactory implements BindableServiceFactory {
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"Unable to find generated class for service " + endpoint.getServiceName()));
-
bindableService.setMethodHandler(new GrpcMethodHandler(consumer));
return bindableService;
}
diff --git a/integration-tests/grpc/pom.xml b/integration-tests/grpc/pom.xml
index ebd8495..884fb95 100644
--- a/integration-tests/grpc/pom.xml
+++ b/integration-tests/grpc/pom.xml
@@ -92,70 +92,15 @@
<build>
<plugins>
<plugin>
- <groupId>kr.motd.maven</groupId>
- <artifactId>os-maven-plugin</artifactId>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
- <phase>initialize</phase>
+ <id>quarkus-generate-code</id>
<goals>
- <goal>detect</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.gmaven</groupId>
- <artifactId>groovy-maven-plugin</artifactId>
- <executions>
- <execution>
- <!-- gRPC is managed in Quarkus BOM but we still need ${grpc.version} for the protobuf-maven-plugin bellow -->
- <!-- To solve that we parse the Quarkus BOM POM and set the grpc.version property dynamically -->
- <!-- instead of hardcoding it -->
- <id>set-grpc-version-property</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>execute</goal>
- </goals>
- <configuration>
- <properties>
- <localRepository>${settings.localRepository}</localRepository>
- <quarkusVersion>${quarkus.version}</quarkusVersion>
- </properties>
- <source>
- import java.nio.file.Path
- import java.nio.file.Paths
- import java.nio.file.Files
- final Path localMavenRepoPath = Paths.get(properties['localRepository'])
- final Path quarkusBomPath = localMavenRepoPath.resolve('io/quarkus/quarkus-bom/' + properties['quarkusVersion'] + '/quarkus-bom-' + properties['quarkusVersion'] + '.pom')
- if (!Files.exists(quarkusBomPath)) {
- throw new IllegalStateException(quarkusBomPath + ' should exist')
- }
- def pomProject = new XmlParser().parseText(quarkusBomPath.getText('UTF-8'))
- final String grpcVersion = pomProject.properties.'grpc.version'.text()
- println 'setting grpc.version = ' + grpcVersion + ' as found in Quarkus BOM'
- project.properties['grpc.version'] = grpcVersion
- </source>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.xolstice.maven.plugins</groupId>
- <artifactId>protobuf-maven-plugin</artifactId>
- <extensions>true</extensions>
- <executions>
- <execution>
- <goals>
- <goal>compile</goal>
- <goal>compile-custom</goal>
+ <goal>generate-code</goal>
</goals>
<phase>generate-sources</phase>
- <configuration>
- <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
- <pluginId>grpc-java</pluginId>
- <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
- <checkStaleness>true</checkStaleness>
- </configuration>
</execution>
</executions>
</plugin>
diff --git a/pom.xml b/pom.xml
index 7db7fa9..6afd688 100644
--- a/pom.xml
+++ b/pom.xml
@@ -149,9 +149,7 @@
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
<!-- NOTE: We pin to this version due to https://github.com/apache/camel-quarkus/issues/723 -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
- <os-maven-plugin.version>1.6.2</os-maven-plugin.version>
<properties-maven-plugin.version>1.0.0</properties-maven-plugin.version>
- <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<protobuf-java.version>3.11.0</protobuf-java.version>
<proto-google-common-protos.version>1.17.0</proto-google-common-protos.version>
<rpkgtests-maven-plugin.version>0.9.0</rpkgtests-maven-plugin.version>
diff --git a/poms/build-parent-it/pom.xml b/poms/build-parent-it/pom.xml
index 93f8822..c568449 100644
--- a/poms/build-parent-it/pom.xml
+++ b/poms/build-parent-it/pom.xml
@@ -122,9 +122,11 @@
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
+ <id>quarkus-build</id>
<goals>
<goal>build</goal>
</goals>
+ <phase>package</phase>
</execution>
</executions>
</plugin>
diff --git a/poms/build-parent/pom.xml b/poms/build-parent/pom.xml
index 57666c8..a8bd4ae 100644
--- a/poms/build-parent/pom.xml
+++ b/poms/build-parent/pom.xml
@@ -71,11 +71,6 @@
</executions>
</plugin>
<plugin>
- <groupId>kr.motd.maven</groupId>
- <artifactId>os-maven-plugin</artifactId>
- <version>${os-maven-plugin.version}</version>
- </plugin>
- <plugin>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-maven-plugin</artifactId>
<version>${project.version}</version>
@@ -95,11 +90,6 @@
<version>${jandex-maven-plugin.version}</version>
</plugin>
<plugin>
- <groupId>org.xolstice.maven.plugins</groupId>
- <artifactId>protobuf-maven-plugin</artifactId>
- <version>${protobuf-maven-plugin.version}</version>
- </plugin>
- <plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter-maven-plugin.version}</version>