Ekryd / sortpom

Maven plugin that helps the user sort pom.xml.
https://github.com/Ekryd/sortpom/wiki/
BSD 3-Clause "New" or "Revised" License
336 stars 181 forks source link

Newlines aren't kept at beginning or end of String content. #437

Closed motlin closed 4 months ago

motlin commented 4 months ago

I'm running the enforcer plugin and have this config in my pom.xml.

                                    <unCheckedPluginList>
                                        org.apache.maven.plugins:maven-site-plugin,
                                        org.apache.maven.plugins:maven-deploy-plugin
                                    </unCheckedPluginList>

After formatting with sortpom, this xml becomes:

                                    <unCheckedPluginList>org.apache.maven.plugins:maven-site-plugin,
                                        org.apache.maven.plugins:maven-deploy-plugin</unCheckedPluginList>

I have <keepBlankLines>true</keepBlankLines> so I was expecting these newlines to be kept.

Ekryd commented 4 months ago

Hi! The keepBlankLines option, in SortPom, lets you keep blank lines between two xml elements, e.g.

<name>Green</name>

<description>Salad</description>

Have you tried using xml:space="preserve"? E.g.

<unCheckedPluginList xml:space="preserve">
  org.apache.maven.plugins:maven-site-plugin,
  org.apache.maven.plugins:maven-deploy-plugin
</unCheckedPluginList>
motlin commented 4 months ago

That works, thanks! Are there no options to control this? I thought some of the options affected the newlines within the string, just not at the front or the end.

Ekryd commented 4 months ago

xml:space="preserve" is a standard XML directive, and the XML framework that I use supported it, so there was no need to re-invent the wheel 😀. I don't know if using newlines in XML elements is such a common case. I tend to use separator characters when possible to avoid the problem altogether, e.g ,:;.

Ekryd commented 4 months ago

Glad that the problem is solved