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

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


The following commit(s) were added to refs/heads/main by this push:
     new 5f846bf64c9 CAMEL-20994: camel-jbang - Do not include rest component 
if not in use.
5f846bf64c9 is described below

commit 5f846bf64c994acc07e173e50e2857295e610e0e
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Aug 7 14:39:28 2024 +0200

    CAMEL-20994: camel-jbang - Do not include rest component if not in use.
---
 .../main/java/org/apache/camel/main/BaseMainSupport.java    | 13 +++++++++----
 .../src/main/java/org/apache/camel/main/KameletMain.java    | 11 ++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 0c7a65ee592..a644305701a 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -2085,17 +2085,24 @@ public abstract class BaseMainSupport extends 
BaseService {
 
         for (String key : prop.stringPropertyNames()) {
             computeProperties("camel.component.", key, prop, properties, name 
-> {
+                boolean optional = name.startsWith("?");
+                if (optional) {
+                    name = name.substring(1);
+                }
                 if (reload) {
                     // force re-creating component on reload
                     camelContext.removeComponent(name);
                 }
                 // its an existing component name
-                Component target = camelContext.getComponent(name);
-                if (target == null) {
+                Component target = optional ? camelContext.hasComponent(name) 
: camelContext.getComponent(name);
+                if (target == null && !optional) {
                     throw new IllegalArgumentException(
                             "Error configuring property: " + key + " because 
cannot find component with name " + name
                                                        + ". Make sure you have 
the component on the classpath");
                 }
+                if (target == null) {
+                    return Collections.EMPTY_LIST;
+                }
                 return Collections.singleton(target);
             });
             computeProperties("camel.dataformat.", key, prop, properties, name 
-> {
@@ -2105,7 +2112,6 @@ public abstract class BaseMainSupport extends BaseService 
{
                             "Error configuring property: " + key + " because 
cannot find dataformat with name " + name
                                                        + ". Make sure you have 
the dataformat on the classpath");
                 }
-
                 return Collections.singleton(target);
             });
             computeProperties("camel.language.", key, prop, properties, name 
-> {
@@ -2117,7 +2123,6 @@ public abstract class BaseMainSupport extends BaseService 
{
                             "Error configuring property: " + key + " because 
cannot find language with name " + name
                                                        + ". Make sure you have 
the language on the classpath");
                 }
-
                 return Collections.singleton(target);
             });
         }
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index bb821d240d3..3536430974a 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -789,12 +789,13 @@ public class KameletMain extends MainCommandLineSupport {
      * Sets initial properties that are specific to camel-kamelet-main
      */
     protected void configureInitialProperties(String location) {
-        addInitialProperty("camel.component.kamelet.location", location);
-        addInitialProperty("camel.component.rest-api.consumerComponentName", 
"platform-http");
-        addInitialProperty("camel.component.rest.consumerComponentName", 
"platform-http");
-        addInitialProperty("camel.component.rest.producerComponentName", 
"vertx-http");
+        // optional configuration if these components are in-use
+        addInitialProperty("camel.component.?kamelet.location", location);
+        addInitialProperty("camel.component.?rest-api.consumerComponentName", 
"platform-http");
+        addInitialProperty("camel.component.?rest.consumerComponentName", 
"platform-http");
+        addInitialProperty("camel.component.?rest.producerComponentName", 
"vertx-http");
         // make it easy to load mock-data from file without having to add 
camel-mock to classpath
-        addInitialProperty("camel.component.rest-openapi.mockIncludePattern", 
"file:camel-mock/**,classpath:camel-mock/**");
+        addInitialProperty("camel.component.?rest-openapi.mockIncludePattern", 
"file:camel-mock/**,classpath:camel-mock/**");
     }
 
     protected String startupInfo() {

Reply via email to