You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Mark Struberg <st...@yahoo.de.INVALID> on 2020/01/01 22:25:41 UTC

Absolute and relative paths in plugins and descriptors

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 <dest>/somedirectory</dest> 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. <dest>/src/test/my.txt</dest> 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    <- a bit unexpected tbh...
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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Absolute and relative paths in plugins and descriptors

Posted by Mark Struberg <st...@yahoo.de.INVALID>.
Yes, will go down this route. 

Fun side note: that warning was so far mostly applied to the outputDirectory part. But this is just the path INSIDE the zip. So most of the warnings have been pretty much useless ;)

Will continue to work on this. Probably we might also extract the path handling out into maven-shared-utils even. Let's see.

LieGrue,
strub


> Am 02.01.2020 um 11:33 schrieb Robert Scholte <rf...@apache.org>:
> 
> 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 <st...@yahoo.de.invalid> 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: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Absolute and relative paths in plugins and descriptors

Posted by Robert Scholte <rf...@apache.org>.
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 <st...@yahoo.de.invalid> 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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org