allthingssecurity opened a new pull request, #30988: URL: https://github.com/apache/camel/pull/30988
# Description [CAMEL-27603](https://issues.apache.org/jira/browse/CAMEL-27603) Addresses the six points of the ticket, found while the option descriptions of camel-file-watch were improved for CAMEL-23832 (#30938). I checked each point against main and directory-watcher 0.19.1 first; all six are real. Point 2 is documented rather than changed in code (see below). 1. **A space or lower case in events failed the consumer** (fixed). Each value is now trimmed and upper-cased (`Locale.ROOT`), and empty values are skipped, so `CREATE, MODIFY` and `create` work. An unknown value fails the start with `Unknown event 'MOVE' in the events option, the accepted values are [CREATE, DELETE, MODIFY]`. This matches what the catalog validation accepts for a multi-value enum (trimmed, any case). 2. **pollThreads > 1 registers and hashes the tree once per thread** (documented, code not changed). Each `watchAsync()` call runs `registerPaths()` again on the same `DirectoryWatcher`. directory-watcher has no public method that runs another event loop without registering again, and calling `watchAsync()` only once would silently drop the extra threads that users set today for OVERFLOW. So the description of the option (endpoint and component) now says that all threads read the same WatchService, that each one registers the watched directories again at start (and hashes their files again with file hashing on), and that more threads can only help when events come from several directories at the same time, since a directory's events are read by one thread at a time. If you prefer, I can change it to one `watchAsync()` call and deprecate the option in a follow-up. 3. **recursive=false still watched and hashed all subdirectories** (fixed). With `recursive=false` the consumer gives the `DirectoryWatcher` a `FileTreeVisitor` that visits only the base directory and the entries directly in it, so subdirectories (also ones created later) are not registered and their files are not hashed. directory-watcher uses the visitor in three places: to hash the tree at start, to register directories, and, with the watch service of the file system that the consumer uses on Linux and Windows, to report a directory that was created. So the visitor passes a subdirectory of the base directory to `onFile`, never to `onDirectory`. That way it is hashed at start, so deleting it gives a DELETE event with file hashing on (the default); creating one gives a CREATE event; and it is never registered. A subdirectory that is already gone when the visitor looks at it (an editor or build temp directory) is no error: `Files.isSameFile` throwing `NoSuchFileException` means "n ot the base directory", and directory-watcher then skips the event quietly. The existing filter that drops events from deeper levels stays, for the watch services that always watch the whole tree (macOS, and Windows with `FILE_TREE`). 4. **The no-argument constructor of FileWatchEndpoint left options at 0 and false** (fixed). `concurrentConsumers`, `pollThreads`, `queueSize` and `useFileHashing` now start with the documented defaults 1, 1, `Integer.MAX_VALUE` and true, like the component. Routes are not affected, as the component always used the other constructor. 5. **CamelMessageTimestamp was not documented** (fixed). `FileWatchConstants.MESSAGE_TIMESTAMP` with `@Metadata` (javaType long, the time the consumer received the event) is added and used by the consumer. The header now shows on the doc page and in the catalog, and the endpoint DSL header builder gets `messageTimestamp()`. 6. **events had no enum metadata** (fixed). `enums = "CREATE,MODIFY,DELETE"` with `multiEnum = true`, so tooling can offer and validate the values. The option stays a String, so nothing changes for routes. Generated files: the component JSON, its catalog copy, and the endpoint and component DSL (`FileWatchEndpointBuilderFactory`, `FileWatchComponentBuilderFactory`) are regenerated. Tests: - `FileWatchConsumerOptionsTest`: - events ` create , Modify` starts and a created file comes in as a CREATE event (point 1); - an unknown event fails the start with a message that names it and lists the accepted values (point 1); - a non-recursive watch hashes a file of the base directory but not a file of a subdirectory, checked with a recording `FileHasher` right after the start (point 3); - `new FileWatchEndpoint()` has the documented defaults (point 4). - `FileWatchNonRecursiveDirectoryTest` (point 3): a created subdirectory gets a CREATE event, a deleted one that existed at start gets a DELETE event, and a subdirectory that is gone when the visitor is called is no error. On macOS the consumer leaves the watch service to directory-watcher, which then uses its own FSEvents service and reports a created directory without calling the visitor, so a route test on macOS cannot see this path. The test therefore builds the `DirectoryWatcher` the way the consumer does on Linux and Windows: with `dir.getFileSystem().newWatchService()` and the visitor of the consumer. The watch service of the file system is inotify on Linux and the JDK polling service on macOS, and both go through the visitor. I could not run it on Linux. All tests fail without the fix and pass with it, 5 runs in a row. Without the fix, `FileWatchNonRecursiveDirectoryTest` gets no CREATE and no DELETE event, and a `NoSuchFileException` for the vanished subdirectory. That is also why the existing `FileWatchComponentRecursiveTest.testCreateFileInSubdirectories`, which expects one CREATE event for directory `a` from the non-recursive route, would have failed on Linux CI with the first version of this change. It passed only on macOS. The camel-file-watch unit tests pass: 19 run, 0 failures, 0 errors, 1 skipped (skipped on main too). I ran them on macOS. This branch overlaps #30938 in meaning, not only in files. Its new `events` description says the values are "in upper case and without spaces", which is no longer required after point 1. Its new `recursive` description says "the whole directory tree is still watched", which is no longer true after point 3 on Linux. Both PRs also rewrite the `pollThreads` description. Whichever of the two is merged second needs those sentences adjusted (and the files regenerated). # 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): [CAMEL-27603](https://issues.apache.org/jira/browse/CAMEL-27603). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built camel-file-watch, which regenerated the component JSON, copied it to the catalog, and ran the camel-package plugin goals for the endpoint and component DSL. I did not run the full root build.) # 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 PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
