desruisseaux commented on code in PR #3392:
URL: https://github.com/apache/maven-surefire/pull/3392#discussion_r3613825602
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java:
##########
@@ -1457,6 +1477,45 @@ private ResolvePathResultWrapper
findModuleDescriptor(File jdkHome, File buildPa
}
}
+ /**
+ * Whether the main build output uses the Maven 4 Module Source Hierarchy
layout:
+ * no module-info.class at the root of the build output directory, but at
least one
+ * immediate subdirectory containing one ({@code
target/classes/<module>/}).
+ * A classic modular build (module-info.class at the root) is never
nested, even if
+ * a subdirectory happens to share the module's name.
+ *
+ * @param buildPath the build output directory (e.g., target/classes)
+ * @return {@code true} for the nested module source hierarchy layout
+ */
+ private static boolean isNestedModuleLayout(File buildPath) {
+ return buildPath != null
+ && buildPath.isDirectory()
+ && !new File(buildPath, "module-info.class").exists()
+ && findNestedModuleDescriptor(buildPath) != null;
+ }
+
+ /**
+ * Searches for a module-info.class in immediate subdirectories of the
given directory.
+ * This supports Maven 4 Module Source Hierarchy where compiled classes
are placed
+ * in {@code target/classes/<module>/} instead of directly in {@code
target/classes/}.
+ *
+ * @param buildPath the build output directory (e.g., target/classes)
+ * @return the subdirectory containing module-info.class, or null if not
found
+ */
+ private static File findNestedModuleDescriptor(File buildPath) {
+ File[] subdirs = buildPath.listFiles(File::isDirectory);
+ if (subdirs != null) {
+ // deterministic pick independent of filesystem iteration order
+ Arrays.sort(subdirs);
Review Comment:
Picking the first module in alphabetical order is still arbitrary. I suggest
to rather throw an exception if more than one sub-directory has a
`module-info.class` file.
--
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]