Copilot commented on code in PR #3395:
URL: https://github.com/apache/maven-surefire/pull/3395#discussion_r3623583465


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ModuleInfoPatchArgsFile.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.surefire;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import static java.util.Collections.unmodifiableList;
+import static java.util.Collections.unmodifiableSet;
+
+/**
+ * The runtime handoff file {@code META-INF/maven/module-info-patch.args} 
written by
+ * maven-compiler-plugin 4.x from {@code module-info-patch.maven}. It contains 
the Java
+ * Modules options the compiler used for the test compilation (one option per 
line, value
+ * either on the same line separated by whitespace or on the following line).
+ *
+ * @since 3.6.0
+ */
+public final class ModuleInfoPatchArgsFile {
+    public static final String RELATIVE_PATH = 
"META-INF/maven/module-info-patch.args";
+
+    private final File file;
+    private final List<String> lines;
+    private final Set<String> addedModules;
+
+    private ModuleInfoPatchArgsFile(File file, List<String> lines, Set<String> 
addedModules) {
+        this.file = file;
+        this.lines = lines;
+        this.addedModules = addedModules;
+    }
+
+    /**
+     * Loads the handoff file from the test output directory.
+     *
+     * @param testClassesDirectory the test output directory (e.g. 
target/test-classes)
+     * @return the parsed file, or null if it does not exist
+     * @throws IOException if the file exists but cannot be read
+     */
+    public static ModuleInfoPatchArgsFile load(File testClassesDirectory) 
throws IOException {
+        if (testClassesDirectory == null || 
!testClassesDirectory.isDirectory()) {
+            return null;
+        }
+        return parse(new File(testClassesDirectory, RELATIVE_PATH));
+    }
+
+    /**
+     * Parses the given handoff file.
+     *
+     * @param file the module-info-patch.args file
+     * @return the parsed file, or null if it does not exist
+     * @throws IOException if the file exists but cannot be read
+     */
+    public static ModuleInfoPatchArgsFile parse(File file) throws IOException {
+        if (file == null || !file.isFile()) {
+            return null;
+        }
+
+        List<String> lines = new ArrayList<>();
+        Set<String> addedModules = new LinkedHashSet<>();
+        try (BufferedReader reader = Files.newBufferedReader(file.toPath())) {

Review Comment:
   Files.newBufferedReader(file.toPath()) uses the platform default charset, 
while the handoff file is treated as UTF-8 elsewhere in tests. Using an 
explicit charset avoids platform-dependent parsing (especially if comments or 
paths ever contain non-ASCII).



##########
surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java:
##########
@@ -76,8 +76,8 @@ public final class MavenLauncher {
         this.resourceName = resourceName;
         this.suffix = suffix != null ? suffix : "";
         this.cli = cli == null ? null : cli.clone();
-        // by default use embedded mode
-        this.forkJvm = false;
+        // Use forked mode for Maven 4+ (Embedded3xLauncher only supports 
Maven 3.x)
+        this.forkJvm = isMaven4Plus();

Review Comment:
   isMaven4Plus() detection logic is duplicated here and in multiple IT classes 
(Surefire3345*/3393*/3090*). Consider extracting a single shared helper (e.g., 
a protected method on AbstractJava9PlusIT or a package-private utility) to 
avoid the checks diverging over time.



##########
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java:
##########
@@ -235,7 +240,8 @@ public void shouldHaveStartupConfigForModularClasspath() 
throws Exception {
 
             verify(mojo, times(1)).effectiveIsEnableAssertions();
             verify(mojo, times(1)).isChildDelegation();
-            verify(mojo, times(1)).getTestClassesDirectory();
+            // once for the patch directory, once probing for 
module-info-patch.args
+            verify(mojo, times(2)).getTestClassesDirectory();

Review Comment:
   This test asserts the exact number of getTestClassesDirectory() calls, which 
is an internal detail and makes the test brittle when the implementation adds 
legitimate additional lookups (e.g., nested module probing). Prefer asserting 
it was called at least once instead of an exact count.



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