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

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

commit 9df42b19ee5fbab3d54c14843ef48b4bacc1db7c
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jul 14 10:14:02 2025 +0200

    CAMEL-22214: camel-groovy - Allow to pre-load groovy source files for 
shared functions and DTOs
---
 .../org/apache/camel/groovy-script-compiler        |  2 +
 ...piler.java => DefaultGroovyScriptCompiler.java} | 44 ++++++++++++++++------
 ...lerTest.java => DefaultGroovyCompilerTest.java} |  8 ++--
 .../processor/groovy/GroovyCompilerRouteTest.java  |  6 +--
 .../org/apache/camel/spi/GroovyScriptCompiler.java | 40 ++++++++++++++++++++
 .../camel/impl/engine/AbstractCamelContext.java    |  4 ++
 .../camel/impl/engine/SimpleCamelContext.java      | 15 ++++++++
 .../MainConfigurationPropertiesConfigurer.java     |  7 ++++
 .../camel-main-configuration-metadata.json         |  1 +
 core/camel-main/src/main/docs/main.adoc            |  3 +-
 .../camel/main/DefaultConfigurationConfigurer.java |  6 +++
 .../camel/main/DefaultConfigurationProperties.java | 38 +++++++++++++++----
 12 files changed, 147 insertions(+), 27 deletions(-)

diff --git 
a/components/camel-groovy/src/generated/resources/META-INF/services/org/apache/camel/groovy-script-compiler
 
b/components/camel-groovy/src/generated/resources/META-INF/services/org/apache/camel/groovy-script-compiler
new file mode 100644
index 00000000000..a6b3fe772ca
--- /dev/null
+++ 
b/components/camel-groovy/src/generated/resources/META-INF/services/org/apache/camel/groovy-script-compiler
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.language.groovy.DefaultGroovyScriptCompiler
diff --git 
a/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyScriptCompiler.java
 
b/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/DefaultGroovyScriptCompiler.java
similarity index 69%
rename from 
components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyScriptCompiler.java
rename to 
components/camel-groovy/src/main/java/org/apache/camel/language/groovy/DefaultGroovyScriptCompiler.java
index 56c1b6190b4..659eb7f97ff 100644
--- 
a/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyScriptCompiler.java
+++ 
b/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/DefaultGroovyScriptCompiler.java
@@ -23,19 +23,29 @@ import java.util.List;
 import groovy.lang.GroovyShell;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
+import org.apache.camel.StaticService;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.spi.GroovyScriptCompiler;
+import org.apache.camel.spi.annotations.JdkService;
 import org.apache.camel.support.service.ServiceSupport;
 import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StopWatch;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class GroovyScriptCompiler extends ServiceSupport implements 
