[ 
https://issues.apache.org/jira/browse/MNG-7217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17458497#comment-17458497
 ] 

Maarten Mulders commented on MNG-7217:
--------------------------------------

I've spent quite some time investigating this ticket, and especially the 
handling of our {{--define}} / {{-D}} option. Our {{-define}} used to accept 
various styles:
 # {{-Dx=y}} : precisely the same as the JVM does
 # {{--define x=y}} : this has recently [been 
removed|https://github.com/apache/maven/commit/f43f9f8a3bcd5167e75b38c930df1d9ac9bbfa08])
 # {{--define}}{{ }}{{ -- x}} : no value supplied, we interpreted it as 
{{-define x=true}} but it has recently [been 
removed|https://github.com/apache/maven/commit/f43f9f8a3bcd5167e75b38c930df1d9ac9bbfa08])
 # {{-D x=y}}
 # {{-Dx}} : no value supplied, we interpret it as {{-Dx=true}}
 # {{-D x}} : no value supplied, we interpret it as {{-D x=true}}

The fact that all of this used to work pretty much surprises me. Commons CLI, 
the library we use for parsing CLI arguments, doesn't explicitly mention all of 
these variants. In fact, they only mention style 1, and style 4 and 5 seems to 
work although not explicitly mentioned in their docs.

The Java Virtual Machine, on the other hand, supports style 1 and style 5.

In this ticket, we wanted to have Commons CLI updated to the latest version 
_and_ to remove some deprecated classes we use from that library. We used to do 
the parsing of {{--define}} / {{-D}} arguments ourselves in 
[{{MavenCli#setCliProperty}}|https://github.com/apache/maven/blob/master/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L1762],
 and I'd like to get rid of that as well.

The first is very easy, the second and third are causing the headache. The 
{{DefaultParser}} of Commons CLI behaves differently than the {{GnuParser}} 
that we used to leverage; more specifically, it doesn't support style 6 while 
the {{GnuParser}} did. There is no evidence in the Commons CLI code or website 
that suggests the {{DefaultParser}} would support {{{}-D x{}}}. What they 
explicitly mention is a style they call ["Java Property 
Option"|https://commons.apache.org/proper/commons-cli/usage.html#Defining_Java_Property_Option].

My suggestion, moving forward, would be to only support the same style as the 
JVM: {{-Dx=y}} and {{{}-Dx{}}}. Indeed, that would be a breaking change, but I 
would prefer using Commons CLI the suggested way _over_ keeping a potpourri of 
invocation styles that clutters and obscures our own code base with workarounds 
and custom parsing.

> Completely update CLI handling according to Commons CLI 1.5 documentation
> -------------------------------------------------------------------------
>
>                 Key: MNG-7217
>                 URL: https://issues.apache.org/jira/browse/MNG-7217
>             Project: Maven
>          Issue Type: Task
>          Components: Command Line
>            Reporter: Michael Osipov
>            Assignee: Maarten Mulders
>            Priority: Major
>             Fix For: 4.0.x-candidate
>
>
> We currently don't have code which complies with the documentation of Commons 
> CLI 1.5. As soon as we move we can address a few issues, e.g., support of 
> {{--}} to separate options from real args.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to