You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/10/27 08:49:11 UTC

[camel] branch camel-3.18.x updated: CAMEL-18657: camel-jbang - Loading dynamic JARs should load EndpointUriFactory

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

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


The following commit(s) were added to refs/heads/camel-3.18.x by this push:
     new 41739eb558d CAMEL-18657: camel-jbang - Loading dynamic JARs should load EndpointUriFactory
41739eb558d is described below

commit 41739eb558dcf801eb0f2101758171a49d932ae9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 27 10:48:02 2022 +0200

    CAMEL-18657: camel-jbang - Loading dynamic JARs should load EndpointUriFactory
---
 .../java/org/apache/camel/main/KameletMain.java    |  2 +
 .../DependencyDownloaderUriFactoryResolver.java    | 44 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

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 4be699c531c..31149f976a6 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
@@ -39,6 +39,7 @@ import org.apache.camel.main.download.DependencyDownloaderPropertyBindingListene
 import org.apache.camel.main.download.DependencyDownloaderResourceLoader;
 import org.apache.camel.main.download.DependencyDownloaderRoutesLoader;
 import org.apache.camel.main.download.DependencyDownloaderStrategy;
+import org.apache.camel.main.download.DependencyDownloaderUriFactoryResolver;
 import org.apache.camel.main.download.DownloadListener;
 import org.apache.camel.main.download.KameletMainInjector;
 import org.apache.camel.main.download.KnownDependenciesResolver;
@@ -364,6 +365,7 @@ public class KameletMain extends MainCommandLineSupport {
                     new DependencyDownloaderStrategy(answer));
             answer.setClassResolver(new DependencyDownloaderClassResolver(answer, known));
             answer.setComponentResolver(new DependencyDownloaderComponentResolver(answer, stub));
+            answer.setUriFactoryResolver(new DependencyDownloaderUriFactoryResolver(answer));
             answer.setDataFormatResolver(new DependencyDownloaderDataFormatResolver(answer));
             answer.setLanguageResolver(new DependencyDownloaderLanguageResolver(answer));
             answer.setResourceLoader(new DependencyDownloaderResourceLoader(answer));
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderUriFactoryResolver.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderUriFactoryResolver.java
new file mode 100644
index 00000000000..8549e12ca63
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderUriFactoryResolver.java
@@ -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.main.download;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.impl.engine.DefaultUriFactoryResolver;
+import org.apache.camel.spi.EndpointUriFactory;
+
+/**
+ * Auto downloaded needed JARs when resolving uri factory.
+ */
+public class DependencyDownloaderUriFactoryResolver extends DefaultUriFactoryResolver {
+
+    public DependencyDownloaderUriFactoryResolver(CamelContext context) {
+        setCamelContext(context);
+    }
+
+    @Override
+    public EndpointUriFactory resolveFactory(String name, CamelContext context) {
+        // need to trigger component resolver that is capable of downloading if needed
+        try {
+            context.adapt(ExtendedCamelContext.class).getComponentResolver().resolveComponent(name, context);
+        } catch (Exception e) {
+            // ignore
+        }
+
+        return super.resolveFactory(name, context);
+    }
+}