tools400 opened a new pull request, #27553: URL: https://github.com/apache/camel/pull/27553
# Description JIRA: [CAMEL-25452](https://issues.apache.org/jira/browse/CAMEL-25452) ## What is wrong CAMEL-24226 added `--resource-dir` to `camel run` and `camel export`. `camel run` puts the directories on the classpath, but `camel export` drops them without a warning. `Export` is only a front for the runtime-specific commands (`ExportCamelMain`, `ExportSpringBoot`, `ExportQuarkus`). `Export.export(Path, ExportBaseCommand)` copies its options onto them one by one, and `resourceDirs` is missing from that list. `ExportBaseCommand.copyResourceDirs` and the `run.resourceDirs` handed to the export run of the routes therefore always see an empty list: - a route that loads such a resource while the export starts it fails: ``` org.apache.camel.FailedToCreateRouteException: Failed to create route: route1 at: >>> SetBody[simple{resource:classpath:schemas/api.yaml}] <<< ... Caused by: java.io.FileNotFoundException: Cannot find resource: resource:classpath:schemas/api.yaml for URI: resource:classpath:schemas/api.yaml ``` - otherwise the export succeeds, but `src/main/resources` contains none of the directories. `camel kubernetes export` goes through the same method (`KubernetesExport extends Export`) and is affected the same way. The option exists since 4.22.0; 4.22.0, 4.22.1 and `main` are affected. ## Steps to reproduce ```shell mkdir -p demo/schemas && cd demo echo 'openapi: 3.0.3' > schemas/api.yaml cat > hello.camel.yaml <<'EOF' - route: from: uri: timer:hello?repeatCount=1 steps: - setBody: simple: resource:classpath:schemas/api.yaml - log: "${body}" EOF camel run hello.camel.yaml --resource-dir=schemas --max-messages=1 # logs "openapi: 3.0.3" camel export hello.camel.yaml --resource-dir=schemas --runtime=quarkus --dir=export # FailedToCreateRouteException ... Cannot find resource: resource:classpath:schemas/api.yaml ``` ## Fix `Export.export(Path, ExportBaseCommand)` hands the option on like every other option: `cmd.resourceDirs = this.resourceDirs;`, next to `cmd.excludes`. ## Tests | Test | Asserts | |---|---| | `ExportTest.shouldExportResourceDirs` (Quarkus, Spring Boot, Camel Main) | `camel export --resource-dir=<relative dir>` copies a file and a file in a sub-directory to `src/main/resources/<last path component>/…` | The new test fails for all three runtimes against `main` (`Expecting path … to exist`). `ResourceDirsTest` covers `validateResourceDir` and `walkResourceDir` and re-implements the copy loop, but never runs the command, which is why the gap went unnoticed. In `dsl/camel-jbang/camel-jbang-core`, `ExportTest` and `ResourceDirsTest` are green (142 tests); after rebasing onto the current `main` I ran the new test and `ResourceDirsTest` again. `mvn clean install -DskipTests` in the module leaves no uncommitted changes. With the fix, the reproducer above exports for `quarkus` and `camel-main`, with `schemas/api.yaml` in the exported resources; with Camel JBang 4.22.1 it fails as shown. I did not run a root `mvn clean install -DskipTests`. _Changes prepared with Claude Code on behalf of @tools400._ # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). <!-- # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes. --> # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. <!-- If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue. --> - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. <!-- You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`. You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md --> # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
