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

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

    [ https://issues.apache.org/jira/browse/SUREFIRE-2159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17711760#comment-17711760 ] 

Guillaume Nodet commented on SUREFIRE-2159:
-------------------------------------------

Ideally, each test would have its own temp dir and would not use system properties if possible. 
Junit extensions can be used to create temp directories for tests.

> 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
>            Priority: Major
>
> 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>
>             <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)
> As then, config could become simpler, and no "sprinkling" of mkdirs would be needed as surefire would handle it:
> {noformat}
>         <plugin>
>           <groupId>org.apache.maven.plugins</groupId>
>           <artifactId>maven-surefire-plugin</artifactId>
>           <configuration>
>             <providerTempDir>${project.build.directory}/surefire-tmp</providerTempDir>
>           </configuration>
>         </plugin>
> {noformat}



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