You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "davsclaus (via GitHub)" <gi...@apache.org> on 2026/09/20 16:59:40 UTC

[PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

davsclaus opened a new pull request, #26635:
URL: https://github.com/apache/camel/pull/26635

   ## Description
   
   `camel export` copies every `.groovy` file into `src/main/resources/camel-groovy`, the directory `camel.main.groovyScriptPattern` compiles scripts from at startup. A Groovy mapping script that a route uses as the body of an expression, `groovy: {expression: "resource:classpath:shipment-mapping.groovy"}`, is then out of reach of the reference in the exported project (it would have to read `camel-groovy/shipment-mapping.groovy`), and is compiled as a script it is not. Neither `resource:classpath:` nor `resource:file:` by bare name survived the export; with CAMEL-24852 the `classpath:` form works in `camel run` too, so it is the form to write in both places.
   
   The export now scans the route files (`camel.main.routesIncludePattern`) for `resource:classpath:x` / `resource:file:x` references and keeps a referenced Groovy file at the resources root, where the reference resolves on Spring Boot, Quarkus and camel-main alike. Groovy files the routes do not reference go to `camel-groovy` as before. Upgrade guide note added.
   
   The camel-jbang-examples data-mapping example is the case (it uses `resource:file:`; a follow-up there switches it to `classpath:`).
   
   ## Tests
   
   `ExportTest.shouldExportAResourceReferencedGroovyScriptToTheResourcesRoot` (all three runtimes): a route referencing `shipment-mapping.groovy` as a resource plus an unreferenced `demo.groovy`: the first lands at `src/main/resources/`, the second in `camel-groovy/`. The existing `shouldExportGroovy` keeps passing.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26635:
URL: https://github.com/apache/camel/pull/26635#issuecomment-5751510222

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `docs`
   - `dsl/camel-jbang/camel-jbang-core`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 6 of 692 tested, 8 compile-only — current: 6 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **16 affected modules** (current approach: 6).
   
   **Skip-tests mode would test 6 modules** (2 direct + 6 downstream), **skip tests for 8** (generated code, meta-modules)
   
   <details><summary>:warning: Modules only in Scalpel (10)</summary>
   
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-launcher`
   - `coverage`
   - `docs`
   
   </details>
   
   
   <details><summary>Modules Scalpel would test (6)</summary>
   
   - `camel-jbang-core` ← dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java, dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java, dsl/camel-jbang/camel-jbang-core/src/test/resources/groovy-resource-demo.camel.yaml, dsl/camel-jbang/camel-jbang-core/src/test/resources/shipment-mapping.groovy
   - `camel-jbang-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-route-parser` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
   - `docs` ← docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
   
   </details>
   
   <details><summary>Modules with tests skipped (8)</summary>
   
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-launcher`
   - `coverage`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   :warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification:
   
   - `dsl/camel-jbang/camel-jbang-core`: 2 test(s) disabled on GitHub Actions
   
   :bulb: **Manual integration tests recommended:**
   
   > You modified `dsl/camel-jbang/camel-jbang-core`. The related integration tests in `dsl/camel-jbang/camel-jbang-it` are excluded from CI. Consider running them manually:
   > ```
   > mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
   > ```
   
   <details><summary>All tested modules (16 modules, 2m 45s total)</summary>
   
   **Total reactor time:** 2m 45s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: Launcher | 44.4s | SUCCESS |
   | Camel :: JBang :: MCP | 35.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: TUI | 31.5s | SUCCESS |
   | Camel :: Docs | 15.7s | SUCCESS |
   | Camel :: JBang :: Plugin :: Kubernetes | 13.8s | SUCCESS |
   | Camel :: JBang :: Plugin :: Testing | 8.1s | SUCCESS |
   | Camel :: JBang :: Plugin :: Validate | 5.4s | SUCCESS |
   | Camel :: Coverage | 2.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: Edit | 1.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: Route Parser | 1.3s | SUCCESS |
   | Camel :: JBang :: Plugin :: MCP | 1.3s | SUCCESS |
   | Camel :: JBang :: Plugin :: Generate | 1.3s | SUCCESS |
   | Camel :: JBang :: Main | 0.9s | SUCCESS |
   | Camel :: JBang :: Integration tests | 0.7s | SUCCESS |
   | Camel :: Launcher :: Container | 0.7s | SUCCESS |
   | Camel :: JBang :: Core | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: Launcher` (44.4s)
   - `Camel :: JBang :: MCP` (35.6s)
   - `Camel :: JBang :: Plugin :: TUI` (31.5s)
   - `Camel :: Docs` (15.7s)
   - `Camel :: JBang :: Plugin :: Kubernetes` (13.8s)
   - `Camel :: JBang :: Plugin :: Testing` (8.1s)
   - `Camel :: JBang :: Plugin :: Validate` (5.4s)
   - `Camel :: Coverage` (2.6s)
   - `Camel :: JBang :: Plugin :: Edit` (1.6s)
   - `Camel :: JBang :: Plugin :: Route Parser` (1.3s)
   - `Camel :: JBang :: Plugin :: MCP` (1.3s)
   - `Camel :: JBang :: Plugin :: Generate` (1.3s)
   - `Camel :: JBang :: Main` (0.9s)
   - `Camel :: JBang :: Integration tests` (0.7s)
   - `Camel :: Launcher :: Container` (0.7s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/35525388029)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #26635:
URL: https://github.com/apache/camel/pull/26635#issuecomment-5751640863

   Both in 3af540a9cd0c: `resourceReferencedFiles` is private static and reads a `classpath:` route through `ExportBaseCommand.class.getClassLoader()`, and a test exports a route given as `classpath:groovy-resource-demo.camel.yaml` and checks the referenced script lands at the resources root.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #26635:
URL: https://github.com/apache/camel/pull/26635#discussion_r4057556538


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java:
##########
@@ -881,6 +881,64 @@ private static void addRuntimeSpecificDependencies(String deps, Set<String> answ
         }
     }
 
+    /** resource:classpath:x or resource:file:x in a route file: the file x is referenced by its path. */
+    private static final Pattern RESOURCE_REF_PATTERN = Pattern.compile("resource:(?:classpath|file):([^\"'\\s?&,]+)");
+
+    /**
+     * The paths of the files the route files (camel.main.routesIncludePattern) reference as resource:classpath: or
+     * resource:file:, as written in the reference (a relative path, or a bare name), so the export can keep them where
+     * the reference resolves. A file: route is read from the file system, a classpath: route from the classpath.
+     */
+    private Set<String> resourceReferencedFiles(String routeFiles) {

Review Comment:
   💡 **`private static` + `ExportBaseCommand.class.getClassLoader()`:** `getScheme()` (the only non-argument dependency) is `protected static` in `CamelCommand`, so this method has no instance dependency. The remaining reason it is not `static` is `getClass().getClassLoader()`. `getClass()` returns the runtime subclass (`Export`, `ExportQuarkus`, …), not `ExportBaseCommand` — the classloaders happen to be identical today, but that is an accidental invariant. Use `ExportBaseCommand.class.getClassLoader()` and declare the method `private static`.
   
   ```suggestion
       private static Set<String> resourceReferencedFiles(String routeFiles) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #26635:
URL: https://github.com/apache/camel/pull/26635


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #26635:
URL: https://github.com/apache/camel/pull/26635#issuecomment-5751358676

   All three in fb5eb5ed7e32: the helper is private (an instance method still, since `getScheme` is one); a `classpath:` route entry is read from the classpath and scanned like a `file:` one; the references are kept as written (a relative path or a bare name) and a script matches by its full path, by a path suffix, or by bare name when that is how it was referenced, so two scripts with one name in different folders are told apart when the reference carries the folder.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #26635:
URL: https://github.com/apache/camel/pull/26635#discussion_r4057504160


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java:
##########
@@ -881,6 +881,43 @@ private static void addRuntimeSpecificDependencies(String deps, Set<String> answ
         }
     }
 
