Package org.codehaus.mojo.flatten
Class KeepCommentsInPom
- java.lang.Object
-
- org.codehaus.mojo.flatten.KeepCommentsInPom
-
class KeepCommentsInPom extends java.lang.Object
Helper class to keep the comments how they have been in the original pom.xml While reading withMavenXpp3Writer
the comments are not placed into theModel
and soMavenXpp3Writer
is not able to re-write those comments.Workaround (maybe until core is fixed) is to remember all the comments and restore them after MavenXpp3Writer has created the new flattened pom.xml.
Current restriction on non-unique child nodes is that this class finds the node back due to the position in the file, that may lead to mis-re-added comments e.g. on multiple added dependencies (but for e.g. resolveCiFriendliesOnly the nodes keep stable)
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,org.w3c.dom.Node>
commentsPaths
The unique path list for an original node (the comments are stored via the referenced previousSibling)private org.apache.maven.plugin.logging.Log
log
-
Constructor Summary
Constructors Constructor Description KeepCommentsInPom()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static KeepCommentsInPom
create(org.apache.maven.plugin.logging.Log aLog, java.io.File aOriginalPomFile)
Create an instance with collected current comments of the passed pom.xml file.org.apache.maven.plugin.logging.Log
getLog()
private void
loadComments(java.io.File anOriginalPomFile)
load all current comments and text fragments from xml filejava.lang.String
restoreOriginalComments(java.lang.String anXml, java.lang.String aModelEncoding)
void
setLog(org.apache.maven.plugin.logging.Log aLog)
private void
walkOverNodes(org.w3c.dom.Node aNode, java.lang.String aParentPath, java.util.function.BiConsumer<org.w3c.dom.Node,java.lang.String> aConsumer)
Walk over the pom hierarchy of the Document.private java.lang.String
writeDocumentToString(org.w3c.dom.Document aPom)
Use an LSSerializer to keep whitespaces added by MavenXpp3Writer
-
-
-
Method Detail
-
create
static KeepCommentsInPom create(org.apache.maven.plugin.logging.Log aLog, java.io.File aOriginalPomFile) throws org.apache.maven.plugin.MojoExecutionException
Create an instance with collected current comments of the passed pom.xml file.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
loadComments
private void loadComments(java.io.File anOriginalPomFile) throws org.apache.maven.plugin.MojoExecutionException
load all current comments and text fragments from xml file- Parameters:
anOriginalPomFile
- the pom.xml- Throws:
org.apache.maven.plugin.MojoExecutionException
-
walkOverNodes
private void walkOverNodes(org.w3c.dom.Node aNode, java.lang.String aParentPath, java.util.function.BiConsumer<org.w3c.dom.Node,java.lang.String> aConsumer)
Walk over the pom hierarchy of the Document.- Parameters:
Node
- the current NodeString
- the unique path in the parentaConsumer
- Function to be called with the toBeCollected/found node.
-
restoreOriginalComments
public java.lang.String restoreOriginalComments(java.lang.String anXml, java.lang.String aModelEncoding) throws org.apache.maven.plugin.MojoExecutionException
- Parameters:
String
- the XML written byMavenXpp3Writer
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
writeDocumentToString
private java.lang.String writeDocumentToString(org.w3c.dom.Document aPom) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
Use an LSSerializer to keep whitespaces added by MavenXpp3Writer- Parameters:
Document
- the pom to write to String.- Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
getLog
public org.apache.maven.plugin.logging.Log getLog()
- See Also:
log
-
setLog
public void setLog(org.apache.maven.plugin.logging.Log aLog)
- See Also:
log
-
-