This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch fix-jandex-parallel-build-race
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8f2034e03a8483862642b9714c86351dde98c401
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Mar 13 12:30:35 2026 +0100

    Fix flaky parallel build failure in camel-test-infra-all jandex indexing
    
    In parallel reactor builds (SmartBuilder), Maven resolves reactor
    dependencies to target/classes directories instead of JAR files.
    The jandex-maven-plugin's ArchiveScanner only accepts files (JARs),
    causing an IllegalStateException: "Archive ... is not a file".
    
    Fix by:
    - Moving jandex and metadata generation phases from generate-resources
      to prepare-package, ensuring reactor dependencies have JARs available
    - Making classExistsInDependency handle both JARs and directories
      for reactor-resolved artifacts
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 test-infra/camel-test-infra-all/pom.xml            |  4 ++--
 .../CamelTestInfraGenerateMetadataMojo.java        | 24 ++++++++++++++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/test-infra/camel-test-infra-all/pom.xml 
b/test-infra/camel-test-infra-all/pom.xml
index b47468b269c3..784542ed05cb 100644
--- a/test-infra/camel-test-infra-all/pom.xml
+++ b/test-infra/camel-test-infra-all/pom.xml
@@ -305,7 +305,7 @@
                         <goals>
                             <goal>jandex</goal>
                         </goals>
-                        <phase>generate-resources</phase>
+                        <phase>prepare-package</phase>
                         <configuration>
                             <fileSets>
                                 <fileSet>
@@ -611,7 +611,7 @@
                         <goals>
                             <goal>test-infra-generate-metadata</goal>
                         </goals>
-                        <phase>generate-resources</phase>
+                        <phase>prepare-package</phase>
                     </execution>
                 </executions>
             </plugin>
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CamelTestInfraGenerateMetadataMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CamelTestInfraGenerateMetadataMojo.java
index 90a590364580..130892231f5a 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CamelTestInfraGenerateMetadataMojo.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CamelTestInfraGenerateMetadataMojo.java
@@ -83,7 +83,7 @@ public class CamelTestInfraGenerateMetadataMojo extends 
AbstractGeneratorMojo {
             try {
                 // Search for target class in the project transitive artifacts 
to retrieve maven coordinates
                 for (Artifact artifact : project.getArtifacts()) {
-                    if (classExistsInJarFile(
+                    if (classExistsInDependency(
                             targetClass.substring(targetClass.lastIndexOf(".") 
+ 1),
                             artifact.getFile())) {
                         
infrastructureServiceModel.setVersion(artifact.getVersion());
@@ -127,7 +127,10 @@ public class CamelTestInfraGenerateMetadataMojo extends 
AbstractGeneratorMojo {
         }
     }
 
-    private boolean classExistsInJarFile(String className, File dependency) 
throws IOException {
+    private boolean classExistsInDependency(String className, File dependency) 
throws IOException {
+        if (dependency.isDirectory()) {
+            return classExistsInDirectory(className, dependency);
+        }
         try (JarFile jarFile = new JarFile(dependency)) {
             Enumeration<JarEntry> e = jarFile.entries();
             while (e.hasMoreElements()) {
@@ -140,6 +143,23 @@ public class CamelTestInfraGenerateMetadataMojo extends 
AbstractGeneratorMojo {
         }
     }
 
+    private boolean classExistsInDirectory(String className, File directory) {
+        File[] files = directory.listFiles();
+        if (files == null) {
+            return false;
+        }
+        for (File file : files) {
+            if (file.isDirectory()) {
+                if (classExistsInDirectory(className, file)) {
+                    return true;
+                }
+            } else if (file.getName().contains(className)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private class InfrastructureServiceModel {
         private String service;
         private String description;

Reply via email to