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 2024/01/25 10:36:25 UTC

(camel) branch main updated (3ae53b6f162 -> 6004d83270c)

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

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


    from 3ae53b6f162 CAMEL-20359: camel-groovy - Consistent name to refer to exchangeProperties. Note this will also apply to other template based components like freemarker.
     new 73807747e5f CAMEL-20354: camel-jbang - Using camel run --source-dir component should be able to load from classpath
     new 6004d83270c Regen

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../impl/engine/DefaultResourceResolvers.java      |  4 ++++
 .../main/HttpServerConfigurationProperties.java    |  6 ++----
 .../main/java/org/apache/camel/util/FileUtil.java  |  1 -
 .../java/org/apache/camel/main/KameletMain.java    |  6 ++++--
 .../DependencyDownloaderResourceLoader.java        | 24 ++++++++++++++++++++--
 5 files changed, 32 insertions(+), 9 deletions(-)


(camel) 01/02: CAMEL-20354: camel-jbang - Using camel run --source-dir component should be able to load from classpath

Posted by da...@apache.org.
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 73807747e5ff94ee72e1c16dbc2de02306f851e5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jan 25 11:10:18 2024 +0100

    CAMEL-20354: camel-jbang - Using camel run --source-dir component should be able to load from classpath
---
 .../impl/engine/DefaultResourceResolvers.java      |  4 ++++
 .../main/java/org/apache/camel/util/FileUtil.java  |  1 -
 .../java/org/apache/camel/main/KameletMain.java    |  6 ++++--
 .../DependencyDownloaderResourceLoader.java        | 24 ++++++++++++++++++++--
 4 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
index 4caca72c06a..21e29e19c55 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
@@ -176,6 +176,10 @@ public final class DefaultResourceResolvers {
         }
 
         private String getPath(String location) {
+            // skip leading double slashes
+            if (location.startsWith("//")) {
+                location = location.substring(2);
+            }
             String uri = tryDecodeUri(location);
             return FileUtil.compactPath(uri, '/');
         }
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java b/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
index 22e9b732a95..a5df404576f 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/FileUtil.java
@@ -275,7 +275,6 @@ public final class FileUtil {
 
     /**
      * Compacts a path by stacking it and reducing <tt>..</tt>, and uses the given separator.
-     *
      */
     public static String compactPath(String path, char separator) {
         return compactPath(path, String.valueOf(separator));
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 f9480d9747e..28f8a6825f4 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
@@ -526,6 +526,9 @@ public class KameletMain extends MainCommandLineSupport {
             }
         }
 
+        // source-dir
+        String sourceDir = getInitialProperties().getProperty("camel.jbang.sourceDir");
+
         try {
             // dependencies from CLI
             Object dependencies = getInitialProperties().get("camel.jbang.dependencies");
@@ -561,7 +564,7 @@ public class KameletMain extends MainCommandLineSupport {
             answer.getCamelContextExtension().addContextPlugin(UriFactoryResolver.class,
                     new DependencyDownloaderUriFactoryResolver(answer));
             answer.getCamelContextExtension().addContextPlugin(ResourceLoader.class,
-                    new DependencyDownloaderResourceLoader(answer));
+                    new DependencyDownloaderResourceLoader(answer, sourceDir));
 
             answer.setInjector(new KameletMainInjector(answer.getInjector(), stubPattern, silent));
             Object kameletsVersion = getInitialProperties().get("camel.jbang.kameletsVersion");
@@ -574,7 +577,6 @@ public class KameletMain extends MainCommandLineSupport {
                     new DownloadModelineParser(answer));
 
             // reloader
-            String sourceDir = getInitialProperties().getProperty("camel.jbang.sourceDir");
             if (sourceDir != null) {
                 if (console || health) {
                     // allow to upload source via http when HTTP console enabled
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderResourceLoader.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderResourceLoader.java
index ca9a133c0be..280384a383a 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderResourceLoader.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderResourceLoader.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.main.download;
 
+import java.io.File;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.impl.engine.DefaultResourceLoader;
 import org.apache.camel.spi.Resource;
@@ -24,9 +26,11 @@ import org.apache.camel.util.StringHelper;
 public class DependencyDownloaderResourceLoader extends DefaultResourceLoader {
 
     private final DependencyDownloader downloader;
+    private final String sourceDir;
 
-    public DependencyDownloaderResourceLoader(CamelContext camelContext) {
+    public DependencyDownloaderResourceLoader(CamelContext camelContext, String sourceDir) {
         super(camelContext);
+        this.sourceDir = sourceDir;
         this.downloader = camelContext.hasService(DependencyDownloader.class);
     }
 
@@ -45,7 +49,23 @@ public class DependencyDownloaderResourceLoader extends DefaultResourceLoader {
                 }
             }
         }
-        return super.resolveResource(uri);
+        Resource answer = super.resolveResource(uri);
+        if (sourceDir != null) {
+            boolean exists = answer != null && answer.exists();
+            // if not found then we need to look again inside the source-dir which we can do
+            // for file and classpath resources
+            if (!exists && ("classpath".equals(scheme) || "file".equals(scheme))) {
+                String path = StringHelper.after(uri, ":");
+                // strip leading double slash
+                if (path.startsWith("//")) {
+                    path = path.substring(2);
+                }
+                // force to load from file system when using source-dir
+                uri = "file" + ":" + sourceDir + File.separator + path;
+                answer = super.resolveResource(uri);
+            }
+        }
+        return answer;
     }
 
 }


(camel) 02/02: Regen

Posted by da...@apache.org.
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 6004d83270cd2ed55cabf7bf5bceeb2ea0cf2fa0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jan 25 11:10:26 2024 +0100

    Regen
---
 .../org/apache/camel/main/HttpServerConfigurationProperties.java    | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
index 322bdde54ae..93fff2e5e26 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
@@ -156,8 +156,7 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable {
     }
 
     /**
-     * Whether to enable jolokia. If enabled then you can access jolokia api on context-path:
-     * /q/jolokia
+     * Whether to enable jolokia. If enabled then you can access jolokia api on context-path: /q/jolokia
      */
     public void setJolokiaEnabled(boolean jolokiaEnabled) {
         this.jolokiaEnabled = jolokiaEnabled;
@@ -268,8 +267,7 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable {
     }
 
     /**
-     * Whether to enable jolokia. If enabled then you can access jolokia api on context-path:
-     * /q/jolokia
+     * Whether to enable jolokia. If enabled then you can access jolokia api on context-path: /q/jolokia
      */
     public HttpServerConfigurationProperties withJolokiaEnabled(boolean jolokiaEnabled) {
         this.jolokiaEnabled = jolokiaEnabled;