You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "officialasishkumar (via GitHub)" <gi...@apache.org> on 2026/05/25 03:13:04 UTC
[PR] [Issue-3349] Handle absolute surefire tempDir on Windows [maven-surefire]
officialasishkumar opened a new pull request, #3359:
URL: https://github.com/apache/maven-surefire/pull/3359
Fixes #3349.
`tempDir` values that are absolute paths, or relative paths with directory separators, are now treated as explicit directories before creating the fork boot directory. Simple names still use the existing `Files.createTempDirectory(prefix)` behavior.
Verification:
- `/tmp/apache-maven-3.9.11/bin/mvn -pl maven-surefire-common -am -DskipTests -Dmaven.build.cache.enabled=false install`
- `/tmp/apache-maven-3.9.11/bin/mvn -pl maven-surefire-common -Dtest=AbstractSurefireMojoTest -Drat.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Dspotless.check.skip=true -Danimal.sniffer.skip=true -Dmaven.build.cache.enabled=false test`
Following this checklist to help us incorporate your
contribution quickly and easily:
- [x] Each commit in the pull request should have a meaningful subject line and body.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Run `mvn clean install` to make sure basic checks pass. A more thorough check will
be performed on your pull request automatically.
- [ ] You have run the integration tests successfully (`mvn -Prun-its clean install`).
If your pull request is about ~20 lines of code you don't need to sign an
[Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
you have to acknowledge this by using the following check-box.
- [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
- [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Issue-3349] Handle absolute surefire tempDir on Windows [maven-surefire]
Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on code in PR #3359:
URL: https://github.com/apache/maven-surefire/pull/3359#discussion_r3297169516
##########
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;
+ }
+
try {
- return Files.createTempDirectory(getTempDir()).toFile();
- } catch (IOException e) {
+ return Files.createTempDirectory(tempDir).toFile();
+ } catch (IOException | IllegalArgumentException e) {
return createSurefireBootDirectoryInBuild();
}
}
+ private static boolean isTempDirPath(String tempDir) {
+ return new File(tempDir).isAbsolute() || tempDir.indexOf('/') >= 0 || tempDir.indexOf('\\') >= 0;
Review Comment:
not sure to understand the logic here to say this directory is temporary?
so a path such `/home/uid/` is temporary?
can you document you use case?
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Issue-3349] Handle absolute surefire tempDir on Windows [maven-surefire]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org