diff --git a/bom/application/pom.xml b/bom/application/pom.xml index b22defaebe009..1deeda04450cd 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -192,6 +192,8 @@ 1.29.0 1.0.1 + 3.11.0 + 3.11.4 4.4.0 0.3.4 @@ -1222,6 +1224,16 @@ quarkus-grpc ${project.version} + + io.quarkus + quarkus-grpc-codegen + ${project.version} + + + io.quarkus + quarkus-grpc-stubs + ${project.version} + io.quarkus quarkus-grpc-deployment @@ -4261,6 +4273,95 @@ jprotoc ${grpc-jprotoc.version} + + com.google.protobuf + protobuf-java + ${protobuf-java.version} + + + com.google.protobuf + protoc + linux-aarch_64 + exe + ${protoc.version} + + + com.google.protobuf + protoc + linux-x86_32 + exe + ${protoc.version} + + + com.google.protobuf + protoc + linux-x86_64 + exe + ${protoc.version} + + + com.google.protobuf + protoc + osx-x86_64 + exe + ${protoc.version} + + + com.google.protobuf + protoc + windows-x86_32 + exe + ${protoc.version} + + + com.google.protobuf + protoc + windows-x86_64 + exe + ${protoc.version} + + + io.grpc + protoc-gen-grpc-java + exe + linux-aarch_64 + ${grpc.version} + + + io.grpc + protoc-gen-grpc-java + exe + linux-x86_32 + ${grpc.version} + + + io.grpc + protoc-gen-grpc-java + exe + linux-x86_64 + ${grpc.version} + + + io.grpc + protoc-gen-grpc-java + exe + osx-x86_64 + ${grpc.version} + + + io.grpc + protoc-gen-grpc-java + exe + windows-x86_32 + ${grpc.version} + + + io.grpc + protoc-gen-grpc-java + exe + windows-x86_64 + ${grpc.version} + diff --git a/build-parent/pom.xml b/build-parent/pom.xml index 7c2d32ace1b0f..9ad6d38efeb1f 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -92,11 +92,6 @@ 0.8.5 - - 1.6.2 - 0.6.1 - 3.11.4 - 1.29.0 3.1.2 @@ -481,16 +476,6 @@ - - kr.motd.maven - os-maven-plugin - ${os-maven-plugin.version} - - - org.xolstice.maven.plugins - protobuf-maven-plugin - ${protobuf-maven-plugin.version} - diff --git a/core/deployment/src/main/java/io/quarkus/deployment/CodeGenProvider.java b/core/deployment/src/main/java/io/quarkus/deployment/CodeGenProvider.java index 7974c580e6df0..04bdfbfb56d2d 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/CodeGenProvider.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/CodeGenProvider.java @@ -16,9 +16,9 @@ public interface CodeGenProvider { String providerId(); /** - * File extensions that CodeGenProvider will generate code from + * File extension that CodeGenProvider will generate code from * - * @return collection of file extensions + * @return file extension */ @NotNull String inputExtension(); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java b/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java index 19472275f002e..5b7ce4af881fb 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java @@ -13,6 +13,9 @@ import io.quarkus.bootstrap.prebuild.CodeGenException; import io.quarkus.deployment.codegen.CodeGenData; +/** + * A set of methods to initialize and execute {@link CodeGenProvider}s. + */ public class CodeGenerator { // used by Gradle diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPrepare.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPrepare.java index 0e8c61e573215..ec1c4fd1e01e1 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPrepare.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPrepare.java @@ -33,7 +33,7 @@ public class QuarkusPrepare extends QuarkusTask { private boolean test = false; public QuarkusPrepare() { - super("Quarkus performs pre-build preparations, such as sources generation"); + super("Performs Quarkus pre-build preparations, such as sources generation"); } @TaskAction diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CodeGenMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CodeGenMojo.java index 67f546f2171af..dc812e5b6131e 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CodeGenMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CodeGenMojo.java @@ -33,7 +33,7 @@ import io.quarkus.deployment.CodeGenerator; import io.quarkus.deployment.codegen.CodeGenData; -@Mojo(name = "prepare", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +@Mojo(name = "prepare", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, threadSafe = true) public class CodeGenMojo extends AbstractMojo { @Parameter(defaultValue = "${project.build.directory}") diff --git a/docs/pom.xml b/docs/pom.xml index 64c7c91d1e3ce..31ca10cb3411f 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -115,8 +115,6 @@ ${grpc.version} ${protoc.version} - ${os-maven-plugin.version} - ${protobuf-maven-plugin.version} ${elasticsearch-server.version} diff --git a/docs/src/main/asciidoc/grpc-getting-started.adoc b/docs/src/main/asciidoc/grpc-getting-started.adoc index eb328b2427307..ae0ed1717d720 100644 --- a/docs/src/main/asciidoc/grpc-getting-started.adoc +++ b/docs/src/main/asciidoc/grpc-getting-started.adoc @@ -15,9 +15,9 @@ The default configuration is enough, but you can also select some extensions if == Configuring your project -Edit the `pom.xml` file to add the quarkus gRPC extension dependency and the JSR 305 (just under ``): +Edit the `pom.xml` file to add the Quarkus gRPC extension dependency (just under ``): -[source, xml] +[source,xml] ---- io.quarkus @@ -25,77 +25,32 @@ Edit the `pom.xml` file to add the quarkus gRPC extension dependency and the JSR ---- -In the `` section, define the 2 following properties: +Make sure you have `prepare` goal of `quarkus-maven-plugin` enabled in your `pom.xml`: -[source, xml, subs="verbatim,attributes"] ----- -{grpc-version} -{protoc-version} ----- - -They configure the gRPC version and the `protoc` version. - -Finally, add to the `build` section the `os-maven-plugin` extension and the `protobuf-maven-plugin` configuration. - -[source, xml, subs="verbatim,attributes"] +[source,xml] ---- - - - kr.motd.maven - os-maven-plugin - {os-maven-plugin-version} - - - - org.xolstice.maven.plugins - protobuf-maven-plugin // <1> - {protobuf-maven-plugin-version} - - com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} // <2> - grpc-java - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - - - quarkus-grpc-protoc-plugin - io.quarkus - quarkus-grpc-protoc-plugin - {quarkus-version} - io.quarkus.grpc.protoc.plugin.MutinyGrpcGenerator - - - + io.quarkus + quarkus-maven-plugin - compile - compile - compile-custom - - - - test-compile - - test-compile - test-compile-custom + prepare + build - - ---- -1. The `protobuf-maven-plugin` that generates stub classes from your gRPC service definition (`proto` files). -2. The class generation uses a tool named `protoc`, which is OS-specific. -That's why we use the `os-maven-plugin` to target the executable compatible with the operating system. - -NOTE: This configuration instructs the `protobuf-maven-plugin` to generate the default gRPC classes and classes using Mutiny to fit with the Quarkus development experience. With this configuration, you can put your service and message definitions in the `src/main/proto` directory. +`quarkus-maven-plugin` will generate Java files from your `proto` files. +Alternatively to using the `prepare` goal of the `quarkus-maven-plugin`, you can use `protobuf-maven-plugin` to generate these files, more in <> + Let's start with a simple _Hello_ service. Create the `src/main/proto/helloworld.proto` file with the following content: @@ -287,14 +242,15 @@ public class ExampleResource { } } ---- -1. Inject the service and configure its name. This name is used in the application configuration + +1. Inject the service and configure its name.This name is used in the application configuration 2. Use the _blocking_ stub (also a generated class) 3. Invoke the service We need to configure the application to indicate where is the `hello` service. In the `src/main/resources/application.properties` file, add the following property: -[source, text] +[source,text] ---- quarkus.grpc.clients.hello.host=localhost ---- @@ -308,3 +264,79 @@ Then, open http://localhost:8080/hello/quarkus in a browser, and you should get Like any other Quarkus applications, you can package it with: `mvn package`. You can also package the application into a native executable with: `mvn package -Pnative`. + +== Generating Java files from proto with protobuf-maven-plugin + +Alternatively to using Quarkus code generation to generate stubs for `proto` files, you can also use +`protobuf-maven-plugin`. + +To do it, first define the 2 following properties in the `` section: + +[source,xml,subs="verbatim,attributes"] +---- +{grpc-version} +{protoc-version} +---- + +They configure the gRPC version and the `protoc` version. + +Then, add to the `build` section the `os-maven-plugin` extension and the `protobuf-maven-plugin` configuration. + +[source,xml,subs="verbatim,attributes"] +---- + + + + kr.motd.maven + os-maven-plugin + ${os-maven-plugin-version} + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin // <1> + ${protobuf-maven-plugin-version} + + com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} // <2> + grpc-java + io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} + + + quarkus-grpc-protoc-plugin + io.quarkus + quarkus-grpc-protoc-plugin + {quarkus-version} + io.quarkus.grpc.protoc.plugin.MutinyGrpcGenerator + + + + + + compile + + compile + compile-custom + + + + test-compile + + test-compile + test-compile-custom + + + + + + + + +---- + +1. The `protobuf-maven-plugin` that generates stub classes from your gRPC service definition (`proto` files). +2. The class generation uses a tool named `protoc`, which is OS-specific. +That's why we use the `os-maven-plugin` to target the executable compatible with the operating system. + +NOTE: This configuration instructs the `protobuf-maven-plugin` to generate the default gRPC classes and classes using Mutiny to fit with the Quarkus development experience. diff --git a/extensions/grpc/codegen/pom.xml b/extensions/grpc/codegen/pom.xml new file mode 100644 index 0000000000000..74e06a25f5f6b --- /dev/null +++ b/extensions/grpc/codegen/pom.xml @@ -0,0 +1,119 @@ + + + 4.0.0 + + quarkus-grpc-parent + io.quarkus + 999-SNAPSHOT + ../ + + + quarkus-grpc-codegen + Quarkus - gRPC - Code Gen + + + + io.quarkus + quarkus-core-deployment + + + io.quarkus + quarkus-devtools-utilities + + + + com.google.protobuf + protoc + linux-aarch_64 + exe + + + com.google.protobuf + protoc + linux-x86_32 + exe + + + com.google.protobuf + protoc + linux-x86_64 + exe + + + com.google.protobuf + protoc + osx-x86_64 + exe + + + com.google.protobuf + protoc + windows-x86_32 + exe + + + com.google.protobuf + protoc + windows-x86_64 + exe + + + io.grpc + protoc-gen-grpc-java + exe + linux-aarch_64 + + + io.grpc + protoc-gen-grpc-java + exe + linux-x86_32 + + + io.grpc + protoc-gen-grpc-java + exe + linux-x86_64 + + + io.grpc + protoc-gen-grpc-java + exe + osx-x86_64 + + + io.grpc + protoc-gen-grpc-java + exe + windows-x86_32 + + + io.grpc + protoc-gen-grpc-java + exe + windows-x86_64 + + + + io.quarkus + quarkus-grpc-protoc-plugin + shaded + + + + + + + + maven-surefire-plugin + + + org.jboss.logmanager.LogManager + + + + + + diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcCodeGen.java b/extensions/grpc/codegen/src/main/java/io/quarkus/grpc/deployment/GrpcCodeGen.java similarity index 94% rename from extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcCodeGen.java rename to extensions/grpc/codegen/src/main/java/io/quarkus/grpc/deployment/GrpcCodeGen.java index 78cf55563718c..dcdc158210bfb 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcCodeGen.java +++ b/extensions/grpc/codegen/src/main/java/io/quarkus/grpc/deployment/GrpcCodeGen.java @@ -62,13 +62,14 @@ public boolean trigger(CodeGenContext context) throws CodeGenException { .filter(Files::isRegularFile) .filter(path -> path.toString().endsWith(".proto")) .map(Path::toString) + .map(this::escapeWhitespace) .collect(Collectors.toList()); if (!protoFiles.isEmpty()) { initExecutables(workDir, context.appModel()); List command = new ArrayList<>(); command.addAll(asList(executables.protoc.toString(), - "-I=" + protoDir.toString(), + "-I=" + escapeWhitespace(protoDir.toString()), "--plugin=protoc-gen-grpc=" + executables.grpc, "--plugin=protoc-gen-q-grpc=" + executables.quarkusGrpc, "--q-grpc_out=" + outDir, @@ -94,6 +95,14 @@ public boolean trigger(CodeGenContext context) throws CodeGenException { return false; } + private String escapeWhitespace(String path) { + if (OS.determineOS() == OS.LINUX) { + return path.replaceAll(" ", "\\ "); + } else { + return path; + } + } + private void initExecutables(Path workDir, AppModel model) throws CodeGenException { if (executables == null) { Path protocExe = prepareExecutable(workDir, model, @@ -195,8 +204,8 @@ private static Path writeScript(Path buildDir, Path pluginPath, String shebang, } private static void writePluginExeCmd(Path pluginPath, BufferedWriter writer) throws IOException { - writer.write(JavaBinFinder.findBin() + " -cp " + - pluginPath.toAbsolutePath().toString() + " " + quarkusProtocPluginMain); + writer.write(JavaBinFinder.findBin() + " -cp \"" + + pluginPath.toAbsolutePath().toString() + "\" " + quarkusProtocPluginMain); writer.newLine(); } diff --git a/extensions/grpc/deployment/src/main/resources/META-INF/services/io.quarkus.deployment.CodeGenProvider b/extensions/grpc/codegen/src/main/resources/META-INF/services/io.quarkus.deployment.CodeGenProvider similarity index 100% rename from extensions/grpc/deployment/src/main/resources/META-INF/services/io.quarkus.deployment.CodeGenProvider rename to extensions/grpc/codegen/src/main/resources/META-INF/services/io.quarkus.deployment.CodeGenProvider diff --git a/extensions/grpc/deployment/pom.xml b/extensions/grpc/deployment/pom.xml index 75cb5cb1aa6bc..f434fb18c047e 100644 --- a/extensions/grpc/deployment/pom.xml +++ b/extensions/grpc/deployment/pom.xml @@ -44,95 +44,9 @@ quarkus-smallrye-health-spi - - com.google.protobuf - protoc - linux-aarch_64 - exe - ${protoc.version} - - - com.google.protobuf - protoc - linux-x86_32 - exe - ${protoc.version} - - - com.google.protobuf - protoc - linux-x86_64 - exe - ${protoc.version} - - - com.google.protobuf - protoc - osx-x86_64 - exe - ${protoc.version} - - - com.google.protobuf - protoc - windows-x86_32 - exe - ${protoc.version} - - - com.google.protobuf - protoc - windows-x86_64 - exe - ${protoc.version} - - - io.grpc - protoc-gen-grpc-java - exe - linux-aarch_64 - ${grpc.version} - - - io.grpc - protoc-gen-grpc-java - exe - linux-x86_32 - ${grpc.version} - - - io.grpc - protoc-gen-grpc-java - exe - linux-x86_64 - ${grpc.version} - - - io.grpc - protoc-gen-grpc-java - exe - osx-x86_64 - ${grpc.version} - - - io.grpc - protoc-gen-grpc-java - exe - windows-x86_32 - ${grpc.version} - - - io.grpc - protoc-gen-grpc-java - exe - windows-x86_64 - ${grpc.version} - - io.quarkus - quarkus-grpc-protoc-plugin - shaded + quarkus-grpc-codegen diff --git a/extensions/grpc/pom.xml b/extensions/grpc/pom.xml index 7c62d8de050b0..df1ba5339850c 100644 --- a/extensions/grpc/pom.xml +++ b/extensions/grpc/pom.xml @@ -15,6 +15,8 @@ pom protoc + codegen + stubs deployment runtime diff --git a/extensions/grpc/protoc/pom.xml b/extensions/grpc/protoc/pom.xml index 6d313ec1597f8..f1d653bc52344 100644 --- a/extensions/grpc/protoc/pom.xml +++ b/extensions/grpc/protoc/pom.xml @@ -14,6 +14,10 @@ Quarkus - gRPC - Protoc Plugin + + com.google.protobuf + protobuf-java + com.salesforce.servicelibs jprotoc @@ -42,6 +46,15 @@ true shaded true + + + com.salesforce.servicelibs:jprotoc + + com/google/protobuf/* + com/google/protobuf/compiler/* + + + diff --git a/extensions/grpc/runtime/pom.xml b/extensions/grpc/runtime/pom.xml index 1ec0b3131308f..4b40c3ad42acc 100644 --- a/extensions/grpc/runtime/pom.xml +++ b/extensions/grpc/runtime/pom.xml @@ -51,6 +51,16 @@ io.quarkus quarkus-arc + + io.quarkus + quarkus-grpc-stubs + + + * + * + + + io.grpc grpc-stub @@ -97,13 +107,6 @@ - - - - kr.motd.maven - os-maven-plugin - - io.quarkus @@ -133,33 +136,6 @@ - - org.xolstice.maven.plugins - protobuf-maven-plugin - - com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} - grpc-java - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - - - quarkus-grpc-protoc-plugin - io.quarkus - quarkus-grpc-protoc-plugin - ${project.version} - io.quarkus.grpc.protoc.plugin.MutinyGrpcGenerator - - - - - - compile - - compile - compile-custom - - - - diff --git a/extensions/grpc/stubs/pom.xml b/extensions/grpc/stubs/pom.xml new file mode 100644 index 0000000000000..3fb9149d53bb0 --- /dev/null +++ b/extensions/grpc/stubs/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + quarkus-grpc-parent + io.quarkus + 999-SNAPSHOT + ../ + + + quarkus-grpc-stubs + Quarkus - gRPC - Stubs for health and reflection + + + + io.quarkus + quarkus-grpc-codegen + + + io.quarkus + quarkus-mutiny + + + io.grpc + grpc-stub + + + com.google.code.findbugs + jsr305 + + + org.checkerframework + checker-qual + + + + + + + + + maven-surefire-plugin + + + org.jboss.logmanager.LogManager + + + + + io.quarkus + quarkus-maven-plugin + + + + prepare + + + + + + + diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/ClientCalls.java b/extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/ClientCalls.java similarity index 100% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/ClientCalls.java rename to extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/ClientCalls.java diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/MultiStreamObserver.java b/extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/MultiStreamObserver.java similarity index 100% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/MultiStreamObserver.java rename to extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/MultiStreamObserver.java diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/ServerCalls.java b/extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/ServerCalls.java similarity index 100% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/ServerCalls.java rename to extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/ServerCalls.java diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/StreamCollector.java b/extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/StreamCollector.java similarity index 100% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/StreamCollector.java rename to extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/StreamCollector.java diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/UniStreamObserver.java b/extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/UniStreamObserver.java similarity index 100% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/UniStreamObserver.java rename to extensions/grpc/stubs/src/main/java/io/quarkus/grpc/runtime/UniStreamObserver.java diff --git a/extensions/grpc/runtime/src/main/proto/health/v1/health.proto b/extensions/grpc/stubs/src/main/proto/health/v1/health.proto similarity index 100% rename from extensions/grpc/runtime/src/main/proto/health/v1/health.proto rename to extensions/grpc/stubs/src/main/proto/health/v1/health.proto diff --git a/extensions/grpc/runtime/src/main/proto/reflection/v1alpha/reflection.proto b/extensions/grpc/stubs/src/main/proto/reflection/v1alpha/reflection.proto similarity index 100% rename from extensions/grpc/runtime/src/main/proto/reflection/v1alpha/reflection.proto rename to extensions/grpc/stubs/src/main/proto/reflection/v1alpha/reflection.proto