You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
ferstl
changed the title
Wrong relative paths after using MavenJUnitTestRunner
Wrong relative paths after using MavenJUnitTestRunner
Aug 25, 2016
ferstl
added a commit
to ferstl/depgraph-maven-plugin
that referenced
this issue
Aug 28, 2016
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.The text was updated successfully, but these errors were encountered: