ascheman commented on code in PR #3392:
URL: https://github.com/apache/maven-surefire/pull/3392#discussion_r3613826632


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +240,76 @@ 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}.
+     *

Review Comment:
   Correct — empirically the file only ever appears once per project at 
`target/test-classes/META-INF/maven/module-info-patch.args` (observed for both 
the classic layout and the module source hierarchy). The misleading part was my 
comment, not the lookup: the patch directory handed to the fork configuration 
is `target/test-classes/<module>` in a module source hierarchy build, which is 
why the code checks the given directory (classic layout: it is the test output 
directory itself) and its parent (hierarchy). Comments fixed in d05524c7f.



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +240,76 @@ 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

Review Comment:
   Fixed together with the above — the comment now describes the single 
per-project file.



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +240,76 @@ 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) {

Review Comment:
   It is not a workaround for #3394 — the parent lookup covers the nested patch 
directory of the module source hierarchy case (see the thread above); 
documented now in d05524c7f.



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +240,76 @@ 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 directives (e.g. 
--add-exports,
+     * --add-opens) to the args builder. Exceptions are --add-reads and 
--add-modules, which
+     * are skipped: they may reference named modules that surefire places on 
the classpath
+     * rather than the module path. Surefire appends its own
+     * {@code --add-reads <module>=ALL-UNNAMED} instead, and {@code 
--add-modules
+     * ALL-MODULE-PATH} is generated by the caller.

Review Comment:
   Yes — tracked in #3090; implementation is in progress on a branch stacked on 
this PR and #3394 (test-scope dependencies move to the module path, the file is 
passed through verbatim, and this skip disappears).



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +240,76 @@ 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 directives (e.g. 
--add-exports,
+     * --add-opens) to the args builder. Exceptions are --add-reads and 
--add-modules, which
+     * are skipped: they may reference named modules that surefire places on 
the classpath
+     * rather than the module path. Surefire appends its own
+     * {@code --add-reads <module>=ALL-UNNAMED} instead, and {@code 
--add-modules
+     * ALL-MODULE-PATH} is generated by the caller.
+     *
+     * @param args the args builder to append to
+     * @param patchArgs the module-info-patch.args file
+     * @param moduleName the module name for surefire's own --add-reads
+     * @throws IOException if the file cannot be read
+     */
+    private static void appendModuleInfoPatchArgs(StringBuilder args, File 
patchArgs, String moduleName)
+            throws IOException {
+        // explicit charset: the compiler writes the args file as UTF-8, the 
platform default may differ
+        try (BufferedReader reader = 
Files.newBufferedReader(patchArgs.toPath(), StandardCharsets.UTF_8)) {

Review Comment:
   Nice, TIL — simplified to `Files.newBufferedReader(Path)` in d05524c7f.



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