gnodet-bot commented on code in PR #29857:
URL: https://github.com/apache/camel/pull/29857#discussion_r4574969390
##########
dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPluginExporter.java:
##########
@@ -194,6 +193,50 @@ 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) {
+ // ignore scan errors for missing catalog
+ }
+ });
+ } catch (IOException e) {
+ // ignore if test directory cannot be listed
+ }
+
+ return deps;
+ }
+
+ private String asScannedDependency(String dependency) {
+ String[] parts = dependency.split(":");
+ if (parts[0].equals("org.citrusframework")) {
+ return asCitrusDependency(parts[1]);
+ } else if (parts[0].startsWith("org.apache.camel")) {
+ if (parts.length > 2 && parts[1].startsWith("camel-test-infra-")) {
+ return asDependency(parts[0], parts[1], parts[2]);
+ }
+ return asDependency(parts[0], parts[1]);
+ } else {
+ return asDependency(dependency);
+ }
+ }
Review Comment:
⚠️ **Potential `ArrayIndexOutOfBoundsException` on malformed dependency
strings**
`parts[1]` is accessed unconditionally in both the `org.citrusframework`
branch and the `org.apache.camel` fallback. If the Citrus analyzer returns a
dependency string without a colon separator, `split(":")` returns a
single-element array and `parts[1]` throws `ArrayIndexOutOfBoundsException`.
A cheap guard makes this robust:
```suggestion
private String asScannedDependency(String dependency) {
String[] parts = dependency.split(":");
if (parts.length < 2) {
return asDependency(dependency);
}
if (parts[0].equals("org.citrusframework")) {
return asCitrusDependency(parts[1]);
} else if (parts[0].startsWith("org.apache.camel")) {
if (parts.length > 2 &&
parts[1].startsWith("camel-test-infra-")) {
return asDependency(parts[0], parts[1], parts[2]);
}
return asDependency(parts[0], parts[1]);
} else {
return asDependency(dependency);
}
}
```
##########
dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPluginExporter.java:
##########
@@ -194,6 +193,50 @@ 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) {
+ // ignore scan errors for missing catalog
Review Comment:
⚠️ **Silent failure on scan errors**
Both `catch (IOException e)` blocks swallow scan failures with no logging.
The inner catch (here) silently drops per-file scan errors, so if the Citrus
catalog is missing or corrupt, `detectDependenciesFromTestSources` returns an
incomplete dependency set with no user feedback.
Consider at minimum logging a debug message:
```suggestion
} catch (IOException e) {
// ignore scan errors for missing catalog
LOG.debug("Failed to scan {} for dependencies:
{}", path, e.getMessage());
}
```
--
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]