Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I preserve whitespace in a Maven plugin configuration?

I have a plugin configuration parameter named suffix. I would like the user to be able to specify a newline (a literal character produced by pressing the Return key, not some escaped variant, although I'll get to that) as the value for that parameter.

At the same time, the parameter has a default-value setting. I would like to continue to use that.

How do I specify, in my plugin's configuration stanza, that the suffix parameter should take a newline?

I've tried this:

<suffix><![CDATA[
]]></suffix>

...and this:

<suffix>${line.separator}</suffix>

...(that one actually substitutes the right character in but XML parsing stomps on it) and this:

<suffix><[!CDATA[${line.separator}]]></suffix>

...and this:

<suffix>&x0d;</suffix>

...and this:

<suffix xml:space="preserve">
</suffix>

...all to no avail. Specifically, I see the default value of the parameter instead.

Edit: Interestingly, the whitespace is eaten long before Maven's internals ever get a chance to work on the value. mvn help:effective-pom will show that the whitespace has been removed. Leading, trailing and "only" whitespace content is removed early on in the parsing stage.

This seems to me most likely to be a bug, so I've filed http://jira.codehaus.org/browse/PLX-461 to track it.

like image 222
Laird Nelson Avatar asked Sep 12 '11 15:09

Laird Nelson


2 Answers

The codehaus links don't work anymore, but I found in the maven documentation that since version 3.0.something you can add an attribute xml:space="preserve" to any element you don't want trimmed.

like image 178
Evert Avatar answered Sep 20 '22 04:09

Evert


Per instructions, I am answering this question by referring people to the following JIRA: https://issues.apache.org/jira/browse/MNG-5380 (originally at http://jira.codehaus.org/browse/PLX-461 ).

like image 39
Laird Nelson Avatar answered Sep 19 '22 04:09

Laird Nelson