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 0a38c5e4fa42 CAMEL-23820: support custom directories in YAML DSL 
validator plugin
0a38c5e4fa42 is described below

commit 0a38c5e4fa4283edf1d8b0f74963dd2fbf37e187
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Jun 24 21:23:18 2026 +0200

    CAMEL-23820: support custom directories in YAML DSL validator plugin
    
    Add a 'directories' parameter to the camel-yaml-dsl-validator-maven-plugin
    that allows users to specify additional directories to scan for YAML files,
    beyond the default Maven resource directories. Both relative and absolute
    paths are supported. Also fixes a pre-existing artifactId typo in the
    documentation examples.
    
    Closes #24234
---
 .../camel-yaml-dsl-validator-maven-plugin.adoc     |  33 +++++-
 .../camel-yaml-dsl-validator-maven-plugin/pom.xml  |   5 +
 .../camel-yaml-dsl-validator-maven-plugin.adoc     |  33 +++++-
 .../camel/dsl/yaml/validator/ValidateMojo.java     |  21 +++-
 .../camel/dsl/yaml/validator/ValidateMojoTest.java | 132 +++++++++++++++++++++
 5 files changed, 218 insertions(+), 6 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-yaml-dsl-validator-maven-plugin.adoc
 
b/docs/user-manual/modules/ROOT/pages/camel-yaml-dsl-validator-maven-plugin.adoc
index f1cbe3439110..6772173b4f8f 100644
--- 
a/docs/user-manual/modules/ROOT/pages/camel-yaml-dsl-validator-maven-plugin.adoc
+++ 
b/docs/user-manual/modules/ROOT/pages/camel-yaml-dsl-validator-maven-plugin.adoc
@@ -26,7 +26,7 @@ You can also enable the plugin to run automatically as part 
of the build to catc
 ----
 <plugin>
   <groupId>org.apache.camel</groupId>
-  <artifactId>camel-yaml-dsl-validate-maven-plugin</artifactId>
+  <artifactId>camel-yaml-dsl-validator-maven-plugin</artifactId>
   <executions>
     <execution>
       <phase>process-classes</phase>
@@ -48,7 +48,7 @@ changed accordingly to `process-test-classes` as shown below:
 ----
 <plugin>
   <groupId>org.apache.camel</groupId>
-  <artifactId>camel-yaml-dsl-validate-maven-plugin</artifactId>
+  <artifactId>camel-yaml-dsl-validator-maven-plugin</artifactId>
   <executions>
     <execution>
       <configuration>
@@ -102,6 +102,7 @@ The maven plugin *validate* goal supports the following 
options which can be con
 | includes | | To filter the names of YAML files to only include files 
matching any of the given list of patterns (wildcard and regular expression). 
Multiple values can be separated by comma.
 | excludes | | To filter the names of YAML files to exclude files matching any 
of the given list of patterns (wildcard and regular expression). Multiple 
values can be separated by comma.
 | onlyCamelYamlExt | false | Whether to only accept files with xxx.camel.yaml 
as file name. By default, all .yaml files are accepted.
+| directories | | Additional directories to scan for YAML files. By default, 
only the project's resource directories are scanned.
 |===
 
 For example to excludes a specific file:
@@ -113,6 +114,34 @@ mvn camel-yaml-dsl-validator:validate 
-Dcamel.excludes=cheese.yaml
 
 Notice that you must prefix the `-D` command argument with `camel.`, eg 
`camel.excludes` as the option name.
 
+=== Validating with additional directories
+
+If your YAML route files are stored in a location outside the standard Maven 
resource directories, you can specify additional directories to scan:
+
+[source,xml]
+----
+<plugin>
+  <groupId>org.apache.camel</groupId>
+  <artifactId>camel-yaml-dsl-validator-maven-plugin</artifactId>
+  <executions>
+    <execution>
+      <configuration>
+        <directories>
+          <directory>src/main/routes</directory>
+          <directory>src/main/camel</directory>
+        </directories>
+      </configuration>
+      <phase>process-classes</phase>
+      <goals>
+        <goal>validate</goal>
+      </goals>
+    </execution>
+  </executions>
+</plugin>
+----
+
+Both relative and absolute paths are supported. Relative paths are resolved 
against the project base directory.
+
 === Validating include test
 
 If you have a Maven project then you can run the plugin to validate the 
endpoints in the unit test source code as well.
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/pom.xml 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/pom.xml
index 41627f10d374..5e2a45c1ea44 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/pom.xml
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/pom.xml
@@ -85,6 +85,11 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/docs/camel-yaml-dsl-validator-maven-plugin.adoc
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/docs/camel-yaml-dsl-validator-maven-plugin.adoc
index f1cbe3439110..6772173b4f8f 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/docs/camel-yaml-dsl-validator-maven-plugin.adoc
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/docs/camel-yaml-dsl-validator-maven-plugin.adoc
@@ -26,7 +26,7 @@ You can also enable the plugin to run automatically as part 
of the build to catc
 ----
 <plugin>
   <groupId>org.apache.camel</groupId>
