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 f05e340360cf CAMEL-25380: camel-yaml-dsl - Do not log the compact 
notation warning for the Kamelets of the Kamelet catalog (#27448)
f05e340360cf is described below

commit f05e340360cf53fa32665047697e912bf836dc39
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Oct 6 19:44:42 2026 +0200

    CAMEL-25380: camel-yaml-dsl - Do not log the compact notation warning for 
the Kamelets of the Kamelet catalog (#27448)
    
    * 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) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    * CAMEL-25380: camel-yaml-dsl - Decide by origin: only the Kamelets of the 
Kamelet catalog are not warned about
    
    Review: "inside a jar" was a proxy for "not the user's file" that misfired 
both
    ways (the application's own jar silenced, the same file through a wildcard 
scan
    warned, other archive protocols warned) and looked up every resource on 
every
    load. Now only a file under kamelets/ in a camel-kamelets jar is exempt, 
however
    it was loaded, and that is asked only when the warning is about to be 
logged.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    * CAMEL-25380: Regen
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    ---------
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../org/apache/camel/catalog/docs/yaml-dsl.adoc    |  3 +
 .../yaml/common/YamlDeserializationContext.java    | 29 ++++++++++
 .../camel-yaml-dsl/src/main/docs/yaml-dsl.adoc     |  3 +
 .../camel/dsl/yaml/CompactNotationWarnTest.java    | 67 ++++++++++++++++++++++
 4 files changed, 102 insertions(+)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/yaml-dsl.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/yaml-dsl.adoc
index 1a0fe5a24885..3900f48764f5 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/yaml-dsl.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/yaml-dsl.adoc
@@ -951,6 +951,9 @@ It is recommended to use canonical/normalized YAML DSL 
notation which is more to
 Use Camel CLI to normalize: camel validate normalize <file>
 ----
 
+The Kamelets of the Kamelet catalog (the `camel-kamelets` jar) are not warned 
about: they are not files of the
+application to normalize. Any other file, in the application's own jar or a 
custom Kamelet included, is.
+
 To disable this warning, set the following property in 
`application.properties`:
 
 [source,properties]
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
index 857f1fea7a34..86eeed51df43 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.dsl.yaml.common;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -23,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
@@ -105,6 +107,10 @@ public class YamlDeserializationContext extends 
StandardConstructor implements C
     public void warnCompactNotationOnce(Logger log) {
         if (compactNotationWarn && !compactNotationWarned) {
             compactNotationWarned = true;
+            if (isKameletCatalog(resource)) {
+                // a Kamelet of the Kamelet catalog (camel-kamelets): not the 
user's file to normalize
+                return;
+            }
             String loc = resource != null ? resource.getLocation() : "unknown";
             log.warn("YAML DSL compact notation detected in: {}."
                      + " It is recommended to use canonical/normalized YAML 
DSL notation"
@@ -114,6 +120,29 @@ public class YamlDeserializationContext extends 
StandardConstructor implements C
         }
     }
 
+    private static final Pattern KAMELET_CATALOG = 
Pattern.compile("/camel-kamelets-[^/!]*\\.jar!/kamelets/");
+
+    /**
+     * Whether the resource is a Kamelet of the Kamelet catalog: under 
kamelets/ in a camel-kamelets jar, however it was
+     * loaded (classpath:kamelets/..., a scan of the jar, a jar nested in a 
Spring Boot jar). Asked only when the
+     * warning is about to be logged.
+     */
+    static boolean isKameletCatalog(Resource resource) {
+        if (resource == null) {
+            return false;
+        }
+        String location = resource.getLocation();
+        if (location != null && KAMELET_CATALOG.matcher(location).find()) {
+            return true;
+        }
+        try {
+            URI uri = resource.getURI();
+            return uri != null && 
KAMELET_CATALOG.matcher(uri.toString()).find();
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
     @Override
     public CamelContext getCamelContext() {
         return camelContext;
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
index 1a0fe5a24885..3900f48764f5 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
@@ -951,6 +951,9 @@ It is recommended to use canonical/normalized YAML DSL 
notation which is more to
 Use Camel CLI to normalize: camel validate normalize <file>
 ----
 
+The Kamelets of the Kamelet catalog (the `camel-kamelets` jar) are not warned 
about: they are not files of the
+application to normalize. Any other file, in the application's own jar or a 
custom Kamelet included, is.
+
 To disable this warning, set the following property in 
`application.properties`:
 
 [source,properties]
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..b37c60a375e9 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,63 @@ class CompactNotationWarnTest extends YamlTestSupport {
         assertThat(warnings.get(0)).contains("YAML DSL compact notation 
detected", "camel validate normalize");
     }
 
+    private static final String COMPACT_ROUTE = """
+            - route:
+                from:
+                  uri: "direct:start"
+                  steps:
+                    - setBody:
+                        simple: "Hello ${body}"
+                    - to: "mock:result"
+            """;
+
+    @Test
+    void aKameletOfTheKameletCatalogIsNotWarnedAbout(@TempDir Path dir) throws 
Exception {
+        // CAMEL-25380: the user cannot normalize a Kamelet of the 
camel-kamelets jar
+        Path jar = jar(dir.resolve("camel-kamelets-4.22.1.jar"), 
"kamelets/compact.yaml");
+        loadFromClasspath(jar, "classpath:kamelets/compact.yaml");
+        assertThat(warnings).isEmpty();
+    }
+
+    @Test
+    void aFileInTheApplicationsJarIsWarnedAbout(@TempDir Path dir) throws 
Exception {
+        // the application's own routes and custom Kamelets are files to 
normalize, in a jar or not
+        Path jar = jar(dir.resolve("my-app.jar"), "kamelets/compact.yaml");
+        loadFromClasspath(jar, "classpath:kamelets/compact.yaml");
+        assertThat(warnings).hasSize(1);
+    }
+
+    @Test
+    void aClasspathFileOutsideAJarIsWarnedAbout(@TempDir Path dir) throws 
Exception {
+        Files.createDirectories(dir.resolve("routes"));
+        Files.writeString(dir.resolve("routes/compact.yaml"), COMPACT_ROUTE);
+        loadFromClasspath(dir, "classpath:routes/compact.yaml");
+        assertThat(warnings).hasSize(1);
+    }
+
+    private static Path jar(Path jar, String entry) throws Exception {
+        try (JarOutputStream out = new 
JarOutputStream(Files.newOutputStream(jar))) {
+            out.putNextEntry(new JarEntry(entry));
+            out.write(COMPACT_ROUTE.getBytes(StandardCharsets.UTF_8));
+            out.closeEntry();
+        }
+        return jar;
+    }
+
+    private void loadFromClasspath(Path classpathEntry, String location) 
throws Exception {
+        ClassLoader original = context.getApplicationContextClassLoader();
+        try (URLClassLoader cl = new URLClassLoader(
+                new URL[] { classpathEntry.toUri().toURL() }, 
getClass().getClassLoader())) {
+            context.setApplicationContextClassLoader(cl);
+            Resource resource = 
PluginHelper.getResourceLoader(context).resolveResource(location);
+            assertThat(resource.exists()).isTrue();
+            loadRoutes(resource);
+        } finally {
+            context.setApplicationContextClassLoader(original);
+        }
+        assertThat(context.getRouteDefinitions()).hasSize(1);
+    }
+
     @Test
     void aStepWrittenAsAStringIsTheCompactNotation() throws Exception {
         loadRoutes("""

Reply via email to