You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by cowwoc <co...@bbs.darktech.org> on 2010/07/01 06:26:17 UTC

Passing ${basedir} into Exec plugin

Hi,

I need to invoke an external command using the Exec plugin, with one of the
arguments equal to "${basedir}/target". The problem is that under Windows
this expands to "c:\\temp\\project/target" because ${basedir} uses
Windows-style slashes whereas the rest of the argument uses Unix-style
slashes. Needless to say, the external program fails to run. If I switch the
slash-style to "${basedir}\\target" then it will fail under Unix.

When Maven is passed ${basedir} into arguments it *knows* are directories
it's smart about fixing the slashes but in this case it has no way of
knowing that the command-line argument refers to a path. What can I do to
ensure that the argument contains a consistent slash-style?

Thank you,
Gili
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p512272.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by Dan Tran <da...@gmail.com>.
lookup maven profile where you can configure your properties to
${basedir}\\target when on windows platform

-D

On Wed, Jun 30, 2010 at 9:26 PM, cowwoc <co...@bbs.darktech.org> wrote:
>
> Hi,
>
> I need to invoke an external command using the Exec plugin, with one of the
> arguments equal to "${basedir}/target". The problem is that under Windows
> this expands to "c:\\temp\\project/target" because ${basedir} uses
> Windows-style slashes whereas the rest of the argument uses Unix-style
> slashes. Needless to say, the external program fails to run. If I switch the
> slash-style to "${basedir}\\target" then it will fail under Unix.
>
> When Maven is passed ${basedir} into arguments it *knows* are directories
> it's smart about fixing the slashes but in this case it has no way of
> knowing that the command-line argument refers to a path. What can I do to
> ensure that the argument contains a consistent slash-style?
>
> Thank you,
> Gili
> --
> View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p512272.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: Passing ${basedir} into Exec plugin

Posted by lukewpatterson <lu...@gmail.com>.

cowwoc wrote:
> 
> ... one of the arguments equal to "${basedir}/target". 
> 

maybe I'm missing something here, but why won't ${project.build.directory}
work?
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p696566.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by Dan Tran <da...@gmail.com>.
ah, that is really overkill :-)

On Thu, Jul 1, 2010 at 12:08 AM, Andreas Sewe
<se...@st.informatik.tu-darmstadt.de> wrote:
> Hi,
>
>> I need to invoke an external command using the Exec plugin, with one of
>> the
>> arguments equal to "${basedir}/target". The problem is that under Windows
>> this expands to "c:\\temp\\project/target" because ${basedir} uses
>> Windows-style slashes whereas the rest of the argument uses Unix-style
>> slashes. Needless to say, the external program fails to run. If I switch
>> the
>> slash-style to "${basedir}\\target" then it will fail under Unix.
>
> Does using ${file.separator} instead of slashes work? After all, these
> standard Java properties are available for interpolation in the POM.
>
> Using a profile as Dan suggested strikes me as a bit of overkill for the
> problem at hand.
>
> Best wishes,
>
> Andreas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: Passing ${basedir} into Exec plugin

Posted by lukewpatterson <lu...@gmail.com>.

cowwoc wrote:
> 
> That works (using quotes) but based on what you wrote above I believe this
> is a bug.
> 
> 1. I am expecting this to work without quotes (since my path does not
> contain any spaces)
> 2. I am expecting to be able to put anything inside the quotes
> 
> Do you agree? Should I file a bug report?
> 

I think so.

http://jira.codehaus.org/browse/MEXEC

Minimally, the bug includes the fact that the "escaping" behavior isn't
documented.

Additionally, if due to the implementation of the escaping behavior, certain
strings or expressions can't be passed as arguments, then that needs to be
fixed too.

Either way, might as well file the bug so you can leave some clues to follow
for others experiencing the same obstacle.
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p704257.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by cowwoc <co...@bbs.darktech.org>.

lukewpatterson wrote:
> 
> ok, and then the plugin does some massaging, and '\' is an escape
> character
> 
> http://fisheye.codehaus.org/browse/mojo/trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java?r=HEAD#l155
> 
> try (with the quotes)
> 
> "${basedir}${file.separator}target${file.separator}lib"
> 
> interestingly though,
> 
> "\" or "\a" or "a\"
> 
> throw error "args contains not properly formatted string"
> 
> but "a\a" is ok
> 
> So looks like you can get by if you use the quotes, and then hope the
> characters touching the quotes aren't a '\'.  I didn't test for nested
> quotes.
> 

That works (using quotes) but based on what you wrote above I believe this
is a bug.

1. I am expecting this to work without quotes (since my path does not
contain any spaces)
2. I am expecting to be able to put anything inside the quotes

Do you agree? Should I file a bug report?

Thanks,
Gili
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p699142.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by lukewpatterson <lu...@gmail.com>.