-  <artifactId>camel-yaml-dsl-validate-maven-plugin</artifactId>
+  <artifactId>camel-yaml-dsl-validator-maven-plugin</artifactId>
   <executions>
     <execution>
       <phase>process-classes</phase>
@@ -48,7 +48,7 @@ changed accordingly to `process-test-classes` as shown below:
 ----
 <plugin>
   <groupId>org.apache.camel</groupId>
-  <artifactId>camel-yaml-dsl-validate-maven-plugin</artifactId>
+  <artifactId>camel-yaml-dsl-validator-maven-plugin</artifactId>
   <executions>
     <execution>
       <configuration>
@@ -102,6 +102,7 @@ The maven plugin *validate* goal supports the following 
options which can be con
 | includes | | To filter the names of YAML files to only include files 
matching any of the given list of patterns (wildcard and regular expression). 
Multiple values can be separated by comma.
 | excludes | | To filter the names of YAML files to exclude files matching any 
of the given list of patterns (wildcard and regular expression). Multiple 
values can be separated by comma.
 | onlyCamelYamlExt | false | Whether to only accept files with xxx.camel.yaml 
as file name. By default, all .yaml files are accepted.
+| directories | | Additional directories to scan for YAML files. By default, 
only the project's resource directories are scanned.
 |===
 
 For example to excludes a specific file:
@@ -113,6 +114,34 @@ mvn camel-yaml-dsl-validator:validate 
-Dcamel.excludes=cheese.yaml
 
 Notice that you must prefix the `-D` command argument with `camel.`, eg 
`camel.excludes` as the option name.
 
+=== Validating with additional directories
+
+If your YAML route files are stored in a location outside the standard Maven 
resource directories, you can specify additional directories to scan:
+
+[source,xml]
+----
+<plugin>
+  <groupId>org.apache.camel</groupId>
+  <artifactId>camel-yaml-dsl-validator-maven-plugin</artifactId>
+  <executions>
+    <execution>
+      <configuration>
+        <directories>
+          <directory>src/main/routes</directory>
+          <directory>src/main/camel</directory>
+        </directories>
+      </configuration>
+      <phase>process-classes</phase>
+      <goals>
+        <goal>validate</goal>
+      </goals>
+    </execution>
+  </executions>
+</plugin>
+----
+
+Both relative and absolute paths are supported. Relative paths are resolved 
against the project base directory.
+
 === Validating include test
 
 If you have a Maven project then you can run the plugin to validate the 
