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 Classes Modifier and Type Class Description private class
CheckFormatMojo.ViolationCollector
-
Nested classes/interfaces inherited from class org.codehaus.mojo.xml.AbstractXmlMojo
AbstractXmlMojo.CatalogHandling
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
encoding
The encoding of files included informatFileSets
.private boolean
failOnFormatViolation
Tells the mojo what to do in case XML formatting violations are found.private java.util.List<FormatFileSet>
formatFileSets
File patterns to include.private int
indentSize
The number of spaces expected for indentation.private javax.xml.parsers.SAXParserFactory
saxParserFactory
ASAXParserFactory
private boolean
useDefaultFormatFileSet
If set totrue
, the result ofFormatFileSet#getDefault(String, int)
will be appended toformatFileSets
before the processing.
-
Constructor Summary
Constructors Constructor Description CheckFormatMojo()
Creates a newCheckFormatMojo
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
check(java.io.File file, java.lang.String encoding, XmlFormatViolationHandler violationHandler)
Checks the formatting of the givenfile
.void
execute()
Called by Maven for executing the Mojo.private java.lang.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
-
-
-
-
Field Detail
-
encoding
@Parameter(property="xml.encoding", defaultValue="${project.build.sourceEncoding}") private java.lang.String encoding
The encoding of files included informatFileSets
. Note that theencoding 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. 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
@Parameter private java.util.List<FormatFileSet> formatFileSets
File patterns to include. The patterns are relative to the current project'sbaseDir
.
-
indentSize
@Parameter(property="xml.indentSize", defaultValue="2") private int indentSize
The number of spaces expected for indentation. Note thatindentSize
can be configuread also perFormatFileSet
.
-
saxParserFactory
private javax.xml.parsers.SAXParserFactory saxParserFactory
ASAXParserFactory
-
useDefaultFormatFileSet
@Parameter(property="xml.useDefaultFormatFileSet", defaultValue="true") private boolean useDefaultFormatFileSet
If set totrue
, the result ofFormatFileSet#getDefault(String, int)
will be appended toformatFileSets
before the processing.
-
-
Constructor Detail
-
CheckFormatMojo
public CheckFormatMojo()
Creates a newCheckFormatMojo
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 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.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)
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
-
-