javamaven-2plexus

How do I stop my command-line arguments being escaped in a maven plugin?


I have a plugin that uses the Plexus Commandline to invoke some external process and capture the output. One of the arguments is in a funny format with spaces and quotes, e.g. --range:"25 Aug 2008"-"04 Aug 2009". I have no way to change the required format of the argument, but Plexus detects the spaces in the argument and wraps the whole thing in quotes.

So

call --range:"25 Aug 2008"-"04 Aug 2009"

becomes

call "--range:"25 Aug 2008"-"04 Aug 2009""

and the invocation fails.

Can I make plexus stop escaping the arguments?


Solution

  • The Commandline object uses a Shell to interact with the local environment, you can configure the Shell to override the default escaping process to not escape any quotes:

    Commandline cl = new Commandline("call");
    commandline.getShell().setQuotedArgumentsEnabled(false);
    

    Be aware that this means that none of the arguments will be enquoted, so use it with care!