You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/02/20 16:09:25 UTC

[camel-quarkus] branch 4393/get-rid-of-report-unsupported-elements-at-runtime updated: Ref #4393: Get rid of --report-unsupported-elements-at-runtime for Groovy DSL

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

nfilotto pushed a commit to branch 4393/get-rid-of-report-unsupported-elements-at-runtime
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/4393/get-rid-of-report-unsupported-elements-at-runtime by this push:
     new 7a8ff7dbea Ref #4393: Get rid of --report-unsupported-elements-at-runtime for Groovy DSL
7a8ff7dbea is described below

commit 7a8ff7dbea76efa73a4dca7e40402f5e2b1a9efa
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Mon Feb 20 17:09:02 2023 +0100

    Ref #4393: Get rid of --report-unsupported-elements-at-runtime for Groovy DSL
---
 .../pages/reference/extensions/groovy-dsl.adoc     | 17 ---------
 .../dsl/groovy/deployment/GroovyDslProcessor.java  | 22 ++++++------
 .../runtime/src/main/doc/limitations.adoc          | 17 ---------
 integration-tests/groovy-dsl/pom.xml               | 23 ++----------
 .../quarkus/dsl/groovy/GroovyDslResource.java      | 19 ++++++++++
 .../routes-with-components-configuration.groovy    | 17 +++++----
 .../routes-with-dataformats-configuration.groovy   |  4 +--
 .../routes/routes-with-endpoint-dsl.groovy         |  3 +-
 .../routes/routes-with-error-handler.groovy        |  6 ++--
 .../routes-with-languages-configuration.groovy     | 10 ++++--
 ...onfiguration.groovy => routes-with-rest.groovy} | 42 ++++++++++++++--------
 .../camel/quarkus/dsl/groovy/GroovyDslTest.java    | 22 +++++++++++-
 12 files changed, 109 insertions(+), 93 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc b/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc
index b5b1d0c9e4..f9c62daa0d 100644
--- a/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc
@@ -49,20 +49,3 @@ endif::[]
 
 The Groovy extensions are not supported which means that the extensions defined in the Camel project are ignored, more details in https://github.com/apache/camel-quarkus/issues/4384[Groovy DSL - Add support of Groovy extensions issue #4384].
 
