desruisseaux commented on code in PR #3394:
URL: https://github.com/apache/maven-surefire/pull/3394#discussion_r3614342788


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +238,73 @@ File createArgsFile(
             return surefireArgs;
         }
     }
+
+    /**
+     * Searches for module-info-patch.args generated by maven-compiler-plugin 
4.x.
+     * The file is expected at {@code 
target/test-classes/META-INF/maven/module-info-patch.args}
+     * or within a module subdirectory at
+     * {@code 
target/test-classes/<module>/META-INF/maven/module-info-patch.args}.
+     *
+     * @param patchFile the test classes directory (may be the module 
subdirectory)
+     * @return the module-info-patch.args file, or null if not found
+     */
+    @Nullable
+    private static File findModuleInfoPatchArgs(File patchFile) {
+        // Direct location: 
target/test-classes/<module>/META-INF/maven/module-info-patch.args
+        File argsFile = new File(patchFile, 
"META-INF/maven/module-info-patch.args");
+        if (argsFile.isFile()) {
+            return argsFile;
+        }
+        // Parent location: 
target/test-classes/META-INF/maven/module-info-patch.args
+        File parent = patchFile.getParentFile();
+        if (parent != null) {
+            argsFile = new File(parent, 
"META-INF/maven/module-info-patch.args");
+            if (argsFile.isFile()) {
+                return argsFile;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Reads the module-info-patch.args file and appends its --add-exports and 
--add-opens
+     * directives to the args builder. The --add-reads directive is handled by 
surefire itself
+     * (always adds ALL-UNNAMED) to avoid referencing modules that may be on 
the classpath
+     * rather than the module-path.
+     *
+     * @param args the args builder to append to
+     * @param patchArgs the module-info-patch.args file
+     * @param moduleName the module name for the fallback --add-reads
+     * @throws IOException if the file cannot be read
+     */
+    private static void appendModuleInfoPatchArgs(StringBuilder args, File 
patchArgs, String moduleName)
+            throws IOException {
+        try (BufferedReader reader = new BufferedReader(new 
FileReader(patchArgs))) {
+            String line;

Review Comment:
   `Files.newBufferedReader(Path)` is sufficient as it already defaults to 
UTF-8 (contrarily to the `FileReader` constructor).



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