gnodet-bot commented on code in PR #29857:
URL: https://github.com/apache/camel/pull/29857#discussion_r4577625814
##########
dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPluginExporter.java:
##########
@@ -194,6 +199,53 @@ public void addSourceFiles(Path buildDir, String
packageName, Printer printer) t
}
+ /**
+ * Scans Citrus test files in the given directory using the Citrus code
analyzer to detect required modules and
+ * dependencies. Supports YAML, XML and Groovy test sources.
+ */
+ private Set<String> detectDependenciesFromTestSources(Path testDir) {
+ Set<String> deps = new HashSet<>();
+ DelegatingCodeAnalyzer analyzer = new DelegatingCodeAnalyzer();
+ try (Stream<Path> paths = Files.list(testDir)) {
+ paths.filter(this::isTestSource)
+ .filter(this::isAnalyzerSupported)
+ .forEach(path -> {
+ try {
+ CodeAnalyzer.ScanResult result =
analyzer.scan(path);
+ for (String module : result.modules()) {
+ deps.add(asCitrusDependency(module));
+ }
+ for (String dependency : result.dependencies()) {
+ deps.add(asScannedDependency(dependency));
+ }
+ } catch (IOException e) {
Review Comment:
The inner catch only handles `IOException`, but `analyzer.scan(path)` and
the iterator calls on `result.modules()` / `result.dependencies()` can also
throw `RuntimeException` subclasses (e.g. `CitrusRuntimeException`,
`NullPointerException` from an analyzer failure).
Since this is a best-effort scan (failures are silently logged), consider
widening the catch:
```suggestion
} catch (Exception e) {
```
This prevents a runtime failure in one file's scan from propagating through
the `forEach` and crashing the entire dependency detection call.
--
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]