You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/12/16 12:59:56 UTC

[camel-k-runtime] branch master updated: groovy: workaround for https://issues.apache.org/jira/browse/CAMEL-14300

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

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git


The following commit(s) were added to refs/heads/master by this push:
     new b1e199a  groovy: workaround for https://issues.apache.org/jira/browse/CAMEL-14300
     new 05528e4  Merge pull request #210 from lburgazzoli/groovy-worakrounds-for-CAMEL-14300
b1e199a is described below

commit b1e199a3e9a0573e019d80292927bf6ba2d34b98
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Dec 16 13:49:01 2019 +0100

    groovy: workaround for https://issues.apache.org/jira/browse/CAMEL-14300
---
 .../extension/ProcessorDefinitionExtensions.groovy | 48 ++++++++++++++++++++++
 .../org.codehaus.groovy.runtime.ExtensionModule    |  6 ++-
 .../k/loader/groovy/dsl/IntegrationTest.groovy     | 16 ++++++--
 .../src/test/resources/routes-with-eip.groovy      | 23 +++++++++++
 4 files changed, 88 insertions(+), 5 deletions(-)

diff --git a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/extension/ProcessorDefinitionExtensions.groovy b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/extension/ProcessorDefinitionExtensions.groovy
new file mode 100644
index 0000000..8a514cb
--- /dev/null
+++ b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/extension/ProcessorDefinitionExtensions.groovy
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.camel.k.loader.groovy.extension
+
+import org.apache.camel.Processor;
+
+import java.util.function.Function;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.model.ProcessorDefinition;
+
+// Workaround for https://issues.apache.org/jira/browse/CAMEL-14300
+// TODO: remove once fixed on camel side
+class ProcessorDefinitionExtensions {
+    static <T extends ProcessorDefinition<T>> T setBody(ProcessorDefinition<T> self, Closure<?> callable) {
+        return self.setBody(new Function<Exchange, Object>() {
+            @Override
+            Object apply(Exchange exchange) {
+                callable.resolveStrategy = Closure.DELEGATE_ONLY
+                return callable.call(exchange)
+            }
+        });
+    }
+
+    static <T extends ProcessorDefinition<T>> T process(ProcessorDefinition<T> self, Closure<?> callable) {
+        return self.process(new Processor() {
+            @Override
+            void process(Exchange exchange) throws Exception {
+                callable.resolveStrategy = Closure.DELEGATE_ONLY
+                callable.call(exchange)
+            }
+        });
+    }
+}
diff --git a/camel-k-loader-groovy/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule b/camel-k-loader-groovy/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
index bc78fb3..d0e5874 100644
--- a/camel-k-loader-groovy/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
+++ b/camel-k-loader-groovy/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
@@ -1,4 +1,6 @@
 moduleName=camel-k-loader-groovy
 moduleVersion=1.0.0
-extensionClasses=org.apache.camel.k.loader.groovy.extension.LogComponentExtension,org.apache.camel.k.loader.groovy.extension.ExpressionClauseExtensions
-#staticExtensionClasses=support.StaticStringExtension
\ No newline at end of file
+extensionClasses=\
+  org.apache.camel.k.loader.groovy.extension.LogComponentExtension,\
+  org.apache.camel.k.loader.groovy.extension.ExpressionClauseExtensions,\
+  org.apache.camel.k.loader.groovy.extension.ProcessorDefinitionExtensions
diff --git a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy
index 11da9a7..8a53b1e 100644
--- a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy
+++ b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy
@@ -169,10 +169,10 @@ class IntegrationTest extends Specification {
 
     def "load integration with component error method configuration"()  {
         when:
-        forRoutes('classpath:routes-with-component-wrong-method-configuration.groovy').accept(Runtime.Phase.ConfigureRoutes, runtime)
+            forRoutes('classpath:routes-with-component-wrong-method-configuration.groovy').accept(Runtime.Phase.ConfigureRoutes, runtime)
         then:
-        def e =  thrown org.apache.camel.RuntimeCamelException
-        assert e.message.contains("No signature of method: org.apache.camel.component.seda.SedaComponent.queueNumber()")
+            def e =  thrown org.apache.camel.RuntimeCamelException
+            assert e.message.contains("No signature of method: org.apache.camel.component.seda.SedaComponent.queueNumber()")
 
     }
 
@@ -191,5 +191,15 @@ class IntegrationTest extends Specification {
 
             ch.output instanceof SendProcessor
     }
+
+    // Test groovy eip extension, relates to https://issues.apache.org/jira/browse/CAMEL-14300
+    def "load integration with eip"()  {
+        when:
+            forRoutes('classpath:routes-with-eip.groovy').accept(Runtime.Phase.ConfigureRoutes, runtime)
+
+            context.start()
+        then:
+            1 == 1
+    }
 }
 
diff --git a/camel-k-loader-groovy/src/test/resources/routes-with-eip.groovy b/camel-k-loader-groovy/src/test/resources/routes-with-eip.groovy
new file mode 100644
index 0000000..3a4fa07
--- /dev/null
+++ b/camel-k-loader-groovy/src/test/resources/routes-with-eip.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+from("direct:1")
+    .setBody { "" }
+    .transform().body { b -> null}
+    .transform().message { m -> null}
+    .transform().exchange { e -> null}
+    .process {e -> e.in.body = null }