butterfly
butterfly copied to clipboard
Modify PomAddDependency to preserve file formatting and comments
Butterfly has one limitation when performing certain modifications to Maven pom files. Depending on the modification, it ends up reformatting the whole file, changing indentation and the order of the tags, besides also removing comments. That happens because Butterfly reads the file, parses it, builds a model in memory, applies the transformation, then writes it back to the same file.
When it writes the file with the transformation, it uses the model in memory as source, which means it looses entirely the original formatting and comments the file used to have. Some users don't like it because many times the transformation is very trivial, and would change just a few lines, but still the result is a file that looks entirely different.
The goal of this is issue is to focus on PomAddDependency
, and modify it to perform isolated modifications, preserving formatting, order and comments (as explained earlier). That could be achieved using StAX.
This change in PomAddParent
can be used as example.
StAX references
- https://docs.oracle.com/javase/tutorial/jaxp/stax/index.html
- https://en.wikipedia.org/wiki/StAX
- http://tutorialspointexamples.com/stax-xml-parser-java-tutorial-examples/
- http://www.xml.com/pub/a/2003/09/17/stax.html