endpoints in the unit test source code as well.
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/java/org/apache/camel/dsl/yaml/validator/ValidateMojo.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/java/org/apache/camel/dsl/yaml/validator/ValidateMojo.java
index a8dc751afba7..a9e239972926 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/java/org/apache/camel/dsl/yaml/validator/ValidateMojo.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/main/java/org/apache/camel/dsl/yaml/validator/ValidateMojo.java
@@ -83,6 +83,12 @@ public class ValidateMojo extends AbstractMojo {
     @Parameter(property = "camel.includeTest", defaultValue = "false")
     private boolean includeTest;
 
+    /**
+     * Additional directories to scan for YAML files. By default, only the 
project's resource directories are scanned.
+     */
+    @Parameter(property = "camel.directories")
+    private List<String> directories;
+
     /**
      * To filter the names of YAML files to only include files matching any of 
the given list of patterns (wildcard and
      * regular expression). Multiple values can be separated by comma.
@@ -121,7 +127,7 @@ public class ValidateMojo extends AbstractMojo {
 
         // find all XML routes
         String ext = onlyCamelYamlExt ? ".camel.yaml" : ".yaml";
-        findYamlRouters(yamlFiles, includeTest, ext, project);
+        findYamlRouters(yamlFiles, includeTest, ext, directories, project);
         getLog().debug("Found " + yamlFiles.size() + " YAML files ...");
 
         Map<File, List<Error>> reports = new LinkedHashMap<>();
@@ -264,7 +270,9 @@ public class ValidateMojo extends AbstractMojo {
         return answer;
     }
 
-    private static void findYamlRouters(Set<File> yamlFiles, boolean 
includeTest, String ext, MavenProject project) {
+    static void findYamlRouters(
+            Set<File> yamlFiles, boolean includeTest, String ext,
+            List<String> directories, MavenProject project) {
         for (Resource dir : project.getResources()) {
             finYamlFiles(new File(dir.getDirectory()), ext, yamlFiles);
         }
@@ -273,6 +281,15 @@ public class ValidateMojo extends AbstractMojo {
                 finYamlFiles(new File(dir.getDirectory()), ext, yamlFiles);
             }
         }
+        if (directories != null) {
+            for (String dir : directories) {
+                File d = new File(dir);
+                if (!d.isAbsolute()) {
+                    d = new File(project.getBasedir(), dir);
+                }
+                finYamlFiles(d, ext, yamlFiles);
+            }
+        }
     }
 
     private static void finYamlFiles(File dir, String ext, Set<File> 
yamlFiles) {
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/test/java/org/apache/camel/dsl/yaml/validator/ValidateMojoTest.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/test/java/org/apache/camel/dsl/yaml/validator/ValidateMojoTest.java
new file mode 100644
index 000000000000..34a2d37c92fe
--- /dev/null
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator-maven-plugin/src/test/java/org/apache/camel/dsl/yaml/validator/ValidateMojoTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.dsl.yaml.validator;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class ValidateMojoTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    void findYamlRoutersScansCustomDirectories() throws IOException {
+        Path customDir = tempDir.resolve("custom-routes");
+        Files.createDirectories(customDir);
+        Files.writeString(customDir.resolve("my-route.yaml"), "- route:\n    
from:\n      uri: timer:yaml\n");
+
+        MavenProject project = new MavenProject();
+        project.setFile(new File(tempDir.toFile(), "pom.xml"));
+
+        Set<File> yamlFiles = new LinkedHashSet<>();
+        ValidateMojo.findYamlRouters(
+                yamlFiles, false, ".yaml",
+                List.of(customDir.toString()), project);
+
+        assertEquals(1, yamlFiles.size());
+        
assertTrue(yamlFiles.iterator().next().getName().endsWith("my-route.yaml"));
+    }
+
+    @Test
+    void findYamlRoutersScansRelativeCustomDirectories() throws IOException {
+        Path customDir = tempDir.resolve("src/main/routes");
+        Files.createDirectories(customDir);
+        Files.writeString(customDir.resolve("route.yaml"), "- route:\n    
from:\n      uri: timer:yaml\n");
+
+        MavenProject project = new MavenProject();
+        project.setFile(new File(tempDir.toFile(), "pom.xml"));
+
+        Set<File> yamlFiles = new LinkedHashSet<>();
+        ValidateMojo.findYamlRouters(
+                yamlFiles, false, ".yaml",
+                List.of("src/main/routes"), project);
+
+        assertEquals(1, yamlFiles.size());
+        
assertTrue(yamlFiles.iterator().next().getName().endsWith("route.yaml"));
+    }
+
+    @Test
+    void findYamlRoutersWithNullDirectories() {
+        MavenProject project = new MavenProject();
+        project.setFile(new File(tempDir.toFile(), "pom.xml"));
+
+        Set<File> yamlFiles = new LinkedHashSet<>();
+        ValidateMojo.findYamlRouters(
+                yamlFiles, false, ".yaml",
+                null, project);
+
+        assertTrue(yamlFiles.isEmpty());
+    }
+
+    @Test
+    void findYamlRoutersScansResourcesAndCustomDirectories() throws 
IOException {
+        Path resourceDir = tempDir.resolve("src/main/resources");
+        Files.createDirectories(resourceDir);
+        Files.writeString(resourceDir.resolve("resource-route.yaml"), "- 
route:\n    from:\n      uri: timer:yaml\n");
+
+        Path customDir = tempDir.resolve("custom");
+        Files.createDirectories(customDir);
+        Files.writeString(customDir.resolve("custom-route.yaml"), "- route:\n  
  from:\n      uri: timer:yaml\n");
+
+        MavenProject project = new MavenProject();
+        project.setFile(new File(tempDir.toFile(), "pom.xml"));
+
+        Resource resource = new Resource();
+        resource.setDirectory(resourceDir.toString());
+        project.addResource(resource);
+
+        Set<File> yamlFiles = new LinkedHashSet<>();
+        ValidateMojo.findYamlRouters(
+                yamlFiles, false, ".yaml",
+                List.of(customDir.toString()), project);
+
+        assertEquals(2, yamlFiles.size());
+    }
+
+    @Test
+    void findYamlRoutersFiltersByCamelYamlExtension() throws IOException {
+        Path customDir = tempDir.resolve("routes");
+        Files.createDirectories(customDir);
+        Files.writeString(customDir.resolve("my-route.camel.yaml"), "- 
route:\n    from:\n      uri: timer:yaml\n");
+        Files.writeString(customDir.resolve("other.yaml"), "key: value\n");
+
+        MavenProject project = new MavenProject();
+        project.setFile(new File(tempDir.toFile(), "pom.xml"));
+
+        Set<File> yamlFiles = new LinkedHashSet<>();
+        ValidateMojo.findYamlRouters(
+                yamlFiles, false, ".camel.yaml",
+                List.of(customDir.toString()), project);
+
+        assertEquals(1, yamlFiles.size());
+        
assertTrue(yamlFiles.iterator().next().getName().endsWith("my-route.camel.yaml"));
+    }
+}

Reply via email to