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

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new e24cf14  groovy dsl: use application contect class loader or tccl as 
parent classloader for GroovyShell
e24cf14 is described below

commit e24cf14dcc7fb9a91f6a60343e9b24f128f55d5c
Author: Luca Burgazzoli <[email protected]>
AuthorDate: Mon Mar 29 19:18:35 2021 +0200

    groovy dsl: use application contect class loader or tccl as parent 
classloader for GroovyShell
---
 .../dsl/groovy/GroovyRoutesBuilderLoader.groovy    | 39 +++++--------------
 .../dsl/groovy/GroovyRoutesBuilderSupport.groovy   | 44 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 29 deletions(-)

diff --git 
a/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderLoader.groovy
 
b/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderLoader.groovy
index e27a10f..2ad2a05 100644
--- 
a/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderLoader.groovy
+++ 
b/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderLoader.groovy
@@ -27,61 +27,42 @@ import org.apache.camel.spi.Resource
 import org.apache.camel.spi.StartupStepRecorder
 import org.apache.camel.spi.annotations.RoutesLoader
 import org.apache.camel.support.RoutesBuilderLoaderSupport
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.control.customizers.ImportCustomizer
 
 @Experimental
 @ManagedResource(description = "Managed GroovyRoutesBuilderLoader")
 @RoutesLoader(EXTENSION)
 class GroovyRoutesBuilderLoader  extends RoutesBuilderLoaderSupport {
-    public static final String EXTENSION = "groovy";
+    public static final String EXTENSION = "groovy"
 
-    private StartupStepRecorder recorder;
+    private StartupStepRecorder recorder
 
     @Override
     protected void doBuild() throws Exception {
-        super.doBuild();
+        super.doBuild()
 
         if (getCamelContext() != null) {
-            this.recorder = 
getCamelContext().adapt(ExtendedCamelContext.class).getStartupStepRecorder();
+            this.recorder = 
getCamelContext().adapt(ExtendedCamelContext.class).getStartupStepRecorder()
         }
     }
 
     @ManagedAttribute(description = "Supported file extension")
     @Override
-    public String getSupportedExtension() {
-        return EXTENSION;
+    String getSupportedExtension() {
+        return EXTENSION
     }
 
     @Override
-    public RoutesBuilder loadRoutesBuilder(Resource resource) throws Exception 
{
+    RoutesBuilder loadRoutesBuilder(Resource resource) throws Exception {
         StartupStep step = recorder != null
                 ? recorder.beginStep(GroovyRoutesBuilderLoader.class, 
resource.getLocation(), "Compiling RouteBuilder")
-                : null;
+                : null
 
         try {
-            return EndpointRouteBuilder.loadEndpointRoutesBuilder(resource, 
this::load);
+            return EndpointRouteBuilder.loadEndpointRoutesBuilder(resource, 
GroovyRoutesBuilderSupport::load)
         } finally {
             if (recorder != null) {
-                recorder.endStep(step);
+                recorder.endStep(step)
             }
         }
     }
-
-    private void load(Reader reader, EndpointRouteBuilder builder) {
-        def ic = new ImportCustomizer()
-        ic.addStarImports('org.apache.camel')
-        ic.addStarImports('org.apache.camel.spi')
-
-        def cc = new CompilerConfiguration()
-        cc.addCompilationCustomizers(ic)
-        cc.setScriptBaseClass(DelegatingScript.class.getName())
-
-        def sh = new GroovyShell(new Binding(), cc)
-        def script = (DelegatingScript) sh.parse(reader)
-
-        // set the delegate target
-        script.setDelegate(new GroovyDSL(builder))
-        script.run()
-    }
 }
diff --git 
a/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderSupport.groovy
 
b/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderSupport.groovy
new file mode 100644
index 0000000..b4e8a4a
--- /dev/null
+++ 
b/dsl/camel-groovy-dsl/src/main/groovy/org/apache/camel/dsl/groovy/GroovyRoutesBuilderSupport.groovy
@@ -0,0 +1,44 @@
+/*
+ * 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.dsl.groovy
+
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ImportCustomizer
+
+class GroovyRoutesBuilderSupport {
+    private GroovyRoutesBuilderSupport() {
+    }
+
+    static void load(Reader reader, EndpointRouteBuilder builder) {
+        def ic = new ImportCustomizer()
+        ic.addStarImports('org.apache.camel')
+        ic.addStarImports('org.apache.camel.spi')
+
+        def cc = new CompilerConfiguration()
+        cc.addCompilationCustomizers(ic)
+        cc.setScriptBaseClass(DelegatingScript.class.getName())
+
+        def cl = builder.context.applicationContextClassLoader ?: 
Thread.currentThread().getContextClassLoader()
+        def sh = new GroovyShell(cl, new Binding(), cc)
+        def script = (DelegatingScript) sh.parse(reader)
+
+        // set the delegate target
+        script.setDelegate(new GroovyDSL(builder))
+        script.run()
+    }
+}

Reply via email to