I get wrong relative paths when using java.io.File#toPath()after executing tests with MavenJUnitTestRunner on Windows. For example, this call should return a path relative to the working directory, e.g. C:\Users\me\my-project:
new File(".").toPath().toAbsolutePath();
However, it returns a path relative to the directory structure of a previous plugin test, e.g. C:\Users\me\my-project\target\test-projects\MyPluginTest_graph[3.3.9]_my-test-project.
I think the reason for this behavior is that Embedded3xLauncher sets the user.dir system property. In case the default FileSystem has not been initialized up to this point (e.g. by creating a new File object or calling FileSystems.getDefault()), it will use the modified user.dir property as default directory for the whole lifetime of the JVM. This leads to wrong results in all subsequent code that uses relative paths.
Probably calling FileSystems.getDefault() right before setting the user.dir property would solve this problem. I am not sure if this is also a problem on other operating systems.
I get wrong relative paths when using
java.io.File#toPath()
after executing tests withMavenJUnitTestRunner
on Windows. For example, this call should return a path relative to the working directory, e.g.C:\Users\me\my-project
:However, it returns a path relative to the directory structure of a previous plugin test, e.g.
C:\Users\me\my-project\target\test-projects\MyPluginTest_graph[3.3.9]_my-test-project
.I think the reason for this behavior is that
Embedded3xLauncher
sets theuser.dir
system property. In case the defaultFileSystem
has not been initialized up to this point (e.g. by creating a newFile
object or callingFileSystems.getDefault()
), it will use the modifieduser.dir
property as default directory for the whole lifetime of the JVM. This leads to wrong results in all subsequent code that uses relative paths.Probably calling
FileSystems.getDefault()
right before setting theuser.dir
property would solve this problem. I am not sure if this is also a problem on other operating systems.