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


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java:
##########
@@ -3361,13 +3362,28 @@ File createSurefireBootDirectoryInBuild() {
     }
 
     File createSurefireBootDirectoryInTemp() {
+        String tempDir = getTempDir();
+        if (isTempDirPath(tempDir)) {
+            File tmp = new File(tempDir);
+            if (!tmp.isAbsolute()) {
+                tmp = new File(getProjectBuildDirectory(), tempDir);
+            }
+            //noinspection ResultOfMethodCallIgnored
+            tmp.mkdirs();
+            return tmp;

Review Comment:
   When `tempDir` is treated as an explicit directory, `tmp.mkdirs()` result is 
ignored and the method returns `tmp` even if creation fails or if the path 
exists as a regular file. That can later cause confusing failures when the fork 
tries to create files under a non-directory. Consider verifying 
`tmp.isDirectory()` after `mkdirs()` (or handling `mkdirs()==false`) and 
falling back to `createSurefireBootDirectoryInBuild()` or failing fast with a 
clear error.



##########
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java:
##########
@@ -816,6 +816,21 @@ public void shouldExistTmpDirectory() throws IOException {
                 .isDirectory();
     }
 
+    @Test
+    public void shouldUseAbsoluteTmpDirectory() throws IOException {
+        File targetDir = Files.createTempDirectory(tempFolder, 
"target").toFile();
+        File absoluteTempDir = tempFolder.resolve("surefire-tmp").toFile();
+
+        Mojo mojo = new Mojo();
+        mojo.setProjectBuildDirectory(targetDir);
+        mojo.setTempDir(absoluteTempDir.getAbsolutePath());
+
+        File bootDir = mojo.createSurefireBootDirectoryInTemp();
+
+        assertThat(bootDir).isDirectory();
+        
assertThat(bootDir.getCanonicalFile()).isEqualTo(absoluteTempDir.getCanonicalFile());
+    }
+
     @Test

Review Comment:
   The new behavior also treats relative `tempDir` values containing path 
separators (e.g. "surefire/tmp") as explicit directories. There’s no test 
covering that branch yet; adding a unit test would help ensure the 
separator-detection logic keeps working (and that relative paths resolve under 
`project.build.directory` on Windows rather than being passed as a temp-dir 
prefix).
   



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