You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Tamas Cservenak (Jira)" <ji...@apache.org> on 2023/04/13 08:14:00 UTC

[jira] [Created] (SUREFIRE-2159) Better test temp dir managemenent

Tamas Cservenak created SUREFIRE-2159:
-----------------------------------------

             Summary: Better test temp dir managemenent
                 Key: SUREFIRE-2159
                 URL: https://issues.apache.org/jira/browse/SUREFIRE-2159
             Project: Maven Surefire
          Issue Type: Improvement
          Components: Maven Surefire Plugin
            Reporter: Tamas Cservenak


How to achieve to put UTs temporary directory under {{target/something}}?

Currently, there is one way to do it:
{noformat}
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <argLine>-Xmx128m</argLine>
            <redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile>
            <systemPropertyVariables>
              <java.io.tmpdir>${project.build.directory}/surefire-tmp</java.io.tmpdir>
            </systemPropertyVariables>
          </configuration>
        </plugin>
{noformat}

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:
{noformat}
Files.createDirectories(Paths.get(System.getProperty("java.io.tmpdir"))); // hack for Surefire
{noformat}

As otherwise, all Java {{Files.createTempFile}} will throw like this:
{noformat}
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)
...
{noformat}

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)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)