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 fc2a4df2e076 CAMEL-25186: camel-jbang - Export should resolve the 
delegate endpoint of a master: endpoint (#28370)
fc2a4df2e076 is described below

commit fc2a4df2e076d96b6c2c15c6051aef532a106045
Author: Serdar Gökay <[email protected]>
AuthorDate: Sat Oct 24 16:51:20 2026 +0300

    CAMEL-25186: camel-jbang - Export should resolve the delegate endpoint of a 
master: endpoint (#28370)
    
    Co-authored-by: Claude Fable 5.1 <[email protected]>
---
 .../camel/dsl/jbang/core/commands/ExportTest.java  | 30 ++++++++++++++++++++++
 .../src/test/resources/master-route.yaml           | 22 ++++++++++++++++
 .../java/org/apache/camel/main/KameletMain.java    |  2 +-
 .../main/download/DownloadEndpointStrategy.java    | 23 ++++++++++++++++-
 4 files changed, 75 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
index b956f3a79269..b005981a471d 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
@@ -767,6 +767,36 @@ class ExportTest {
         }
     }
 
+    @ParameterizedTest
+    @MethodSource("runtimeProvider")
+    public void shouldExportMasterDelegate(RuntimeType rt) throws Exception {
+        LOG.info("shouldExportMasterDelegate {}", rt);
+        Export command = createCommand(rt, new String[] { 
"src/test/resources/master-route.yaml" },
+                "--gav=examples:route:1.0.0", "--dir=" + workingDir, 
"--quiet");
+        int exit = command.doCall();
+
+        Assertions.assertEquals(0, exit);
+        Model model = readMavenModel();
+
+        // the delegate component of the master endpoint must be exported as 
well (CAMEL-25186)
+        if (rt == RuntimeType.main) {
+            Assertions.assertTrue(containsDependency(model.getDependencies(), 
"org.apache.camel", "camel-master", null));
+            Assertions.assertTrue(containsDependency(model.getDependencies(), 
"org.apache.camel", "camel-timer", null));
+        } else if (rt == RuntimeType.springBoot) {
+            Assertions.assertTrue(
+                    containsDependency(model.getDependencies(), 
"org.apache.camel.springboot", "camel-master-starter",
+                            null));
+            Assertions.assertTrue(
+                    containsDependency(model.getDependencies(), 
"org.apache.camel.springboot", "camel-timer-starter",
+                            null));
+        } else if (rt == RuntimeType.quarkus) {
+            Assertions.assertTrue(
+                    containsDependency(model.getDependencies(), 
"org.apache.camel.quarkus", "camel-quarkus-master", null));
+            Assertions.assertTrue(
+                    containsDependency(model.getDependencies(), 
"org.apache.camel.quarkus", "camel-quarkus-timer", null));
+        }
+    }
+
     @ParameterizedTest
     @MethodSource("runtimeProvider")
     public void shouldExportCircuitBreaker(RuntimeType rt) throws Exception {
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/master-route.yaml 
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/master-route.yaml
new file mode 100644
index 000000000000..fac9d343db38
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/master-route.yaml
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+- route:
+    from:
+      uri: master:lock:timer:tick?period=1000
+      steps:
+        - log: "tick"
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 165122225fe9..7e25887ac230 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
@@ -723,7 +723,7 @@ public class KameletMain extends MainCommandLineSupport {
                     ff, answer, 
Optional.ofNullable(camelVersion).map(Object::toString).orElse(null), export);
             
answer.getCamelContextExtension().addContextPlugin(PeriodTaskResolver.class, 
ptr);
 
-            answer.getCamelContextExtension().registerEndpointCallback(new 
DownloadEndpointStrategy(answer, silent));
+            answer.getCamelContextExtension().registerEndpointCallback(new 
DownloadEndpointStrategy(answer, export));
             
answer.getCamelContextExtension().addContextPlugin(ComponentResolver.class,
                     new DependencyDownloaderComponentResolver(answer, 
stubPattern, silent, transform));
             
answer.getCamelContextExtension().addContextPlugin(DataFormatResolver.class,
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java
index 2fb0559c9ed2..b28a0982cec1 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DownloadEndpointStrategy.java
@@ -18,16 +18,20 @@ package org.apache.camel.main.download;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
+import org.apache.camel.component.stub.StubEndpoint;
 import org.apache.camel.spi.EndpointStrategy;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
 
 public class DownloadEndpointStrategy implements EndpointStrategy {
 
     private final CamelContext camelContext;
+    private final boolean export;
 
-    public DownloadEndpointStrategy(CamelContext camelContext, boolean silent) 
{
+    public DownloadEndpointStrategy(CamelContext camelContext, boolean export) 
{
         this.camelContext = camelContext;
+        this.export = export;
     }
 
     @Override
@@ -44,10 +48,27 @@ public class DownloadEndpointStrategy implements 
EndpointStrategy {
             if (name != null) {
                 camelContext.resolveDataFormat(name);
             }
+        } else if (export && "master".equals(scheme) && endpoint instanceof 
StubEndpoint) {
+            // a stubbed master endpoint does not create its delegate 
endpoint, so resolve it here (CAMEL-25186)
+            String delegateUri = extractDelegateUri(uri);
+            if (delegateUri != null) {
+                camelContext.getEndpoint(delegateUri);
+            }
         }
         return endpoint;
     }
 
+    // extracts the delegate uri the same way as MasterComponent
+    private static String extractDelegateUri(String uri) {
+        String remaining = 
FileUtil.stripLeadingSeparator(StringHelper.after(uri, ":"));
+        String namespace = StringHelper.before(remaining, ":");
+        String delegateUri = StringHelper.after(remaining, ":");
+        if (ObjectHelper.isEmpty(namespace) || 
ObjectHelper.isEmpty(delegateUri)) {
+            return null;
+        }
+        return delegateUri;
+    }
+
     private static String extractName(String uri) {
         uri = StringHelper.before(uri, "?", uri);
         int count = StringHelper.countChar(uri, ':');

Reply via email to