[
https://issues.apache.org/jira/browse/SUREFIRE-2159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tamas Cservenak updated SUREFIRE-2159:
--------------------------------------
Description:
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}
was:
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)
> 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)