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 2026/10/06 15:13:56 UTC

(camel) branch fix/CAMEL-25380 created (now 71de42e3ad04)

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

davsclaus pushed a change to branch fix/CAMEL-25380
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 71de42e3ad04 CAMEL-25380: camel-yaml-dsl - Do not log the compact notation warning for YAML inside a jar

This branch includes the following new commits:

     new 71de42e3ad04 CAMEL-25380: camel-yaml-dsl - Do not log the compact notation warning for YAML inside a jar

The 1 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.



(camel) 01/01: CAMEL-25380: camel-yaml-dsl - Do not log the compact notation warning for YAML inside a jar

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 71de42e3ad04f9694ae09be007b89548208e0a76
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 6 17:13:36 2026 +0200

    CAMEL-25380: camel-yaml-dsl - Do not log the compact notation warning for YAML inside a jar
    
    The Kamelets of the Kamelet catalog are compact, and every user of timer-source
    was told to normalize a file inside a jar they cannot change.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <no...@anthropic.com>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
---
 .../dsl/yaml/YamlRoutesBuilderLoaderSupport.java   | 23 ++++++++++++++
 .../camel/dsl/yaml/CompactNotationWarnTest.java    | 37 ++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
index 1b0ea4f5fd46..fc3e74aee4f9 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
@@ -18,6 +18,7 @@ package org.apache.camel.dsl.yaml;
 
 import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.List;
 import java.util.Objects;
 import java.util.function.Predicate;
@@ -68,9 +69,31 @@ public abstract class YamlRoutesBuilderLoaderSupport extends RouteBuilderLoaderS
         } catch (Exception e) {
             // ignore
         }
+        if (ctx.isCompactNotationWarn() && isInsideJar(resource)) {
+            // a file inside a jar, such as a Kamelet of the Kamelet catalog, is not the user's to normalize: the
+            // warning told every user of timer-source to fix a file they cannot change
+            ctx.setCompactNotationWarn(false);
+        }
         return ctx;
     }
 
+    private boolean isInsideJar(Resource resource) {
+        String loc = resource != null ? resource.getLocation() : null;
+        if (loc == null || !loc.startsWith("classpath:")) {
+            return false;
+        }
+        try {
+            String path = loc.substring("classpath:".length());
+            if (path.startsWith("/")) {
+                path = path.substring(1);
+            }
+            URL url = getCamelContext().getClassResolver().loadResourceAsURL(path);
+            return url != null && "jar".equals(url.getProtocol());
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
     @Override
     public RouteBuilder doLoadRouteBuilder(Resource resource) throws Exception {
         if (!resource.exists()) {
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/CompactNotationWarnTest.java b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/CompactNotationWarnTest.java
index 4f547c2efe1f..be72917480e7 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/CompactNotationWarnTest.java
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/CompactNotationWarnTest.java
@@ -16,11 +16,20 @@
  */
 package org.apache.camel.dsl.yaml;
 
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
 
 import org.apache.camel.dsl.yaml.common.YamlDeserializerBase;
 import org.apache.camel.dsl.yaml.support.YamlTestSupport;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.PluginHelper;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.LogEvent;
@@ -30,6 +39,7 @@ import org.apache.logging.log4j.core.config.Property;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.junit.jupiter.api.parallel.Isolated;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -82,6 +92,33 @@ class CompactNotationWarnTest extends YamlTestSupport {
         assertThat(warnings.get(0)).contains("YAML DSL compact notation detected", "camel validate normalize");
     }
 
+    @Test
+    void aFileInsideAJarIsNotWarnedAbout(@TempDir Path dir) throws Exception {
+        // CAMEL-25380: the Kamelets of the Kamelet catalog are compact, and the user cannot change a file in a jar
+        Path jar = dir.resolve("routes.jar");
+        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(jar))) {
+            out.putNextEntry(new JarEntry("jarroutes/compact.yaml"));
+            out.write("""
+                    - route:
+                        from:
+                          uri: "direct:start"
+                          steps:
+                            - setBody:
+                                simple: "Hello ${body}"
+                            - to: "mock:result"
+                    """.getBytes(StandardCharsets.UTF_8));
+            out.closeEntry();
+        }
+        try (URLClassLoader cl = new URLClassLoader(new URL[] { jar.toUri().toURL() }, getClass().getClassLoader())) {
+            context.setApplicationContextClassLoader(cl);
+            Resource resource = PluginHelper.getResourceLoader(context).resolveResource("classpath:jarroutes/compact.yaml");
+            assertThat(resource.exists()).isTrue();
+            loadRoutes(resource);
+        }
+        assertThat(context.getRouteDefinitions()).hasSize(1);
+        assertThat(warnings).isEmpty();
+    }
+
     @Test
     void aStepWrittenAsAStringIsTheCompactNotation() throws Exception {
         loadRoutes("""