Class AbstractXmlPlugin

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    XmlCheckPlugin, XmlFormatPlugin

    public abstract class AbstractXmlPlugin
    extends org.apache.maven.plugin.AbstractMojo
    Common infrastructure for the various plugin goals.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private char attributeQuoteChar
      Quote character to use when writing attributes.
      private java.io.File baseDirectory
      The base directory of the project.
      private java.lang.String encoding
      The encoding format.
      private java.lang.String[] excludes
      A set of file patterns that allow you to exclude certain files/folders from the formatting.
      private boolean expandEmptyElements
      Whether or not to expand empty elements to <tagName></tagName>.
      private java.lang.String[] includes
      A set of file patterns that dictate which files should be included in the formatting with each file pattern being relative to the base directory.
      private int indentSize
      Indicates the number of spaces to apply when indenting.
      private boolean keepBlankLines
      Whether to keep blank lines.
      private LineEnding lineEnding
      Sets the line-ending of files after formatting.
      private java.lang.String lineSeparator
      Deprecated.
      Please do not set this value; use lineEnding instead
      private boolean newLineAfterDeclaration
      Whether or not to print new line after the XML declaration.
      private int newLineAfterNTags
      Controls when to output a line.separator every so many tags in case of no lines and total text trimming.
      private boolean newlines
      The default new line flag, set to do new lines only as in original document.
      private boolean omitEncoding
      Whether or not to output the encoding in the XML declaration.
      private boolean padText
      Pad string-element boundaries with whitespace.
      private boolean skip
      Skip XML formatting.
      private boolean skipTargetFolder
      In addition to the exclusions, the project build directory (typically target) is always excluded if true.
      private boolean suppressDeclaration
      Whether or not to suppress the XML declaration.
      private boolean tabIndent
      Use tabs instead of spaces for indents.
      private java.io.File targetDirectory
      The project target directory.
      private boolean trimText
      Should we preserve whitespace or not in text nodes.
      private boolean xhtml
      Whether or not to use XHTML standard.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Field Detail

      • attributeQuoteChar

        @Parameter(property="attributeQuoteChar",
                   defaultValue="\"")
        private char attributeQuoteChar
        Quote character to use when writing attributes.
      • baseDirectory

        @Parameter(defaultValue=".",
                   readonly=true,
                   required=true,
                   property="project.basedir")
        private java.io.File baseDirectory
        The base directory of the project.
      • encoding

        @Parameter(property="encoding",
                   defaultValue="UTF-8")
        private java.lang.String encoding
        The encoding format.
      • excludes

        @Parameter(property="excludes")
        private java.lang.String[] excludes
        A set of file patterns that allow you to exclude certain files/folders from the formatting. In addition to these exclusions, the project build directory (typically target) is always excluded if skipTargetFolder is true.
      • expandEmptyElements

        @Parameter(property="expandEmptyElements",
                   defaultValue="false")
        private boolean expandEmptyElements
        Whether or not to expand empty elements to <tagName></tagName>.
      • includes

        @Parameter(property="includes")
        private java.lang.String[] includes
        A set of file patterns that dictate which files should be included in the formatting with each file pattern being relative to the base directory.
      • indentSize

        @Parameter(property="indentSize",
                   defaultValue="2")
        private int indentSize
        Indicates the number of spaces to apply when indenting.
      • tabIndent

        @Parameter(property="tabIndent",
                   defaultValue="false")
        private boolean tabIndent
        Use tabs instead of spaces for indents. If set to true, indentSize will be ignored.
      • lineEnding

        @Parameter(property="lineEnding",
                   defaultValue="LF")
        private LineEnding lineEnding
        Sets the line-ending of files after formatting. Valid values are:
        • "SYSTEM" - Use line endings of current system
        • "LF" - Use Unix and Mac style line endings
        • "CRLF" - Use DOS and Windows style line endings
        • "CR" - Use early Mac style line endings
        This property is only used if lineSeparator has its default value. Do not set any value for lineSeparator.
      • lineSeparator

        @Parameter(property="lineSeparator",
                   defaultValue="\n")
        @Deprecated
        private java.lang.String lineSeparator
        Deprecated.
        Please do not set this value; use lineEnding instead
        New line separator.
      • newLineAfterDeclaration

        @Parameter(property="newLineAfterDeclaration",
                   defaultValue="false")
        private boolean newLineAfterDeclaration
        Whether or not to print new line after the XML declaration.
      • newLineAfterNTags

        @Parameter(property="newLineAfterNTags",
                   defaultValue="0")
        private int newLineAfterNTags
        Controls when to output a line.separator every so many tags in case of no lines and total text trimming.
      • newlines

        @Parameter(property="newlines",
                   defaultValue="true")
        private boolean newlines
        The default new line flag, set to do new lines only as in original document.
      • omitEncoding

        @Parameter(property="omitEncoding",
                   defaultValue="false")
        private boolean omitEncoding
        Whether or not to output the encoding in the XML declaration.
      • padText

        @Parameter(property="padText",
                   defaultValue="false")
        private boolean padText
        Pad string-element boundaries with whitespace.
      • skip

        @Parameter(property="xml-format.skip",
                   defaultValue="false")
        private boolean skip
        Skip XML formatting.
      • skipTargetFolder

        @Parameter(property="skipTargetFolder",
                   defaultValue="true")
        private boolean skipTargetFolder
        In addition to the exclusions, the project build directory (typically target) is always excluded if true.
      • suppressDeclaration

        @Parameter(property="suppressDeclaration",
                   defaultValue="false")
        private boolean suppressDeclaration
        Whether or not to suppress the XML declaration.
      • targetDirectory

        @Parameter(defaultValue="${project.build.directory}",
                   readonly=true,
                   required=true)
        private java.io.File targetDirectory
        The project target directory. This is always excluded from formatting.
      • trimText

        @Parameter(property="trimText",
                   defaultValue="true")
        private boolean trimText
        Should we preserve whitespace or not in text nodes.
      • xhtml

        @Parameter(property="xhtml",
                   defaultValue="false")
        private boolean xhtml
        Whether or not to use XHTML standard.
      • keepBlankLines

        @Parameter(property="keepBlankLines",
                   defaultValue="false")
        private boolean keepBlankLines
        Whether to keep blank lines. A maximum of one line is preserved between each tag.
    • Constructor Detail

      • AbstractXmlPlugin

        public AbstractXmlPlugin()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • processFile

        protected abstract boolean processFile​(java.io.File input,
                                               XmlOutputFormat fmt)
                                        throws org.dom4j.DocumentException,
                                               java.io.IOException
        Processes a single file found in the project.
        Parameters:
        input - the file to process
        fmt - the formatting options
        Returns:
        true if the file required changes to match the formatting style
        Throws:
        org.dom4j.DocumentException - if input XML could not be parsed
        java.io.IOException - if output XML stream could not be written
      • afterAllProcessed

        protected abstract void afterAllProcessed​(boolean neededFormatting)
                                           throws org.apache.maven.plugin.MojoExecutionException
        Invoked after all files in the project have been processed.
        Parameters:
        neededFormatting - whether any processed file required changes to match the formatting style
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if the build must be failed
      • setBaseDirectory

        void setBaseDirectory​(java.io.File baseDirectory)
      • setExcludes

        void setExcludes​(java.lang.String... excludes)
      • setIncludes

        void setIncludes​(java.lang.String... includes)
      • setSkip

        void setSkip​(boolean skip)
      • setSkipTargetFolder

        void setSkipTargetFolder​(boolean skipTargetFolder)
      • setTargetDirectory

        void setTargetDirectory​(java.io.File targetDirectory)
      • determineLineSeparator

        private java.lang.String determineLineSeparator()
      • find

        private java.lang.String[] find()
      • initializeExcludes

        private void initializeExcludes()
      • initializeIncludes

        private void initializeIncludes()