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 93a002d54b1ac4a668b1d71fca45030f2387020d Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Mon Mar 16 16:42:21 2020 +0100 Use the cq-maven-plugin instead of quarkus-maven-plugin for generating new extensions --- docs/modules/ROOT/pages/contributor-guide.adoc | 29 +++++--------- extensions/pom.xml | 29 -------------- pom.xml | 23 +++++++++++ tooling/create-extension-templates/IT.java | 2 +- tooling/create-extension-templates/Processor.java | 2 +- tooling/create-extension-templates/Test.java | 29 ++++++++++---- .../create-extension-templates/TestResource.java | 45 +++++++++++++++++++++- .../integration-test-pom.xml | 8 ++-- .../quarkus-extension.yaml | 35 +++++++++++++++++ tooling/create-extension-templates/runtime-pom.xml | 1 + 10 files changed, 140 insertions(+), 63 deletions(-) diff --git a/docs/modules/ROOT/pages/contributor-guide.adoc b/docs/modules/ROOT/pages/contributor-guide.adoc index a0f5ebb..8e61d00 100644 --- a/docs/modules/ROOT/pages/contributor-guide.adoc +++ b/docs/modules/ROOT/pages/contributor-guide.adoc @@ -65,21 +65,12 @@ $ mvn clean install -Pnative [source,shell] ---- $ cd camel-quarkus -$ cd extensions -$ mvn quarkus:create-extension -N \ - -Dquarkus.artifactIdBase=foo-abc \ - -Dquarkus.nameBase="Foo ABC" \ - -Dquarkus.additionalRuntimeDependencies="org.apache.camel:camel-@{quarkus.artifactIdBase}:@{$}{camel.version}" +$ mvn cq:create -N -Dcq.artifactIdBase=foo-abc ---- + where: + * `foo-abc` is the unique part of the new extension's `artifactId` without the `camel-quarkus-` prefix -* `Foo ABC` is the unique part of the artifact name without the `Camel Quarkus :: ` prefix -* `additionalRuntimeDependencies` adds the `org.apache.camel:camel-foo-abc` dependency to the runtime - BOM (Bill of Materials) and to the runtime module. -+ -The `artifactId` and artifact `name` prefixes and suffixes are added automatically by the plugin. + The above sequence of commands does the following: * It creates three new Maven modules under the `extensions` directory: `camel-quarkus-foo-abc-parent`, `camel-quarkus-foo-abc` @@ -93,16 +84,14 @@ The above sequence of commands does the following: + A compilation performed immediately after generating the modules should pass flawlessly but running the tests will fail because the test project needs to get finished. You need to build `poms/bom` and `poms/bom-deployment` one time first. -+ -TIP: The `nameBase` parameter of the mojo is optional. If you do not specify it on the command line, the plugin will -derive it from `artifactIdBase` by replacing dashes with spaces and capitalizing the first letter of each token. So you -may consider omitting explicit `nameBase` in some cases. - -6. Create `extensions/foo-abc/runtime/src/main/resources/META-INF/quarkus-extension.yaml`. Consult other existing - extensions for the content of the file. -7. Complete the extension by adding dependencies to the runtime module. You probably want to add a dependency on - on the given Camel component - in our case `org.apache.camel:camel-foo-abc`. +6. Review the generated + `extensions/foo-abc/runtime/src/main/resources/META-INF/quarkus-extension.yaml` file. If you + see improper description or keyword, + https://issues.apache.org/jira/secure/CreateIssue!default.jspa[file a new Camel issue] and ask to fix the metadata + for the given Camel component. +7. Review the dependencies in the generate runtime and deployment modules. In case the given library is supported by + Quarkus, you may want to add a dependency on the corresponding Quarkus extension. 8. Complete the integration test module under `integration-tests/foo-abc`. Make sure you test both the consumer and the producer of the component (if the component supports both). Make sure the tests are passing both in the JVM mode @@ -113,7 +102,7 @@ may consider omitting explicit `nameBase` in some cases. 10. If the usage of your new extension differs from the usage of the given Camel component, please add an AsciiDoc page under `docs/modules/ROOT/pages/extensions` and document the differences and Quarkus specific configuration options - there. For our imaginary Camel component `foo-abc` the complete path of the page would be + there. For our imaginary Camel component `foo-abc` the path of the page would be `docs/modules/ROOT/pages/extensions/foo-abc.adoc`. After completing the page, run `mvn clean install -DskipTests` from the root of the source tree to add your extension to the autogenerated list of extensions. diff --git a/extensions/pom.xml b/extensions/pom.xml index f3f3aec..a42483d 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -127,33 +127,4 @@ <module>zipfile</module> </modules> - <build> - <plugins> - <plugin> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <inherited>false</inherited> - <!-- Settings for stubbing new extensions. E.g. to add a new extension to support an imaginary - Camel Foo ABC component, you would run - - mvn quarkus:create-extension -N -Dquarkus.artifactIdBase=foo-abc -Dquarkus.nameBase="Foo ABC" -Dquarkus.additionalRuntimeDependencies="org.apache.camel:camel-@{quarkus.artifactIdBase}:@{$}{camel.version}" - - -Dquarkus.nameBase is optional. If you do not specify it, the plugin will derive it from - artifactIdBase by replacing dashes with spaces and capitalizing the first letter of each token. - --> - <configuration> - <artifactIdPrefix>camel-quarkus-</artifactIdPrefix> - <namePrefix xml:space="preserve">Camel Quarkus :: </namePrefix> - <nameSegmentDelimiter xml:space="preserve"> :: </nameSegmentDelimiter> - <javaPackageInfix>component</javaPackageInfix> - <templatesUriBase>file:///${project.basedir}/../tooling/create-extension-templates</templatesUriBase> - <runtimeBomPath>../poms/bom/pom.xml</runtimeBomPath> - <deploymentBomPath>../poms/bom-deployment/pom.xml</deploymentBomPath> - <bomEntryVersion>@{camel-quarkus.version}</bomEntryVersion> - <itestParentPath>../integration-tests/pom.xml</itestParentPath> - </configuration> - </plugin> - </plugins> - </build> - </project> diff --git a/pom.xml b/pom.xml index 84cdb6f..8d48ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,7 @@ <maven-dependency-plugin.version>3.1.1</maven-dependency-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> + <cq-plugin.version>0.0.1</cq-plugin.version> <!-- maven-release-plugin --> <tagNameFormat>@{project.version}</tagNameFormat> @@ -228,6 +229,11 @@ <artifactId>quarkus-maven-plugin</artifactId> <version>${quarkus.version}</version> </plugin> + <plugin> + <groupId>org.l2x6.cq</groupId> + <artifactId>cq-maven-plugin</artifactId> + <version>${cq-plugin.version}</version> + </plugin> <plugin> <groupId>org.codehaus.gmaven</groupId> @@ -303,6 +309,23 @@ </plugins> </pluginManagement> + <plugins> + <plugin> + <groupId>org.l2x6.cq</groupId> + <artifactId>cq-maven-plugin</artifactId> + <inherited>false</inherited> + <!-- Settings for stubbing new extensions. E.g. to add a new extension to support an imaginary + Camel Foo ABC component, you would run + + mvn cq:create -N -Dcq.artifactIdBase=foo-abc + + --> + <configuration> + <templatesUriBase>file:///${project.basedir}/tooling/create-extension-templates</templatesUriBase> + </configuration> + </plugin> + </plugins> + </build> <profiles> diff --git a/tooling/create-extension-templates/IT.java b/tooling/create-extension-templates/IT.java index 9012813..e8ebb7b 100644 --- a/tooling/create-extension-templates/IT.java +++ b/tooling/create-extension-templates/IT.java @@ -19,6 +19,6 @@ package [=javaPackageBase].it; import io.quarkus.test.junit.NativeImageTest; @NativeImageTest -class [=artifactIdBaseCamelCase]IT extends [=artifactIdBaseCamelCase]Test { +class [=toCapCamelCase(artifactIdBase)]IT extends [=toCapCamelCase(artifactIdBase)]Test { } diff --git a/tooling/create-extension-templates/Processor.java b/tooling/create-extension-templates/Processor.java index 06e13a3..03753fc 100644 --- a/tooling/create-extension-templates/Processor.java +++ b/tooling/create-extension-templates/Processor.java @@ -19,7 +19,7 @@ package [=javaPackageBase].deployment; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.FeatureBuildItem; -class [=artifactIdBaseCamelCase]Processor { +class [=toCapCamelCase(artifactIdBase)]Processor { private static final String FEATURE = "camel-[=artifactIdBase]"; diff --git a/tooling/create-extension-templates/Test.java b/tooling/create-extension-templates/Test.java index 0f5494f..fabd474 100644 --- a/tooling/create-extension-templates/Test.java +++ b/tooling/create-extension-templates/Test.java @@ -16,8 +16,6 @@ */ package [=javaPackageBase].it; -import java.util.UUID; - import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -26,18 +24,35 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @QuarkusTest -class [=artifactIdBaseCamelCase]Test { +class [=toCapCamelCase(artifactIdBase)]Test { +[#if nativeSupported ] @Test public void test() { - final String msg = UUID.randomUUID().toString().replace("-", ""); + final String msg = java.util.UUID.randomUUID().toString().replace("-", ""); RestAssured.given() // - .contentType(ContentType.TEXT).body(msg).post("/[=artifactIdBase]/post") // - .then().statusCode(201); + .contentType(ContentType.TEXT) + .body(msg) + .post("/[=artifactIdBase]/post") // + .then() + .statusCode(201); Assertions.fail("Add some assertions to " + getClass().getName()); - RestAssured.get("/[=artifactIdBase]/get").then().statusCode(200); + RestAssured.get("/[=artifactIdBase]/get") + .then() + .statusCode(200); + } +[#else] +[#list models as model] + @Test + public void load[=toCapCamelCase(model.kind)][=toCapCamelCase(model.scheme)]() { + /* A simple autogenerated test */ + RestAssured.get("/[=artifactIdBase]/load/[=model.kind]/[=model.scheme]") + .then() + .statusCode(200); } +[/#list] +[/#if] } diff --git a/tooling/create-extension-templates/TestResource.java b/tooling/create-extension-templates/TestResource.java index e7ad910..0ddba52 100644 --- a/tooling/create-extension-templates/TestResource.java +++ b/tooling/create-extension-templates/TestResource.java @@ -28,16 +28,21 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +[#if nativeSupported ] import org.apache.camel.ConsumerTemplate; import org.apache.camel.ProducerTemplate; +[#else] +import org.apache.camel.CamelContext; +[/#if] import org.jboss.logging.Logger; @Path("/[=artifactIdBase]") @ApplicationScoped -public class [=artifactIdBaseCamelCase]Resource { +public class [=toCapCamelCase(artifactIdBase)]Resource { - private static final Logger LOG = Logger.getLogger([=artifactIdBaseCamelCase]Resource.class); + private static final Logger LOG = Logger.getLogger([=toCapCamelCase(artifactIdBase)]Resource.class); +[#if nativeSupported ] @Inject ProducerTemplate producerTemplate; @@ -66,4 +71,40 @@ public class [=artifactIdBaseCamelCase]Resource { .entity(response) .build(); } +[#else] +[#list models as m] + private static final String [=toSnakeCase(m.kind)?upper_case]_[=toSnakeCase(m.scheme)?upper_case] = "[=m.scheme]"; +[/#list] + @Inject + CamelContext context; + +[#list models as model] + @Path("/load/[=model.kind]/[=model.scheme]") + @GET + @Produces(MediaType.TEXT_PLAIN) + public Response load[=toCapCamelCase(model.kind)][=toCapCamelCase(model.scheme)]() throws Exception { + /* This is an autogenerated test */ +[#if kind == "other" ] + /* No way to test a Camel artifact of kind "other" */ + return Response.ok().build(); +[#else] +[#if kind == "component" ] +[#assign contextMethod = "getComponent"] +[#elseif kind == "language" ] +[#assign contextMethod = "resolveLanguage"] +[#elseif kind == "dataformat" ] +[#assign contextMethod = "createDataFormat"] +[#else] +[#stop "Unexpected Camel artifact kind " + kind ] +[/#if] +[#assign schemeVarName = "[=toSnakeCase(model.kind)?upper_case]_[=toSnakeCase(model.scheme)?upper_case]"] + if (context.[=contextMethod]([=schemeVarName]) != null) { + return Response.ok().build(); + } + LOG.warnf("Could not load [%s] from the Camel context", [=schemeVarName]); + return Response.status(500, [=schemeVarName] + " could not be loaded from the Camel context").build(); +[/#if] + } +[/#list] +[/#if] } diff --git a/tooling/create-extension-templates/integration-test-pom.xml b/tooling/create-extension-templates/integration-test-pom.xml index 56b3006..b7bce74 100644 --- a/tooling/create-extension-templates/integration-test-pom.xml +++ b/tooling/create-extension-templates/integration-test-pom.xml @@ -23,12 +23,12 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-integration-tests</artifactId> + <artifactId>[=itestParentArtifactId]</artifactId> <version>[=version]</version> </parent> - <artifactId>camel-quarkus-integration-test-[=artifactIdBase]</artifactId> - <name>Camel Quarkus :: Integration Tests :: [=nameBase]</name> + <artifactId>camel-quarkus-[#if nativeSupported]integration-test-[=artifactIdBase][#else][=artifactIdBase]-integration-test[/#if]</artifactId> + <name>Camel Quarkus :: [#if nativeSupported]Integration Tests :: [=nameBase][#else][=nameBase] :: Integration Test[/#if]</name> <description>Integration tests for Camel Quarkus [=nameBase] extension</description> <dependencies> @@ -69,6 +69,7 @@ </plugin> </plugins> </build> +[#if nativeSupported ] <profiles> <profile> @@ -100,4 +101,5 @@ </profile> </profiles> +[/#if] </project> diff --git a/tooling/create-extension-templates/quarkus-extension.yaml b/tooling/create-extension-templates/quarkus-extension.yaml new file mode 100644 index 0000000..c0c67f2 --- /dev/null +++ b/tooling/create-extension-templates/quarkus-extension.yaml @@ -0,0 +1,35 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +--- +name: "[=nameBase]" +description: "[=description]" +metadata: +[#if !nativeSupported ] unlisted: true +[/#if] +[#if keywords?size > 0 ] keywords: +[#list keywords as keyword] + - "[=keyword]" +[/#list] +[/#if] + guide: "[=guideUrl]" +[#if categories?size > 0 ] categories: +[#list categories as category] + - "[=category]" +[/#list] +[/#if] + status: "[=nativeSupported?then('stable', 'preview')]" diff --git a/tooling/create-extension-templates/runtime-pom.xml b/tooling/create-extension-templates/runtime-pom.xml index 1c28b30..dcb11e7 100644 --- a/tooling/create-extension-templates/runtime-pom.xml +++ b/tooling/create-extension-templates/runtime-pom.xml @@ -30,6 +30,7 @@ <artifactId>[=artifactId]</artifactId> <name>[=namePrefix][=nameBase][=nameSegmentDelimiter]Runtime</name> + <description>[=description]</description> <properties> <firstVersion>1.0.0-M6</firstVersion>