lukewpatterson wrote:
> 
> 
> cowwoc wrote:
>> 
>> ... this looks like a bug in the plugin. What do you think?
>> 
> 
> the parameters are resolved before the plugin even sees them though,
> right?
> 

ok, and then the plugin does some massaging, and '\' is an escape character

http://fisheye.codehaus.org/browse/mojo/trunk/mojo/exec-maven-plugin/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java?r=HEAD#l155

try (with the quotes)

"${basedir}${file.separator}target${file.separator}lib"

interestingly though,

"\" or "\a" or "a\"

throw error "args contains not properly formatted string"

but "a\a" is ok

So looks like you can get by if you use the quotes, and then hope the
characters touching the quotes aren't a '\'.  I didn't test for nested
quotes.
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p696586.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by lukewpatterson <lu...@gmail.com>.

lukewpatterson wrote:
> 
> 
> cowwoc wrote:
>> 
>> ... one of the arguments equal to "${basedir}/target". 
>> 
> 
> maybe I'm missing something here, but why won't ${project.build.directory}
> work?
> 

nevermind, I see what you are saying now, you want a general way to create a
String parameter value containing proper file separators


cowwoc wrote:
> 
> ... this looks like a bug in the plugin. What do you think?
> 

the parameters are resolved before the plugin even sees them though, right?
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p696574.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by cowwoc <co...@bbs.darktech.org>.

cowwoc wrote:
> 
> 
> Andreas Sewe wrote:
>> 
>> Hi,
>> 
>>> I need to invoke an external command using the Exec plugin, with one of
>>> the
>>> arguments equal to "${basedir}/target". The problem is that under
>>> Windows
>>> this expands to "c:\\temp\\project/target" because ${basedir} uses
>>> Windows-style slashes whereas the rest of the argument uses Unix-style
>>> slashes. Needless to say, the external program fails to run. If I switch
>>> the
>>> slash-style to "${basedir}\\target" then it will fail under Unix.
>> 
>> Does using ${file.separator} instead of slashes work? After all, these 
>> standard Java properties are available for interpolation in the POM.
>> 
>> Using a profile as Dan suggested strikes me as a bit of overkill for the 
>> problem at hand.
>> 
>> Best wishes,
>> 
>> Andreas
>> 
> 
> Hi Andreas,
> 
> Surprisingly, this doesn't work. Please take a look at the attached log
> file from maven-exec-plugin: 
> http://maven.40175.n5.nabble.com/file/n696563/exec-output.txt
> exec-output.txt 
> 
> At first glance, this looks like a bug in the plugin. What do you think?
> 
> Thanks,
> Gili
> 

Here is a cleaned up log without -Dfoo=${file.separator}. You should be
focusing on java.library.path in this log.

http://maven.40175.n5.nabble.com/file/n696569/exec-output2.txt
exec-output2.txt 

Gili
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p696569.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by cowwoc <co...@bbs.darktech.org>.

Andreas Sewe wrote:
> 
> Hi,
> 
>> I need to invoke an external command using the Exec plugin, with one of
>> the
>> arguments equal to "${basedir}/target". The problem is that under Windows
>> this expands to "c:\\temp\\project/target" because ${basedir} uses
>> Windows-style slashes whereas the rest of the argument uses Unix-style
>> slashes. Needless to say, the external program fails to run. If I switch
>> the
>> slash-style to "${basedir}\\target" then it will fail under Unix.
> 
> Does using ${file.separator} instead of slashes work? After all, these 
> standard Java properties are available for interpolation in the POM.
> 
> Using a profile as Dan suggested strikes me as a bit of overkill for the 
> problem at hand.
> 
> Best wishes,
> 
> Andreas
> 

Hi Andreas,

Surprisingly, this doesn't work. Please take a look at the attached log file
from maven-exec-plugin: 
http://maven.40175.n5.nabble.com/file/n696563/exec-output.txt
exec-output.txt 

At first glance, this looks like a bug in the plugin. What do you think?

Thanks,
Gili
-- 
View this message in context: http://maven.40175.n5.nabble.com/Passing-basedir-into-Exec-plugin-tp512272p696563.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Passing ${basedir} into Exec plugin

Posted by Andreas Sewe <se...@st.informatik.tu-darmstadt.de>.
Hi,

> I need to invoke an external command using the Exec plugin, with one of the
> arguments equal to "${basedir}/target". The problem is that under Windows
> this expands to "c:\\temp\\project/target" because ${basedir} uses
> Windows-style slashes whereas the rest of the argument uses Unix-style
> slashes. Needless to say, the external program fails to run. If I switch the
> slash-style to "${basedir}\\target" then it will fail under Unix.

Does using ${file.separator} instead of slashes work? After all, these 
standard Java properties are available for interpolation in the POM.

Using a profile as Dan suggested strikes me as a bit of overkill for the 
problem at hand.

Best wishes,

Andreas

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