Re: Absolute and relative paths in plugins and descriptors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Absolute and relative paths in plugins and descriptors

rfscholte
I'd prefer to switch to Path, and in this case use Path.resolve
You should add that to the test.
I agree that a path starting with "/" should be interpreted as an absolute path, and AFAIK the warning is there already for ages so I don't mind changing the behavior.

thanks,
Robert
On 1-1-2020 23:26:00, Mark Struberg <[hidden email]> wrote:
Hi lords and ladies!

I try to get my head around the ticket MASSEMBLY-775.
It is related to MASSEMBLY-746 and MASSEMBLY-665.

The problem is basically that a reference to /somedirectory is interpreted as absolute path on *nix and as relative path on Win*.

And sometimes we have code of the form

File destDir = new File(dest);
if (! destDir.isAbsolute()) {
destDir = new File(basedir destDir);
}

And thus we treat e.g. /src/test/my.txt as relative to ${project.basedir} on Windows but as an absolute path in OSX and Linux for example. But Maven projects should by default be perfectly portable on different operating systems.

It get's a bit more complicated when also taking mingw and cygwin into consideration.

I wrote a tiny class and tested it on multiple systems.

public class Test {
public static void main(String[] args) {
java.lang.System.out.println("path: " + new java.io.File(args[0]).getAbsolutePath());
}
}

Feeding /test as parameter gives the following values:
OSX: /test
Linux: /test
Windows CMD: c:\test
Windows mingw: c:\opt\GIT\test
Windows Powershell: c\test

I don't have cygwin at hand. Anyone?

It looks like using / as detector for an absolute file *in addition* to File#isAbsolute() would be the most porbable way to handle it?
At least if we otherwise concat it to our basedir like we did in maven-assembly-plugin.

Wdyt?

LieGrue,
strub



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]