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/04/26 07:39:21 UTC

[camel] branch main updated: CAMEL-18010: camel-jbang - Resolved downloaded JARs should consider jbang CP

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 2957dff5103 CAMEL-18010: camel-jbang - Resolved downloaded JARs should consider jbang CP
2957dff5103 is described below

commit 2957dff5103710e116e278b1a1a60606949b8341
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 26 09:39:05 2022 +0200

    CAMEL-18010: camel-jbang - Resolved downloaded JARs should consider jbang CP
---
 .../apache/camel/dsl/jbang/core/commands/Run.java  |  8 +++++++-
 .../org/apache/camel/main/DownloaderHelper.java    | 23 ++++++++++++++--------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index d81260e2fd2..d59489f1098 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -22,7 +22,9 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.FileSystems;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Locale;
+import java.util.Set;
 import java.util.StringJoiner;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executors;
@@ -182,9 +184,13 @@ class Run implements Callable<Integer> {
             writeSettings("localKameletDir", localKameletDir);
         }
 
+        final Set<String> downloaded = new HashSet<>();
         main.setDownloadListener((groupId, artifactId, version) -> {
             String line = "mvn:" + groupId + ":" + artifactId + ":" + version;
-            writeSettings("dependency", line);
+            if (!downloaded.contains(line)) {
+                writeSettings("dependency", line);
+                downloaded.add(line);
+            }
         });
         main.setAppName("Apache Camel (JBang)");
 
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 6ace61173f9..37d62d6055a 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
@@ -44,6 +44,21 @@ public final class DownloaderHelper {
             listener.onDownloadDependency(groupId, artifactId, version);
         }
 
+        // when running jbang directly then the CP has some existing camel components
+        // that essentially is not needed to be downloaded, but we need the listener to trigger
+        // to capture that the GAV is required for running the application
+        if (CP != null) {
+            // is it already on classpath
+            String target = artifactId;
+            if (version != null) {
+                target = target + "-" + version;
+            }
+            if (CP.contains(target)) {
+                // already on classpath
+                return;
+            }
+        }
+
         StopWatch watch = new StopWatch();
         Map<String, Object> map = new HashMap<>();
         map.put("classLoader", camelContext.getApplicationContextClassLoader());
@@ -78,14 +93,6 @@ public final class DownloaderHelper {
             target = target + "-" + version;
         }
 
-        if (CP != null) {
-            // is it already on classpath
-            if (CP.contains(target)) {
-                // already on classpath
-                return true;
-            }
-        }
-
         if (camelContext.getApplicationContextClassLoader() != null) {
             ClassLoader cl = camelContext.getApplicationContextClassLoader();
             if (cl instanceof URLClassLoader) {