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

commit 598b5cf4803d1ef4f839530a987725d505e47985
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Apr 21 11:09:59 2022 +0200

    CAMEL-17998: camel-jbang - Download listener so we can know dependencies 
needed to run
---
 .../org/apache/camel/main/DownloadListener.java    | 26 ++++++++++++++++++++++
 .../org/apache/camel/main/DownloaderHelper.java    |  9 +++++++-
 .../java/org/apache/camel/main/KameletMain.java    | 18 +++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloadListener.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloadListener.java
new file mode 100644
index 00000000000..f0281710677
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloadListener.java
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/**
+ * Listener for downloading a dependency (can be downloaded from a local cache)
+ */
+public interface DownloadListener {
+
+    void onDownloadDependency(String groupId, String artifactId, String 
version);
+
+}
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloaderHelper.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloaderHelper.java
index 444df1fd94b..6ace61173f9 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloaderHelper.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DownloaderHelper.java
@@ -37,6 +37,13 @@ public final class DownloaderHelper {
     }
 
     public static void downloadDependency(CamelContext camelContext, String 
groupId, String artifactId, String version) {
+
+        // trigger listener
+        DownloadListener listener = 
camelContext.getExtension(DownloadListener.class);
+        if (listener != null) {
+            listener.onDownloadDependency(groupId, artifactId, version);
+        }
+
         StopWatch watch = new StopWatch();
         Map<String, Object> map = new HashMap<>();
         map.put("classLoader", 
camelContext.getApplicationContextClassLoader());
@@ -56,7 +63,7 @@ public final class DownloaderHelper {
         if (taken < 1000) {
             LOG.debug(msg);
         } else {
-            LOG.debug(msg);
+            LOG.info(msg);
         }
     }
 
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 b0f50cb8070..896fbdbb2ef 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
@@ -22,6 +22,7 @@ import java.util.Objects;
 
 import groovy.lang.GroovyClassLoader;
 import org.apache.camel.CamelContext;
+import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -38,6 +39,7 @@ public class KameletMain extends MainCommandLineSupport {
     private static ClassLoader kameletClassLoader;
     protected final MainRegistry registry = new MainRegistry();
     private boolean download = true;
+    private DownloadListener downloadListener;
 
     public KameletMain() {
         configureInitialProperties(DEFAULT_KAMELETS_LOCATION);
@@ -113,6 +115,17 @@ public class KameletMain extends MainCommandLineSupport {
         this.download = download;
     }
 
+    public DownloadListener getDownloadListener() {
+        return downloadListener;
+    }
+
+    /**
+     * Sets a custom download listener
+     */
+    public void setDownloadListener(DownloadListener downloadListener) {
+        this.downloadListener = downloadListener;
+    }
+
     // Implementation methods
     // 
-------------------------------------------------------------------------
 
@@ -159,6 +172,11 @@ public class KameletMain extends MainCommandLineSupport {
         // do not build/init camel context yet
         DefaultCamelContext answer = new DefaultCamelContext(false);
 
+        // register download listener
+        if (downloadListener != null) {
+            
answer.adapt(ExtendedCamelContext.class).setExtension(DownloadListener.class, 
downloadListener);
+        }
+
         String info = startupInfo();
         if (info != null) {
             LOG.info(info);

Reply via email to