gnodet-bot commented on code in PR #31188:
URL: https://github.com/apache/camel/pull/31188#discussion_r4756393609


##########
tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java:
##########
@@ -322,6 +326,30 @@ private Path getComponentClassesDirectory(Path 
componentRootDirectory) {
         return result;
     }
 
+    private static String extractArtifactId(Path componentRootDirectory) {
+        Path pom = componentRootDirectory.resolve("pom.xml");
+        if (Files.exists(pom)) {
+            try {
+                boolean inParent = false;
+                for (String line : Files.readAllLines(pom)) {
+                    if (line.contains("<parent>")) {
+                        inParent = true;
+                    } else if (line.contains("</parent>")) {
+                        inParent = false;
+                    } else if (!inParent) {
+                        String artifactId = Strings.between(line, 
"<artifactId>", "</artifactId>");
+                        if (artifactId != null) {
+                            return artifactId.trim();
+                        }
+                    }
+                }
+            } catch (IOException e) {

Review Comment:
   ⚠️ **Silent failure on POM read error**
   
   The `IOException` is caught and silently discarded with an empty `// 
fallback` comment. When a `pom.xml` exists but cannot be read (permissions, 
corruption, encoding issue), the method falls back to the directory name — same 
as before the fix — but gives no signal that something went wrong. At minimum, 
log at `DEBUG` so the fallback is diagnosable:
   
   ```suggestion
               } catch (IOException e) {
                   getLog().debug("Failed to read artifactId from %s, falling 
back to directory name".formatted(pom), e);
               }
   ```



##########
tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java:
##########
@@ -322,6 +326,30 @@ private Path getComponentClassesDirectory(Path 
componentRootDirectory) {
         return result;
     }
 
+    private static String extractArtifactId(Path componentRootDirectory) {
+        Path pom = componentRootDirectory.resolve("pom.xml");
+        if (Files.exists(pom)) {
+            try {
+                boolean inParent = false;
+                for (String line : Files.readAllLines(pom)) {
+                    if (line.contains("<parent>")) {
+                        inParent = true;
+                    } else if (line.contains("</parent>")) {
+                        inParent = false;
+                    } else if (!inParent) {
+                        String artifactId = Strings.between(line, 
"<artifactId>", "</artifactId>");
+                        if (artifactId != null) {
+                            return artifactId.trim();
+                        }
+                    }
+                }
+            } catch (IOException e) {
+                // fallback
+            }
+        }
+        return componentRootDirectory.getFileName().toString();

Review Comment:
   💡 **`extractArtifactId` deserves a unit test**
   
   This method contains non-trivial line-by-line POM parsing with an `inParent` 
state flag. The logic is correct for the standard Camel POM format, but it has 
an edge case: if `<parent>` and `</parent>` appear on the same line (not 
currently the case in Camel POMs), the `else-if` chain means only `inParent = 
true` runs and the closing tag branch is skipped — the rest of the file would 
be treated as if inside the parent block, returning the wrong `artifactId` or 
falling back to the directory name.
   
   There is no existing test for this method. Please add a unit test in the 
existing `camel-package-maven-plugin` test module covering at minimum:
   1. Standard multi-line parent block (the common case — the fix's happy path)
   2. No `pom.xml` present (directory name fallback)
   3. `pom.xml` present but no `<artifactId>` outside parent (directory name 
fallback)



##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocSeveralOptionsTest.java:
##########
@@ -97,10 +97,10 @@ void aTermThatMatchesNothingIsSaidWithTheClosestOptions() 
throws Exception {
 
     @Test
     void aTermThatIsAMessageHeaderSaysSo() throws Exception {
-        JsonObject answer = catalogDoc(Map.of("name", "aws2-s3", 
"optionsFilter", "bucketNameOrArn,CamelAwsS3Key"));
+        JsonObject answer = catalogDoc(Map.of("name", "aws2-s3", 
"optionsFilter", "bucketNameOrArn,CamelAwsS3CannedAcl"));
         assertThat(names(answer, "options")).contains("bucketNameOrArn");
-        JsonObject term = unmatched(answer, "camelawss3key");
-        assertThat(names(term, "headers")).contains("CamelAwsS3Key");
+        JsonObject term = unmatched(answer, "camelawss3cannedacl");
+        assertThat(names(term, "headers")).contains("CamelAwsS3CannedAcl");

Review Comment:
   💡 **Test fragility — depends on `CamelAwsS3CannedAcl` NOT appearing in 
option descriptions**
   
   The fix switches from `CamelAwsS3Key` (which now appears in aws2-s3 option 
descriptions after #31149, causing it to match as an option instead of an 
unmatched header) to `CamelAwsS3CannedAcl`. This works today, but the same 
regression could recur if CAMEL-23832 work later adds `CamelAwsS3CannedAcl` to 
an option description.
   
   Consider adding a comment explaining why this specific header was chosen and 
what would need to change if it breaks again — this will save the next person 
from having to trace the same commit history.



-- 
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]

Reply via email to