-In case of native compilation, for some specific use cases like the following one, it could be needed to add the flag `--report-unsupported-elements-at-runtime` to prevent compilation error of type `DeletedElementException: Unsupported method java.lang.Class.registerNatives() is reachable`.
-
-[source,groovy]
-----
-import org.apache.camel.component.seda.SedaComponent
-
-camel {
-    components {
-        mySeda(SedaComponent) { // <1>
-            // rest of the closure here
-        }
-    }
-}
-// rest of the Groovy script
-----
-<1> Requires the flag `--report-unsupported-elements-at-runtime` to be added to the build command for native compilation.
-
diff --git a/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java b/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java
index 739c7221d6..5f23bb77c0 100644
--- a/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java
+++ b/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java
@@ -24,7 +24,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
@@ -55,14 +54,17 @@ public class GroovyDslProcessor {
 
     private static final Logger LOG = LoggerFactory.getLogger(GroovyDslProcessor.class);
     private static final String PACKAGE_NAME = "org.apache.camel.quarkus.dsl.groovy.generated";
-    private static final String FILE_FORMAT = "package %s\n" +
-            "%s\n" +
-            "@groovy.transform.InheritConstructors \n" +
-            "class %s extends %s {\n" +
-            "  void configure(){ \n" +
-            "    %s\n" +
-            "  }\n" +
-            "}";
+    private static final String FILE_FORMAT = """
+            package %s
+            %s
+            @groovy.transform.InheritConstructors
+            class %s extends %s {
+              void configure() {
+                %s
+              }
+            }
+            """;
+
     private static final String FEATURE = "camel-groovy-dsl";
 
     @BuildStep
@@ -101,7 +103,7 @@ public class GroovyDslProcessor {
                         .map(ResolvedDependency::getResolvedPaths)
                         .flatMap(PathCollection::stream)
                         .map(Objects::toString)
-                        .collect(Collectors.toList()));
+                        .toList());
         unit.configure(cc);
         unit.compile(Phases.CLASS_GENERATION);
         for (GroovyClass clazz : unit.getClasses()) {
diff --git a/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc b/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc
index b1a77c234a..a77743a491 100644
--- a/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc
+++ b/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc
@@ -1,18 +1 @@
 The Groovy extensions are not supported which means that the extensions defined in the Camel project are ignored, more details in https://github.com/apache/camel-quarkus/issues/4384[Groovy DSL - Add support of Groovy extensions issue #4384].
-
-In case of native compilation, for some specific use cases like the following one, it could be needed to add the flag `--report-unsupported-elements-at-runtime` to prevent compilation error of type `DeletedElementException: Unsupported method java.lang.Class.registerNatives() is reachable`.
-
-[source,groovy]
-----
-import org.apache.camel.component.seda.SedaComponent
-
-camel {
-    components {
-        mySeda(SedaComponent) { // <1>
-            // rest of the closure here
-        }
-    }
-}
-// rest of the Groovy script
-----
-<1> Requires the flag `--report-unsupported-elements-at-runtime` to be added to the build command for native compilation.
diff --git a/integration-tests/groovy-dsl/pom.xml b/integration-tests/groovy-dsl/pom.xml
index cb0e802a89..07f11a865a 100644
--- a/integration-tests/groovy-dsl/pom.xml
+++ b/integration-tests/groovy-dsl/pom.xml
@@ -39,10 +39,6 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-direct</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-seda</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-jackson</artifactId>
@@ -53,11 +49,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-timer</artifactId>
+            <artifactId>camel-quarkus-log</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-log</artifactId>
+            <artifactId>camel-quarkus-rest</artifactId>
         </dependency>
         <dependency>
             <groupId>io.quarkus</groupId>
@@ -159,20 +155,7 @@
                 </dependency>
                 <dependency>
                     <groupId>org.apache.camel.quarkus</groupId>
-                    <artifactId>camel-quarkus-seda-deployment</artifactId>
-                    <version>${project.version}</version>
-                    <type>pom</type>
-                    <scope>test</scope>
-                    <exclusions>
-                        <exclusion>
-                            <groupId>*</groupId>
-                            <artifactId>*</artifactId>
-                        </exclusion>
-                    </exclusions>
-                </dependency>
-                <dependency>
-                    <groupId>org.apache.camel.quarkus</groupId>
-                    <artifactId>camel-quarkus-timer-deployment</artifactId>
+                    <artifactId>camel-quarkus-rest-deployment</artifactId>
                     <version>${project.version}</version>
                     <type>pom</type>
                     <scope>test</scope>
diff --git a/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java b/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java
index c0af54f739..b731e15a85 100644
--- a/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java
+++ b/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.quarkus.dsl.groovy;
 
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import jakarta.enterprise.context.ApplicationScoped;
@@ -29,6 +30,7 @@ import jakarta.ws.rs.core.MediaType;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
+import org.apache.camel.component.direct.DirectEndpoint;
 import org.apache.camel.dsl.groovy.GroovyRoutesBuilderLoader;
 import org.apache.camel.quarkus.main.CamelMain;
 import org.apache.camel.spi.RoutesBuilderLoader;
@@ -71,6 +73,23 @@ public class GroovyDslResource {
                 .collect(Collectors.joining(","));
     }
 
+    @GET
+    @Path("/main/successful/routes")
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public int successfulRoutes() {
+        int successful = 0;
+        Set<String> excluded = Set.of("my-groovy-route", "routes-with-rest-dsl-get", "routes-with-rest-dsl-post");
+        for (Route route : main.getCamelContext().getRoutes()) {
+            String name = route.getRouteId();
+            if (route.getEndpoint() instanceof DirectEndpoint && !excluded.contains(name)
+                    && producerTemplate.requestBody(route.getEndpoint(), "", Boolean.class) == Boolean.TRUE) {
+                successful++;
+            }
+        }
+        return successful;
+    }
+
     @POST
     @Path("/hello")
     @Consumes(MediaType.TEXT_PLAIN)
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy
index c32538db86..276b1246d1 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy
@@ -14,20 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import org.apache.camel.component.direct.DirectComponent
 
 camel {
     components {
-        seda {
+        direct {
             // set value as method
-            queueSize 1234
-
-            // set value as property
-            concurrentConsumers = 12
+            timeout 1234
+        }
+        myDirect(DirectComponent) {
+            // set value as method
+            timeout = 4321
         }
     }
 }
 
 
-from('timer:tick')
+
+from('direct:routes-with-components-configuration')
     .id('routes-with-components-configuration')
-    .to('log:info')
+    .setBody(simple('${camelContext.getComponent("myDirect")} != null', Boolean.class))
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
index 127dba3550..3e2788cbaf 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
@@ -31,6 +31,6 @@ camel {
 }
 
 
-from('timer:tick')
+from('direct:routes-with-dataformats-configuration')
     .id('routes-with-dataformats-configuration')
-    .to('log:info')
+    .setBody(simple('${ref:my-jackson} != null', Boolean.class))
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy
index 18f2b7b9ce..c5b76d2298 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy
@@ -14,9 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-def f = timer('tick').period('1s')
+def f = direct("routes-with-endpoint-dsl").advanced().synchronous(true)
 def t = log('info')
 
 from(f)
     .id('routes-with-endpoint-dsl')
+    .setBody().constant("true")
     .to(t)
\ No newline at end of file
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy
index 406269a016..a58cf634d9 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy
@@ -19,6 +19,8 @@ onException(IllegalArgumentException.class)
     .id('my-on-exception')
     .to('log:exception')
 
-from('timer:tick')
+from('direct:routes-with-error-handler')
     .id('routes-with-error-handler')
-    .to('log:info')
\ No newline at end of file
+    .setHeader("SomeHeader", constant("SomeHeaderValue"))
+    .filter().simple('${header.SomeHeader} == "SomeHeaderValue"')
+    .setBody().constant("true")
\ No newline at end of file
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy
index 144249b8ae..90ef41a68c 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy
@@ -1,3 +1,5 @@
+import org.apache.camel.language.bean.BeanLanguage
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -21,10 +23,14 @@ camel {
             beanType = String.class
             method = "toUpperCase"
         }
+        myBean(BeanLanguage) {
+            beanType = String.class
+            method = "toLowerCase"
+        }
     }
 }
 
 