+    /** resource:classpath:x or resource:file:x in a route file: the file x is referenced by name. */
+    private static final Pattern RESOURCE_REF_PATTERN = Pattern.compile("resource:(?:classpath|file):([^\"'\\s?&,]+)");
+
+    /**
+     * The names of the files the route files (camel.main.routesIncludePattern) reference as resource:classpath: or
+     * resource:file:, so the export can keep them where the reference resolves.
+     */
+    Set<String> resourceReferencedFiles(String routeFiles) {
+        Set<String> names = new HashSet<>();
+        if (routeFiles == null || routeFiles.isBlank()) {
+            return names;
+        }
+        for (String f : routeFiles.split(",")) {
+            f = f.trim();
+            String scheme = getScheme(f);
+            if (scheme != null) {
+                if (!"file".equals(scheme)) {
+                    continue;
+                }
+                f = f.substring(scheme.length() + 1);
+            }
+            Path path = Paths.get(f);
+            if (!Files.isRegularFile(path)) {
+                continue;
+            }
+            try {
+                Matcher m = RESOURCE_REF_PATTERN.matcher(Files.readString(path));
+                while (m.find()) {
+                    names.add(FileUtil.stripPath(m.group(1)));

Review Comment:
   🔍 **Basename-only matching:** `FileUtil.stripPath(m.group(1))` reduces `resource:classpath:scripts/mapping.groovy` to just `mapping.groovy`. If two Groovy files in different subdirectories share a basename, both will be routed to the resources root even if only one is referenced. This is consistent with how `f` is stripped on the other side (line 989), so the matching is symmetric — but the imprecision is worth documenting. Consider retaining the relative path in the set and matching with `f.endsWith(name)` to narrow the collision window.



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java:
##########
@@ -881,6 +881,43 @@ private static void addRuntimeSpecificDependencies(String deps, Set<String> answ
         }
     }
 
+    /** resource:classpath:x or resource:file:x in a route file: the file x is referenced by name. */
+    private static final Pattern RESOURCE_REF_PATTERN = Pattern.compile("resource:(?:classpath|file):([^\"'\\s?&,]+)");
+
+    /**
+     * The names of the files the route files (camel.main.routesIncludePattern) reference as resource:classpath: or
+     * resource:file:, so the export can keep them where the reference resolves.
+     */
+    Set<String> resourceReferencedFiles(String routeFiles) {
+        Set<String> names = new HashSet<>();
+        if (routeFiles == null || routeFiles.isBlank()) {
+            return names;
+        }
+        for (String f : routeFiles.split(",")) {
+            f = f.trim();
+            String scheme = getScheme(f);
+            if (scheme != null) {
+                if (!"file".equals(scheme)) {
+                    continue;

Review Comment:
   ⚠️ **Silent gap — `classpath:` route files are not scanned:** When `camel.main.routesIncludePattern` contains `classpath:route.yaml` entries (written by `Run` for classpath-loaded routes), this branch silently skips them. Any Groovy resource referenced inside such a route will not be detected and will therefore be placed in `camel-groovy` instead of the resources root — which is the exact bug this PR is fixing.
   
   The Javadoc describes the method as scanning "the route files (`camel.main.routesIncludePattern`)" without qualifying that `classpath:` entries are excluded. At a minimum, update the Javadoc to document the limitation. Ideally, resolve classpath entries against the classpath or the settings-adjacent resource directories.



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java:
##########
@@ -881,6 +881,43 @@ private static void addRuntimeSpecificDependencies(String deps, Set<String> answ
         }
     }
 
+    /** resource:classpath:x or resource:file:x in a route file: the file x is referenced by name. */
+    private static final Pattern RESOURCE_REF_PATTERN = Pattern.compile("resource:(?:classpath|file):([^\"'\\s?&,]+)");
+
+    /**
+     * The names of the files the route files (camel.main.routesIncludePattern) reference as resource:classpath: or
+     * resource:file:, so the export can keep them where the reference resolves.
+     */
+    Set<String> resourceReferencedFiles(String routeFiles) {

Review Comment:
   💡 **Method visibility / `static`:** `resourceReferencedFiles` accesses no instance state — it reads only its argument and the static `RESOURCE_REF_PATTERN`. It should be `private static`. As written (package-private instance method) it unnecessarily widens the implicit API surface of `ExportBaseCommand`.
   
   ```suggestion
       private static Set<String> resourceReferencedFiles(String routeFiles) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24853: camel export keeps a Groovy script the routes reference as a resource: at the resources root [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26635:
URL: https://github.com/apache/camel/pull/26635#issuecomment-5751263540

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org