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

Konrad Windszus edited comment on MNG-6434 at 9/11/22 10:23 AM:
----------------------------------------------------------------

The problem is that the {{Xpp3DomBuilder}} trims all XML element values by 
default 
(https://github.com/codehaus-plexus/plexus-utils/blob/3896620b4fbf031b1b02b4d46b328c5839a231da/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java#L209)
 and {{Sisu.Plexus}} injects the configuration value only if its length is 
greater than 0 
(https://github.com/eclipse/sisu.plexus/blob/27a29dc633e6b03753a3c8d29a033648630c8831/org.eclipse.sisu.plexus/src/org/codehaus/plexus/component/configurator/converters/AbstractConfigurationConverter.java#L49).
However, using the {{xml:space}} attribute with value {{preserve}} should 
disable the trim logic 
(https://github.com/codehaus-plexus/plexus-utils/blob/3896620b4fbf031b1b02b4d46b328c5839a231da/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java#L195).
 Still the blank value does not kick in usually, as the XML is merged via 
{{Xpp3DomUtils}} to consider the property attribute of the parameter which 
disregards blank values due to the trim logic in 
https://github.com/codehaus-plexus/plexus-utils/blob/3896620b4fbf031b1b02b4d46b328c5839a231da/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java#L285.
The logic merges the configuration from the pom.xml and the plugin descriptor 
(https://maven.apache.org/ref/3.8.6/maven-plugin-api/plugin.html#paramname), 
where the plugin descriptor wins in case the configuration value is blank.


was (Author: kwin):
The problem is that the {{Xpp3DomBuilder}} trims all XML element values by 
default 
(https://github.com/codehaus-plexus/plexus-utils/blob/3896620b4fbf031b1b02b4d46b328c5839a231da/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java#L209)
 and {{Sisu.Plexus}} injects the configuration value only if its length is 
greater than 0 
(https://github.com/eclipse/sisu.plexus/blob/27a29dc633e6b03753a3c8d29a033648630c8831/org.eclipse.sisu.plexus/src/org/codehaus/plexus/component/configurator/converters/AbstractConfigurationConverter.java#L49).
However, using the {{xml:space}} attribute with value {{preserve}} should 
disable the trim logic 
(https://github.com/codehaus-plexus/plexus-utils/blob/3896620b4fbf031b1b02b4d46b328c5839a231da/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java#L195).
 Still the blank value does not kick in usually, as the XML is merged via 
{{Xpp3DomUtils}} to consider the property attribute of the parameter which 
disregards blank values due to the trim logic in 
https://github.com/codehaus-plexus/plexus-utils/blob/3896620b4fbf031b1b02b4d46b328c5839a231da/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java#L285.

> Cannot specify empty string for configuration value
> ---------------------------------------------------
>
>                 Key: MNG-6434
>                 URL: https://issues.apache.org/jira/browse/MNG-6434
>             Project: Maven
>          Issue Type: Bug
>          Components: Plugin API
>    Affects Versions: 3.5.4
>            Reporter: Chris Egerton
>            Priority: Major
>
> We have a MOJO class that involves several user-configured parameters. Some 
> of these parameters have default values that we'd like to use in the event 
> that the user doesn't specify a value for them; however, we'd also like the 
> user to be able to explicitly specify that the parameter should _not_ have a 
> value. The approach we wanted to take was to specify default values in the 
> parameter's annotation:
> {{@Parameter(property = "foo.bar", defaultValue = "${project.scm.url}")}}
> {{private String foo;}}
> And then detect empty strings as the user's way of saying "I know there's a 
> default value for this parameter but I'm sure that I'd actually like it to be 
> empty anyways.":
> {{<configuration>}}
> {{  <foo></foo>}}
> {{</configuration>}}
> or
> {{<configuration>}}
> {{  <foo />}}
> {{</configuration>}}
>  
> However, there's been some trouble as we haven't found a way yet to 
> distinguish between an intentionally-empty string and one that hasn't been 
> specified at all; the value for foo is always null regardless.
> Is there a friendly and/or intuitive way for the user to pass an empty string 
> as a parameter value?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to