CamelContextAware {
+@JdkService(GroovyScriptCompiler.FACTORY)
+@ManagedResource(description = "Managed GroovyScriptCompiler")
+public class DefaultGroovyScriptCompiler extends ServiceSupport
+        implements CamelContextAware, GroovyScriptCompiler, StaticService {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(GroovyScriptCompiler.class);
+    private static final Logger LOG = 
LoggerFactory.getLogger(DefaultGroovyScriptCompiler.class);
 
+    private long elapsed;
     private GroovyScriptClassLoader classLoader;
     private CamelContext camelContext;
-    private String folder;
+    private String scriptPattern;
 
     @Override
     public CamelContext getCamelContext() {
@@ -47,12 +57,20 @@ public class GroovyScriptCompiler extends ServiceSupport 
implements CamelContext
         this.camelContext = camelContext;
     }
 
-    public String getFolder() {
-        return folder;
+    @ManagedAttribute(description = "Total compilation time in millis")
+    public long getCompileTime() {
+        return elapsed;
     }
 
-    public void setFolder(String folder) {
-        this.folder = folder;
+    @ManagedAttribute(description = "Directories to scan for groovy source to 
be pre-compiled")
+    @Override
+    public String getScriptPattern() {
+        return scriptPattern;
+    }
+
+    @Override
+    public void setScriptPattern(String scriptPattern) {
+        this.scriptPattern = scriptPattern;
     }
 
     /**
@@ -74,8 +92,11 @@ public class GroovyScriptCompiler extends ServiceSupport 
implements CamelContext
     protected void doStart() throws Exception {
         super.doStart();
 
-        if (folder != null) {
-            LOG.info("Pre compiling groovy scripts from: {}", folder);
+        if (scriptPattern != null) {
+            StopWatch watch = new StopWatch();
+
+            // TODO: ant path style
+            LOG.info("Pre compiling groovy scripts from: {}", scriptPattern);
 
             ClassLoader cl = camelContext.getApplicationContextClassLoader();
             if (cl == null) {
@@ -88,12 +109,12 @@ public class GroovyScriptCompiler extends ServiceSupport 
implements CamelContext
             
camelContext.getCamelContextExtension().addContextPlugin(GroovyScriptClassLoader.class,
 classLoader);
 
             CompilerConfiguration cc = new CompilerConfiguration();
-            cc.setClasspathList(List.of(folder));
+            cc.setClasspathList(List.of(scriptPattern));
 
             GroovyShell shell = new GroovyShell(cl, cc);
 
             // discover each class from the folder
-            File[] files = new File(folder).listFiles();
+            File[] files = new File(scriptPattern).listFiles();
             if (files != null) {
                 for (File f : files) {
                     String code = IOHelper.loadText(new FileInputStream(f));
@@ -103,6 +124,7 @@ public class GroovyScriptCompiler extends ServiceSupport 
implements CamelContext
                     }
                 }
             }
+            elapsed = watch.taken();
         }
     }
 
diff --git 
a/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerTest.java
 
b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/DefaultGroovyCompilerTest.java
similarity index 84%
rename from 
components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerTest.java
rename to 
components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/DefaultGroovyCompilerTest.java
index d3f74cdc11b..dbbdab88a49 100644
--- 
a/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerTest.java
+++ 
b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/DefaultGroovyCompilerTest.java
@@ -18,19 +18,19 @@ package org.apache.camel.processor.groovy;
 
 import java.lang.reflect.Method;
 
-import org.apache.camel.language.groovy.GroovyScriptCompiler;
+import org.apache.camel.language.groovy.DefaultGroovyScriptCompiler;
 import org.apache.camel.support.ObjectHelper;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-public class GroovyCompilerTest extends CamelTestSupport {
+public class DefaultGroovyCompilerTest extends CamelTestSupport {
 
     @Test
     public void testCompiler() throws Exception {
-        GroovyScriptCompiler compiler = new GroovyScriptCompiler();
+        DefaultGroovyScriptCompiler compiler = new 
DefaultGroovyScriptCompiler();
         compiler.setCamelContext(context);
-        compiler.setFolder("src/test/resources/myscript");
+        compiler.setScriptPattern("src/test/resources/myscript");
         compiler.start();
 
         Class<?> clazz = compiler.loadClass("Dude");
diff --git 
a/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerRouteTest.java
 
b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerRouteTest.java
index 7dcdb079522..e7a7a270d68 100644
--- 
a/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerRouteTest.java
+++ 
b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/GroovyCompilerRouteTest.java
@@ -20,7 +20,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.language.groovy.GroovyScriptCompiler;
+import org.apache.camel.language.groovy.DefaultGroovyScriptCompiler;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 
@@ -30,9 +30,9 @@ public class GroovyCompilerRouteTest extends CamelTestSupport 
{
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
 
-        GroovyScriptCompiler compiler = new GroovyScriptCompiler();
+        DefaultGroovyScriptCompiler compiler = new 
DefaultGroovyScriptCompiler();
         compiler.setCamelContext(context);
-        compiler.setFolder("src/test/resources/myscript");
+        compiler.setScriptPattern("src/test/resources/myscript");
         context.addService(compiler);
 
         return context;
diff --git 
a/core/camel-api/src/main/java/org/apache/camel/spi/GroovyScriptCompiler.java 
b/core/camel-api/src/main/java/org/apache/camel/spi/GroovyScriptCompiler.java
new file mode 100644
index 00000000000..bcbfc261859
--- /dev/null
+++ 
b/core/camel-api/src/main/java/org/apache/camel/spi/GroovyScriptCompiler.java
@@ -0,0 +1,40 @@
+/*
+ * 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.spi;
+
+/**
+ * To let camel-groovy pre-compile script files during bootstrap.
+ */
+public interface GroovyScriptCompiler {
+
+    /**
+     * Service factory key.
+     */
+    String FACTORY = "groovy-script-compiler";
+
+    /**
+     * Directories to scan for groovy source to be pre-compiled. The 
directories are using Ant-path style pattern, and
+     * multiple directories can be specified separated by comma.
+     */
+    void setScriptPattern(String scriptPattern);
+
+    /**
+     * Directories to scan for groovy source to be pre-compiled. The 
directories are using Ant-path style pattern, and
+     * multiple directories can be specified separated by comma.
+     */
+    String getScriptPattern();
+}
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 072d1775448..e696ca0e69a 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -120,6 +120,7 @@ import org.apache.camel.spi.ExchangeFactoryManager;
 import org.apache.camel.spi.ExecutorServiceManager;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;
+import org.apache.camel.spi.GroovyScriptCompiler;
 import org.apache.camel.spi.HeadersMapFactory;
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.Injector;
@@ -387,6 +388,7 @@ public abstract class AbstractCamelContext extends 
BaseService
                 this::createAnnotationBasedProcessorFactory);
         camelContextExtension.lazyAddContextPlugin(DumpRoutesStrategy.class, 
this::createDumpRoutesStrategy);
         camelContextExtension.lazyAddContextPlugin(BackOffTimerFactory.class, 
this::createBackOffTimerFactory);
+        camelContextExtension.lazyAddContextPlugin(GroovyScriptCompiler.class, 
this::createGroovyScriptCompiler);
     }
 
     protected static <T> T lookup(CamelContext context, String ref, Class<T> 
type) {
@@ -4301,6 +4303,8 @@ public abstract class AbstractCamelContext extends 
BaseService
 
     protected abstract HeadersMapFactory createHeadersMapFactory();
 
+    protected abstract GroovyScriptCompiler createGroovyScriptCompiler();
+
     protected abstract BeanProxyFactory createBeanProxyFactory();
 
     protected abstract AnnotationBasedProcessorFactory 
createAnnotationBasedProcessorFactory();
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
index 5c7237038bd..45fc96b0158 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
@@ -56,6 +56,7 @@ import org.apache.camel.spi.ExchangeFactoryManager;
 import org.apache.camel.spi.ExecutorServiceManager;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;
+import org.apache.camel.spi.GroovyScriptCompiler;
 import org.apache.camel.spi.HeadersMapFactory;
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.Injector;
@@ -473,6 +474,20 @@ public class SimpleCamelContext extends 
AbstractCamelContext {
         return result.orElseGet(DefaultHeadersMapFactory::new);
     }
 
+    @Override
+    protected GroovyScriptCompiler createGroovyScriptCompiler() {
+        Optional<GroovyScriptCompiler> result = ResolverHelper.resolveService(
+                getCamelContextReference(),
+                getCamelContextExtension().getBootstrapFactoryFinder(),
+                GroovyScriptCompiler.FACTORY,
+                GroovyScriptCompiler.class);
+        if (result.isPresent()) {
+            return result.get();
+        } else {
+            throw new IllegalArgumentException("Cannot find 
GroovyScriptCompiler on classpath. Add camel-groovy to classpath.");
+        }
+    }
+
     private CliConnectorFactory createCliConnectorFactory() {
         // lookup in registry first
         CliConnectorFactory ccf = 
getCamelContextReference().getRegistry().findSingleByType(CliConnectorFactory.class);
diff --git 
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
 
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index 1a7ccf5dbe0..02687bf7ddf 100644
--- 
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++ 
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -67,6 +67,7 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         map.put("ExtraShutdownTimeout", int.class);
         map.put("FileConfigurations", java.lang.String.class);
         map.put("GlobalOptions", java.util.Map.class);
+        map.put("GroovyScriptPattern", java.lang.String.class);
         map.put("InflightRepositoryBrowseEnabled", boolean.class);
         map.put("JavaRoutesExcludePattern", java.lang.String.class);
         map.put("JavaRoutesIncludePattern", java.lang.String.class);
@@ -239,6 +240,8 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         case "fileConfigurations": 
target.setFileConfigurations(property(camelContext, java.lang.String.class, 
value)); return true;
         case "globaloptions":
         case "globalOptions": target.setGlobalOptions(property(camelContext, 
java.util.Map.class, value)); return true;
+        case "groovyscriptpattern":
+        case "groovyScriptPattern": 
target.setGroovyScriptPattern(property(camelContext, java.lang.String.class, 
value)); return true;
         case "inflightrepositorybrowseenabled":
         case "inflightRepositoryBrowseEnabled": 
target.setInflightRepositoryBrowseEnabled(property(camelContext, boolean.class, 
value)); return true;
         case "javaroutesexcludepattern":
@@ -489,6 +492,8 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         case "fileConfigurations": return java.lang.String.class;
         case "globaloptions":
         case "globalOptions": return java.util.Map.class;
+        case "groovyscriptpattern":
+        case "groovyScriptPattern": return java.lang.String.class;
         case "inflightrepositorybrowseenabled":
         case "inflightRepositoryBrowseEnabled": return boolean.class;
         case "javaroutesexcludepattern":
@@ -735,6 +740,8 @@ public class MainConfigurationPropertiesConfigurer extends 
org.apache.camel.supp
         case "fileConfigurations": return target.getFileConfigurations();
         case "globaloptions":
         case "globalOptions": return target.getGlobalOptions();
+        case "groovyscriptpattern":
+        case "groovyScriptPattern": return target.getGroovyScriptPattern();
         case "inflightrepositorybrowseenabled":
         case "inflightRepositoryBrowseEnabled": return 
target.isInflightRepositoryBrowseEnabled();
         case "javaroutesexcludepattern":
diff --git 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index ecd123e7a0b..d01b20ce547 100644
--- 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -72,6 +72,7 @@
     { "name": "camel.main.extraShutdownTimeout", "description": "Extra timeout 
in seconds to graceful shutdown Camel. When Camel is shutting down then Camel 
first shutdown all the routes (shutdownTimeout). Then additional services is 
shutdown (extraShutdownTimeout).", "sourceType": 
"org.apache.camel.main.MainConfigurationProperties", "type": "integer", 
"javaType": "int", "defaultValue": 15 },
     { "name": "camel.main.fileConfigurations", "description": "Directory to 
load additional configuration files that contains configuration values that 
takes precedence over any other configuration. This can be used to refer to 
files that may have secret configuration that has been mounted on the file 
system for containers. You can specify a pattern to load from sub directories 
and a name pattern such as \/var\/app\/secret\/.properties, multiple 
directories can be separated by comma.", " [...]
     { "name": "camel.main.globalOptions", "description": "Sets global options 
that can be referenced in the camel context Important: This has nothing to do 
with property placeholders, and is just a plain set of key\/value pairs which 
are used to configure global options on CamelContext, such as a maximum debug 
logging length etc.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "object", 
"javaType": "java.util.Map" },
+    { "name": "camel.main.groovyScriptPattern", "description": "Directories to 
scan for groovy source to be pre-compiled. The directories are using Ant-path 
style pattern, and multiple directories can be specified separated by comma.", 
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": 
"string", "javaType": "java.lang.String" },
     { "name": "camel.main.inflightRepositoryBrowseEnabled", "description": 
"Sets whether the inflight repository should allow browsing each inflight 
exchange. This is by default disabled as there is a very slight performance 
overhead when enabled.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.javaRoutesExcludePattern", "description": "Used for 
exclusive filtering RouteBuilder classes which are collected from the registry 
or via classpath scanning. The exclusive filtering takes precedence over 
inclusive filtering. The pattern is using Ant-path style pattern. Multiple 
patterns can be specified separated by comma. For example to exclude all 
classes starting with Bar use: &#42;&#42;\/Bar&#42; To exclude all routes form 
a specific package use: com\/mycomp [...]
     { "name": "camel.main.javaRoutesIncludePattern", "description": "Used for 
inclusive filtering RouteBuilder classes which are collected from the registry 
or via classpath scanning. The exclusive filtering takes precedence over 
inclusive filtering. The pattern is using Ant-path style pattern. Multiple 
patterns can be specified separated by comma. Multiple patterns can be 
specified separated by comma. For example to include all classes starting with 
Foo use: &#42;&#42;\/Foo To include a [...]
diff --git a/core/camel-main/src/main/docs/main.adoc 
b/core/camel-main/src/main/docs/main.adoc
index dde170b84a0..8c1452e51ee 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -19,7 +19,7 @@ The following tables lists all the options:
 
 // main options: START
 === Camel Main configurations
-The camel.main supports 122 options, which are listed below.
+The camel.main supports 123 options, which are listed below.
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -69,6 +69,7 @@ The camel.main supports 122 options, which are listed below.
 | *camel.main.extraShutdown{zwsp}Timeout* | Extra timeout in seconds to 
graceful shutdown Camel. When Camel is shutting down then Camel first shutdown 
all the routes (shutdownTimeout). Then additional services is shutdown 
(extraShutdownTimeout). | 15 | int
 | *camel.main.fileConfigurations* | Directory to load additional configuration 
files that contains configuration values that takes precedence over any other 
configuration. This can be used to refer to files that may have secret 
configuration that has been mounted on the file system for containers. You can 
specify a pattern to load from sub directories and a name pattern such as 
/var/app/secret/.properties, multiple directories can be separated by comma. |  
| String
 | *camel.main.globalOptions* | Sets global options that can be referenced in 
the camel context Important: This has nothing to do with property placeholders, 
and is just a plain set of key/value pairs which are used to configure global 
options on CamelContext, such as a maximum debug logging length etc. |  | Map
+| *camel.main.groovyScriptPattern* | Directories to scan for groovy source to 
be pre-compiled. The directories are using Ant-path style pattern, and multiple 
directories can be specified separated by comma. |  | String
 | *camel.main.inflightRepository{zwsp}BrowseEnabled* | Sets whether the 
inflight repository should allow browsing each inflight exchange. This is by 
default disabled as there is a very slight performance overhead when enabled. | 
false | boolean
 | *camel.main.javaRoutesExclude{zwsp}Pattern* | Used for exclusive filtering 
RouteBuilder classes which are collected from the registry or via classpath 
scanning. The exclusive filtering takes precedence over inclusive filtering. 
The pattern is using Ant-path style pattern. Multiple patterns can be specified 
separated by comma. For example to exclude all classes starting with Bar use: 
&#42;&#42;/Bar&#42; To exclude all routes form a specific package use: 
com/mycompany/bar/&#42; To exclud [...]
 | *camel.main.javaRoutesInclude{zwsp}Pattern* | Used for inclusive filtering 
RouteBuilder classes which are collected from the registry or via classpath 
scanning. The exclusive filtering takes precedence over inclusive filtering. 
The pattern is using Ant-path style pattern. Multiple patterns can be specified 
separated by comma. Multiple patterns can be specified separated by comma. For 
example to include all classes starting with Foo use: &#42;&#42;/Foo To include 
all routes form a speci [...]
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index d1dee0fb9dd..66381be9c6f 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -61,6 +61,7 @@ import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.ExchangeFactory;
 import org.apache.camel.spi.ExecutorServiceManager;
 import org.apache.camel.spi.FactoryFinderResolver;
+import org.apache.camel.spi.GroovyScriptCompiler;
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.LifecycleStrategy;
@@ -287,6 +288,11 @@ public final class DefaultConfigurationConfigurer {
             ContextReloadStrategy reloader = new 
DefaultContextReloadStrategy();
             camelContext.addService(reloader);
         }
+        if (config.getGroovyScriptPattern() != null) {
+            GroovyScriptCompiler gsc = 
camelContext.getCamelContextExtension().getContextPlugin(GroovyScriptCompiler.class);
+            gsc.setScriptPattern(config.getGroovyScriptPattern());
+            camelContext.addService(gsc);
+        }
 
         if (camelContext.getManagementStrategy().getManagementAgent() != null) 
{
             camelContext.getManagementStrategy().getManagementAgent()
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index d3658ccef79..1228a4f3fd9 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -129,6 +129,7 @@ public abstract class DefaultConfigurationProperties<T> {
     @Metadata(defaultValue = "true")
     private boolean routesReloadRemoveAllRoutes = true;
     private boolean routesReloadRestartDuration;
+    private String groovyScriptPattern;
     @Metadata(defaultValue = "default", enums = "default,prototype,pooled")
     private String exchangeFactory = "default";
     private int exchangeFactoryCapacity = 100;
@@ -1394,6 +1395,18 @@ public abstract class DefaultConfigurationProperties<T> {
         this.jmxUpdateRouteEnabled = jmxUpdateRouteEnabled;
     }
 
+    public String getGroovyScriptPattern() {
+        return groovyScriptPattern;
+    }
+
+    /**
+     * Directories to scan for groovy source to be pre-compiled. The 
directories are using Ant-path style pattern, and
+     * multiple directories can be specified separated by comma.
+     */
+    public void setGroovyScriptPattern(String groovyScriptPattern) {
+        this.groovyScriptPattern = groovyScriptPattern;
+    }
+
     public String getExchangeFactory() {
         return exchangeFactory;
     }
@@ -1634,6 +1647,18 @@ public abstract class DefaultConfigurationProperties<T> {
         this.startupRecorderDir = startupRecorderDir;
     }
 
+    public String getCloudPropertiesLocation() {
+        return cloudPropertiesLocation;
+    }
+
+    /**
+     * Sets the locations (comma separated values) where to find properties 
configuration as defined for cloud native
+     * environments such as Kubernetes. You should only scan text based 
mounted configuration.
+     */
+    public void setCloudPropertiesLocation(String cloudPropertiesLocation) {
+        this.cloudPropertiesLocation = cloudPropertiesLocation;
+    }
+
     // fluent builders
     // --------------------------------------------------------------
 
@@ -2756,16 +2781,13 @@ public abstract class DefaultConfigurationProperties<T> 
{
         return (T) this;
     }
 
-    public String getCloudPropertiesLocation() {
-        return cloudPropertiesLocation;
-    }
-
     /**
-     * Sets the locations (comma separated values) where to find properties 
configuration as defined for cloud native
-     * environments such as Kubernetes. You should only scan text based 
mounted configuration.
+     * Directories to scan for groovy source to be pre-compiled. The 
directories are using Ant-path style pattern, and
+     * multiple directories can be specified separated by comma.
      */
-    public void setCloudPropertiesLocation(String cloudPropertiesLocation) {
-        this.cloudPropertiesLocation = cloudPropertiesLocation;
+    public T withGroovyScriptPattern(String groovyScriptPattern) {
+        this.groovyScriptPattern = groovyScriptPattern;
+        return (T) this;
     }
 
     /**

Reply via email to