gnodet-bot commented on code in PR #26558:
URL: https://github.com/apache/camel/pull/26558#discussion_r4039279298
##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacade.java:
##########
@@ -1035,56 +1049,38 @@ JsonObject getFiles(String name, String file) {
if (dir == null || !Files.isDirectory(dir)) {
return null;
}
- if (file != null && !file.isEmpty()) {
- Path filePath = dir.resolve(file).normalize();
- if (!filePath.startsWith(dir) || !Files.isRegularFile(filePath)) {
- return null;
+ JsonObject result;
+ try {
+ result = file != null && !file.isEmpty()
+ ? AuthoringTools.readFile(dir, file) :
AuthoringTools.listFiles(dir);
+ } catch (ToolExecutionException e) {
+ JsonObject error = new JsonObject();
+ error.put("error", e.getMessage());
+ describeSourceDirectory(target, dir, error);
+ return error;
+ }
+ describeSourceDirectory(target, dir, result);
+ if (file == null || file.isEmpty()) {
+ JsonArray routes = new JsonArray();
+ for (RouteInfo r : target.routes) {
+ if (r.source != null && !r.source.isBlank()) {
+ JsonObject j = new JsonObject();
+ j.put("routeId", r.routeId);
Review Comment:
💡 **Nit:** `r.routeId` may be null for anonymous routes (no `id:` in the
YAML). `AuthoringTools.routeSources` guards against this (`r.get("routeId") !=
null`), so the output is correct, but this stores `null` in the intermediate
map and relies on the downstream guard to filter it. Mirror the guard here for
consistency and to avoid a silent regression if `routeSources` is ever
refactored:
```suggestion
if (r.routeId != null) {
j.put("routeId", r.routeId);
}
```
--
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]