-from('timer:tick')
+from('direct:routes-with-languages-configuration')
     .id('routes-with-languages-configuration')
-    .to('log:info')
\ No newline at end of file
+    .setBody(simple('${ref:my-bean} != null', Boolean.class))
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-rest.groovy
similarity index 50%
copy from integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
copy to integration-tests/groovy-dsl/src/main/resources/routes/routes-with-rest.groovy
index 127dba3550..06046d781a 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-rest.groovy
@@ -14,23 +14,37 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+rest {
+    configuration {
+        contextPath = "/root"
+    }
 
-import org.apache.camel.component.jackson.JacksonDataFormat
-
-camel {
-    dataFormats {
-        dataFormat("jackson") {
-            unmarshalType = Map.class
-            prettyPrint = true
-        }
-        dataFormat("my-jackson", JacksonDataFormat) {
-            unmarshalType = String.class
-            prettyPrint = false
+    path("/my/path") {
+        get("/get") {
+            id("routes-with-rest-get")
+            produces("text/plain")
+            to("direct:get")
         }
     }
+
+    post {
+        id("routes-with-rest-post")
+        path("/post")
+        consumes("text/plain")
+        produces("text/plain")
+        to("direct:post")
+    }
 }
 
+from('direct:get')
+    .id("routes-with-rest-dsl-get")
+    .transform().constant("Hello World")
+from('direct:post')
+    .id("routes-with-rest-dsl-post")
+    .setBody().simple('Hello ${body}')
 
-from('timer:tick')
-    .id('routes-with-dataformats-configuration')
-    .to('log:info')
+from("direct:routes-with-rest")
+    .id("routes-with-rest")
+    .setHeader("AnotherHeader", constant("AnotherHeaderValue"))
+    .filter().simple('${header.AnotherHeader} == "AnotherHeaderValue"')
+    .setBody().constant("true")
\ No newline at end of file
diff --git a/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java b/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java
index 87e065f256..fdc6a4faf4 100644
--- a/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java
+++ b/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java
@@ -54,6 +54,26 @@ class GroovyDslTest {
                 .then()
                 .statusCode(200)
                 .body(CoreMatchers.is(
-                        "my-groovy-route,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration"));
+                        "my-groovy-route,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration,routes-with-rest,routes-with-rest-dsl-get,routes-with-rest-dsl-post,routes-with-rest-get,routes-with-rest-post"));
+        RestAssured.given()
+                .get("/groovy-dsl/main/successful/routes")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("5"));
+    }
+
+    @Test
+    void testRestEndpoints() {
+        RestAssured.given()
+                .get("/root/my/path/get")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("Hello World"));
+        RestAssured.given()
+                .body("Will")
+                .post("/root/post")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("Hello Will"));
     }
 }