Package org.codehaus.mojo.xml
Class CheckFormatMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.xml.AbstractXmlMojo
org.codehaus.mojo.xml.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.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.codehaus.mojo.xml.AbstractXmlMojo
AbstractXmlMojo.CatalogHandling
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The encoding of files included informatFileSets
.private boolean
Tells the mojo what to do in case XML formatting violations are found.private List
<FormatFileSet> File patterns to include.private int
The number of spaces expected for indentation.private SAXParserFactory
private boolean
If set totrue
, the result ofinvalid reference
FormatFileSet#getDefault(String, int)
formatFileSets
before the processing.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
check
(File file, String encoding, XmlFormatViolationHandler violationHandler) Checks the formatting of the givenfile
.void
execute()
Called by Maven for executing the Mojo.private String[]
scan
(org.apache.maven.model.FileSet fileSet) ADirectoryScanner
boiler plate.void
setIndentSize
(int indentSize) Sets the number of spaces for indentation.Methods inherited from class org.codehaus.mojo.xml.AbstractXmlMojo
activateProxy, asAbsoluteFile, asFiles, checkCatalogHandling, getBasedir, getCatalogHandling, getExcludes, getFileNames, getFiles, getLocator, getProject, getResolver, getResource, isSkipping, passivateProxy, setCatalogs
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
encoding
@Parameter(property="xml.encoding", defaultValue="${project.build.sourceEncoding}") private String encodingThe encoding of files included informatFileSets
. Note that theencoding can be set also per FormatFileSet
. -
failOnFormatViolation
@Parameter(property="xml.failOnFormatViolation", defaultValue="true") private boolean failOnFormatViolationTells the mojo what to do in case XML formatting violations are found. iftrue
, all violations will be reported on the console as ERRORs and the build will fail. iffalse
, all violations will be reported on the console as WARNs and the build will proceed further. -
formatFileSets
File patterns to include. The patterns are relative to the current project'sbaseDir
. -
indentSize
@Parameter(property="xml.indentSize", defaultValue="2") private int indentSizeThe number of spaces expected for indentation. Note thatindentSize
can be configuread also perFormatFileSet
. -
saxParserFactory
-
useDefaultFormatFileSet
@Parameter(property="xml.useDefaultFormatFileSet", defaultValue="true") private boolean useDefaultFormatFileSetIf set totrue
, the result ofinvalid reference
FormatFileSet#getDefault(String, int)
formatFileSets
before the processing.
-
-
Constructor Details
-
CheckFormatMojo
public CheckFormatMojo()Creates a newCheckFormatMojo
instance.
-
-
Method Details
-
check
private void check(File file, String encoding, XmlFormatViolationHandler violationHandler) throws org.apache.maven.plugin.MojoExecutionException Checks the formatting of the givenfile
. The file is read using the givenencoding
and the violations are reported to the givenviolationHandler
.- Parameters:
file
- the file to checkencoding
- the encoding to use for reading thefile
violationHandler
- theXmlFormatViolationHandler
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.MojoFailureExceptionCalled 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
ADirectoryScanner
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
-