Class KeepCommentsInPom

java.lang.Object
org.codehaus.mojo.flatten.KeepCommentsInPom

class KeepCommentsInPom extends Object
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 Details

    • log

      private org.apache.maven.plugin.logging.Log log
    • commentsPaths

      private Map<String,Node> 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

      private void walkOverNodes(Node aNode, String aParentPath, BiConsumer<Node,String> aConsumer)
      Walk over the pom hierarchy of the Document.
      Parameters:
      aConsumer - Function to be called with the toBeCollected/found node.
      Node - the current Node
      String - 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 by MavenXpp3Writer
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • writeDocumentToString

      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: