Class CheckFormatMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(defaultPhase=VALIDATE,
          name="check-format",
          threadSafe=true)
    public class CheckFormatMojo
    extends AbstractXmlMojo
    An XML indentation check over a set of files.
    • Field Detail

      • encoding

        @Parameter(property="xml.encoding",
                   defaultValue="${project.build.sourceEncoding}")
        private java.lang.String encoding
        The encoding of files included in formatFileSets. Note that the encoding can be set also per FormatFileSet.
      • failOnFormatViolation

        @Parameter(property="xml.failOnFormatViolation",
                   defaultValue="true")
        private boolean failOnFormatViolation
        Tells the mojo what to do in case XML formatting violations are found. if true, all violations will be reported on the console as ERRORs and the build will fail. if false, all violations will be reported on the console as WARNs and the build will proceed further.
      • formatFileSets

        @Parameter
        private java.util.List<FormatFileSet> formatFileSets
        File patterns to include. The patterns are relative to the current project's baseDir.
      • indentSize

        @Parameter(property="xml.indentSize",
                   defaultValue="2")
        private int indentSize
        The number of spaces expected for indentation. Note that indentSize can be configuread also per FormatFileSet.
      • saxParserFactory

        private javax.xml.parsers.SAXParserFactory saxParserFactory
        A SAXParserFactory
      • useDefaultFormatFileSet

        @Parameter(property="xml.useDefaultFormatFileSet",
                   defaultValue="true")
        private boolean useDefaultFormatFileSet
        If set to true, the result of FormatFileSet#getDefault(String, int) will be appended to formatFileSets before the processing.
    • Constructor Detail

      • CheckFormatMojo

        public CheckFormatMojo()
        Creates a new CheckFormatMojo instance.
    • Method Detail

      • check

        private void check​(java.io.File file,
                           java.lang.String encoding,
                           XmlFormatViolationHandler violationHandler)
                    throws org.apache.maven.plugin.MojoExecutionException
        Checks the formatting of the given file. The file is read using the given encoding and the violations are reported to the given violationHandler.
        Parameters:
        file - the file to check
        encoding - the encoding to use for reading the file
        violationHandler - the XmlFormatViolationHandler to report violations
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if there is any lover level exception reading or parsing the file.
      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Called by Maven for executing the Mojo.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - Running the Mojo failed.
        org.apache.maven.plugin.MojoFailureException - A configuration error was detected.
      • scan

        private java.lang.String[] scan​(org.apache.maven.model.FileSet fileSet)
        A DirectoryScanner boiler plate.
        Parameters:
        fileSet - FileSet to scan
        Returns:
        the included paths
      • setIndentSize

        public void setIndentSize​(int indentSize)
        Sets the number of spaces for indentation.
        Parameters:
        indentSize - the number of spaces