apache / apache/maven-surefire
[SUREFIRE-2159] Better test temp dir managemenent
- Dominant language
- Java
- Stars
- 461
- Forks
- 588
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 19
Description
**[Tamas Cservenak](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cstamas)** opened **[SUREFIRE-2159](https://issues.apache.org/jira/browse/SUREFIRE-2159?redirect=false)** and commented
How to achieve to put UTs temporary directory under `target/something`?
Currently, there is one way to do it:
```
org.apache.maven.plugins
maven-surefire-plugin
${project.build.directory}/surefire-tmp
```
This works as expected, BUT the temp directory DOES NOT EXISTS, so one have to sprinkle UTs (each, unless you lock down test run ordering) with code like this:
```
Files.createDirectories(Paths.get(System.getProperty("java.io.tmpdir"))); // hack for Surefire
```
As otherwise, all Java `Files.createTempFile` will throw like this:
```
java.nio.file.NoSuchFileException: /home/runner/work/maven-resolver/maven-resolver/maven-resolver-impl/target/surefire-tmp/artifact5917045446313461619tmp
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
at java.base/java.nio.file.Files.newByteChannel(Files.java:371)
at java.base/java.nio.file.Files.createFile(Files.java:648)
at java.base/java.nio.file.TempFileHelper.create(TempFileHelper.java:137)
at java.base/java.nio.file.TempFileHelper.createTempFile(TempFileHelper.java:160)
at java.base/java.nio.file.Files.createTempFile(Files.java:913)
at org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessorTest.prepareSubject(TrustedChecksumsArtifactResolverPostProcessorTest.java:77)
...
```
So, the idea: just like existing [tempDir](https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#tempdir) (that is somewhat misleading, as it says "Relative path to temporary-surefire-boot directory containing internal Surefire temporary files.") add some new property that would:
* set java.tmp.dir on provider/forked JVM
* create the directory (make sure it exists)
As then, config could become simpler, and no "sprinkling" of mkdirs would be needed as surefire would handle it:
```
org.apache.maven.plugins
maven-surefire-plugin
${project.build.directory}/surefire-tmp
```
---
No further details from [SUREFIRE-2159](https://issues.apache.org/jira/browse/SUREFIRE-2159?redirect=false)
Contributor guide
Research direction
Start by tracing how maven-surefire-plugin configuration reaches the provider and forked JVM, using the existing tempDir handling as the comparison point. Reproduce the failure from TrustedChecksumsArtifactResolverPostProcessorTest.prepareSubject at line 77 with java.io.tmpdir set to a missing directory. Done means a providerTempDir-style setting sets java.io.tmpdir and creates the directory before tests need it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100