Package org.codehaus.mojo.flatten
Class KeepCommentsInPom
java.lang.Object
org.codehaus.mojo.flatten.KeepCommentsInPom
Helper class to keep the comments how they have been in the original pom.xml While reading with
MavenXpp3Writer
the comments are not placed into the
Model
and so MavenXpp3Writer
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
FieldsModifier and TypeFieldDescriptionThe unique path list for an original node (the comments are stored via the referenced previousSibling)private org.apache.maven.plugin.logging.Log
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static KeepCommentsInPom
Create an instance with collected current comments of the passed pom.xml file.org.apache.maven.plugin.logging.Log
getLog()
private void
loadComments
(File anOriginalPomFile) load all current comments and text fragments from xml filerestoreOriginalComments
(String anXml, String aModelEncoding) void
setLog
(org.apache.maven.plugin.logging.Log aLog) private void
walkOverNodes
(Node aNode, String aParentPath, BiConsumer<Node, String> aConsumer) Walk over the pom hierarchy of the Document.private String
Use an LSSerializer to keep whitespaces added by MavenXpp3Writer
-
Field Details
-
log
private org.apache.maven.plugin.logging.Log log -
commentsPaths
The unique path list for an original node (the comments are stored via the referenced previousSibling)
-
-
Constructor Details
-
KeepCommentsInPom
KeepCommentsInPom()
-
-
Method Details
-
create
static KeepCommentsInPom create(org.apache.maven.plugin.logging.Log aLog, 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(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
Walk over the pom hierarchy of the Document.- Parameters:
aConsumer
- Function to be called with the toBeCollected/found node.Node
- the current NodeString
- the unique path in the parent
-
restoreOriginalComments
public String restoreOriginalComments(String anXml, String aModelEncoding) throws org.apache.maven.plugin.MojoExecutionException - Parameters:
String
- the XML written byMavenXpp3Writer
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
writeDocumentToString
private String writeDocumentToString(Document aPom) throws ClassNotFoundException, InstantiationException, IllegalAccessException Use an LSSerializer to keep whitespaces added by MavenXpp3Writer- Parameters:
Document
- the pom to write to String.- Throws:
ClassNotFoundException
InstantiationException
IllegalAccessException
-
getLog
public org.apache.maven.plugin.logging.Log getLog()- See Also:
-
setLog
public void setLog(org.apache.maven.plugin.logging.Log aLog) - See Also:
-