takari / takari-plugin-testing-project

Maven Plugin Testing Framework
Eclipse Public License 1.0
27 stars 19 forks source link

Wrong relative paths after using MavenJUnitTestRunner #14

Open ferstl opened 8 years ago

ferstl commented 8 years ago

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.