@Mojo(name="check",
defaultPhase=VERIFY,
requiresDependencyResolution=TEST,
threadSafe=true)
public class CheckstyleViolationCheckMojo
extends org.apache.maven.plugin.AbstractMojo
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
cacheFile
Specifies the cache file used to speed up Checkstyle on successive runs.
|
private static java.lang.String |
CHECKSTYLE_FILE_HEADER |
protected CheckstyleExecutor |
checkstyleExecutor |
private org.codehaus.plexus.configuration.PlexusConfiguration |
checkstyleRules
By using this property, you can specify the whole Checkstyle rules
inline directly inside this pom.
|
private java.lang.String |
configLocation
Specifies the location of the XML configuration to use.
|
private boolean |
consoleOutput
Output errors to console.
|
private java.lang.String |
encoding
The file encoding to use when reading the source files.
|
private java.lang.String |
excludes
Specifies the names filter of the source files to be excluded for
Checkstyle.
|
private boolean |
failOnViolation
Fail the build on a violation.
|
private boolean |
failsOnError
If this is true, and Checkstyle reported any violations or errors,
the build fails immediately after running Checkstyle, before checking the log
for
logViolationsToConsole. |
private java.lang.String |
headerLocation
Specifies the location of the License file (a.k.a.
|
private boolean |
includeResources
Whether to apply Checkstyle to resource directories.
|
private java.lang.String |
includes
Specifies the names filter of the source files to be used for Checkstyle.
|
private boolean |
includeTestResources
Whether to apply Checkstyle to test resource directories.
|
private boolean |
includeTestSourceDirectory
Include or not the test source directory to be used for Checkstyle.
|
private static java.lang.String |
JAVA_FILES |
private boolean |
logViolationsToConsole
Output the detected violations to the console.
|
private int |
maxAllowedViolations
The maximum number of allowed violations.
|
private boolean |
omitIgnoredModules
Specifies whether modules with a configured severity of
ignore should be omitted during Checkstyle
invocation. |
private java.io.File |
outputFile
Specifies the path and filename to save the Checkstyle output.
|
private java.lang.String |
outputFileFormat
Specifies the format of the output to be used when writing to the output
file.
|
private java.io.File |
outputXmlFile |
private org.apache.maven.plugin.descriptor.PluginDescriptor |
plugin
The Plugin Descriptor
|
protected org.apache.maven.project.MavenProject |
project
The Maven Project Object.
|
private java.lang.String |
propertiesLocation
Specifies the location of the properties file.
|
private java.lang.String |
propertyExpansion
Allows for specifying raw property expansion information.
|
private java.lang.String |
resourceExcludes
Specifies the names filter of the files to be excluded for
Checkstyle when checking resources.
|
private java.lang.String |
resourceIncludes
Specifies the names filter of the files to be used for Checkstyle when checking resources.
|
protected java.util.List<org.apache.maven.model.Resource> |
resources
Specifies the location of the resources to be used for Checkstyle.
|
private java.io.File |
rulesFiles
Dump file for inlined Checkstyle rules.
|
private boolean |
skip
Skip entire check.
|
private boolean |
skipExec
Skip Checkstyle execution will only scan the outputFile.
|
private java.util.List<java.lang.String> |
sourceDirectories
Specifies the location of the source directories to be used for Checkstyle.
|
private java.io.File |
sourceDirectory
Deprecated.
instead use
sourceDirectories. For version 3.0.0, this parameter is only defined to break
the build if you use it! |
private java.io.ByteArrayOutputStream |
stringOutputStream |
private java.lang.String |
suppressionsFileExpression
The key to be used in the properties for the suppressions file.
|
private java.lang.String |
suppressionsLocation
Specifies the location of the suppressions XML file to use.
|
protected java.util.List<org.apache.maven.model.Resource> |
testResources
Specifies the location of the test resources to be used for Checkstyle.
|
private java.util.List<java.lang.String> |
testSourceDirectories
Specifies the location of the test source directories to be used for Checkstyle.
|
private java.io.File |
testSourceDirectory
Deprecated.
instead use
testSourceDirectories. For version 3.0.0, this parameter is only defined to
break the build if you use it! |
private java.io.File |
useFile
If
null, the Checkstyle plugin will display violations on stdout. |
private java.lang.String |
violationIgnore
Violations to ignore.
|
private java.lang.String |
violationSeverity
The lowest severity level that is considered a violation.
|
| Constructor and Description |
|---|
CheckstyleViolationCheckMojo() |
| Modifier and Type | Method and Description |
|---|---|
private void |
checkDeprecatedParameterUsage(java.lang.Object parameter,
java.lang.String name,
java.lang.String replacement) |
private java.util.List<org.apache.maven.artifact.Artifact> |
collectArtifacts(java.lang.String hint) |
private int |
countViolations(org.codehaus.plexus.util.xml.pull.XmlPullParser xpp) |
void |
execute() |
private java.util.List<org.apache.maven.artifact.Artifact> |
getCheckstylePluginDependenciesAsArtifacts(java.util.Map<java.lang.String,org.apache.maven.model.Plugin> plugins,
java.lang.String hint) |
private com.puppycrawl.tools.checkstyle.DefaultLogger |
getConsoleListener() |
private com.puppycrawl.tools.checkstyle.api.AuditListener |
getListener() |
private java.io.OutputStream |
getOutputStream(java.io.File file) |
private java.util.List<java.io.File> |
getSourceDirectories() |
private java.util.List<java.io.File> |
getTestSourceDirectories() |
private boolean |
ignore(RuleUtil.Matcher[] ignores,
java.lang.String source) |
private boolean |
isViolation(java.lang.String severity)
Checks if the given severity is considered a violation.
|
private void |
log(java.lang.String severity,
java.lang.String message) |
private static final java.lang.String JAVA_FILES
private static final java.lang.String CHECKSTYLE_FILE_HEADER
@Parameter(property="checkstyle.output.file",
defaultValue="${project.build.directory}/checkstyle-result.xml")
private java.io.File outputFile
outputFileFormat
parameter.@Parameter(property="checkstyle.output.format",
defaultValue="xml")
private java.lang.String outputFileFormat
plain" and "xml".@Parameter(property="checkstyle.failOnViolation",
defaultValue="true")
private boolean failOnViolation
logViolationsToConsole is true).
Compare this to failsOnError which fails the build immediately
before examining the output log.@Parameter(property="checkstyle.maxAllowedViolations",
defaultValue="0")
private int maxAllowedViolations
@Parameter(property="checkstyle.violationSeverity",
defaultValue="error")
private java.lang.String violationSeverity
error", "warning" and "info".@Parameter(property="checkstyle.violation.ignore") private java.lang.String violationIgnore
@Parameter(property="checkstyle.skip",
defaultValue="false")
private boolean skip
@Parameter(property="checkstyle.skipExec",
defaultValue="false")
private boolean skipExec
@Parameter(property="checkstyle.console",
defaultValue="true")
private boolean logViolationsToConsole
@Parameter(defaultValue="${project.resources}",
readonly=true)
protected java.util.List<org.apache.maven.model.Resource> resources
@Parameter(defaultValue="${project.testResources}",
readonly=true)
protected java.util.List<org.apache.maven.model.Resource> testResources
@Parameter(property="checkstyle.config.location",
defaultValue="sun_checks.xml")
private java.lang.String configLocation
Specifies the location of the XML configuration to use.
Potential values are a filesystem path, a URL, or a classpath resource. This parameter expects that the contents of the location conform to the xml format (Checkstyle Checker module) configuration of rulesets.
This parameter is resolved as resource, URL, then file. If successfully
resolved, the contents of the configuration is copied into the
${project.build.directory}/checkstyle-configuration.xml
file before being passed to Checkstyle as a configuration.
There are 2 predefined rulesets.
sun_checks.xml: Sun Checks.google_checks.xml: Google Checks.@Parameter(property="checkstyle.properties.location") private java.lang.String propertiesLocation
Specifies the location of the properties file.
This parameter is resolved as URL, File then resource. If successfully
resolved, the contents of the properties location is copied into the
${project.build.directory}/checkstyle-checker.properties
file before being passed to Checkstyle for loading.
The contents of the propertiesLocation will be made
available to Checkstyle for specifying values for parameters within the
xml configuration (specified in the configLocation
parameter).
@Parameter private java.lang.String propertyExpansion
@Parameter(property="checkstyle.header.file",
defaultValue="LICENSE.txt")
private java.lang.String headerLocation
Specifies the location of the License file (a.k.a. the header file) that can be used by Checkstyle to verify that source code has the correct license header.
You need to use ${checkstyle.header.file} in your Checkstyle xml
configuration to reference the name of this header file.
For instance:
<module name="RegexpHeader">
<property name="headerFile" value="${checkstyle.header.file}"/>
</module>
@Parameter(defaultValue="${project.build.directory}/checkstyle-cachefile")
private java.lang.String cacheFile
@Parameter(property="checkstyle.suppression.expression",
defaultValue="checkstyle.suppressions.file")
private java.lang.String suppressionsFileExpression
@Parameter(property="checkstyle.suppressions.location") private java.lang.String suppressionsLocation
Specifies the location of the suppressions XML file to use.
This parameter is resolved as resource, URL, then file. If successfully
resolved, the contents of the suppressions XML is copied into the
${project.build.directory}/checkstyle-suppressions.xml file
before being passed to Checkstyle for loading.
See suppressionsFileExpression for the property that will
be made available to your Checkstyle configuration.
@Parameter(property="encoding",
defaultValue="${project.build.sourceEncoding}")
private java.lang.String encoding
project.build.sourceEncoding
is not set, the platform default encoding is used. Note: This parameter always overrides the
property charset from Checkstyle's TreeWalker module.@Component(role=CheckstyleExecutor.class, hint="default") protected CheckstyleExecutor checkstyleExecutor
@Parameter(property="checkstyle.consoleOutput",
defaultValue="false")
private boolean consoleOutput
@Parameter(defaultValue="${project}",
readonly=true,
required=true)
protected org.apache.maven.project.MavenProject project
@Parameter(defaultValue="${plugin}",
readonly=true,
required=true)
private org.apache.maven.plugin.descriptor.PluginDescriptor plugin
@Parameter private java.io.File useFile
null, the Checkstyle plugin will display violations on stdout.
Otherwise, a text file will be created with the violations.@Parameter(property="checkstyle.excludes") private java.lang.String excludes
@Parameter(property="checkstyle.includes",
defaultValue="**\\/*.java",
required=true)
private java.lang.String includes
@Parameter(property="checkstyle.resourceExcludes") private java.lang.String resourceExcludes
@Parameter(property="checkstyle.resourceIncludes",
defaultValue="**/*.properties",
required=true)
private java.lang.String resourceIncludes
@Parameter(defaultValue="false") private boolean failsOnError
logViolationsToConsole. If you want to use logViolationsToConsole,
use failOnViolation instead of this.@Deprecated @Parameter private java.io.File testSourceDirectory
testSourceDirectories. For version 3.0.0, this parameter is only defined to
break the build if you use it!@Parameter private java.util.List<java.lang.String> testSourceDirectories
${project.testCompileSourceRoots}.@Parameter(defaultValue="false") private boolean includeTestSourceDirectory
@Deprecated @Parameter private java.io.File sourceDirectory
sourceDirectories. For version 3.0.0, this parameter is only defined to break
the build if you use it!@Parameter private java.util.List<java.lang.String> sourceDirectories
${project.compileSourceRoots}.@Parameter(property="checkstyle.includeResources",
defaultValue="true",
required=true)
private boolean includeResources
@Parameter(property="checkstyle.includeTestResources",
defaultValue="true",
required=true)
private boolean includeTestResources
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration checkstyleRules
<plugin>
...
<configuration>
<checkstyleRules>
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true" />
</module>
<module name="TreeWalker">
<module name="EmptyBlock"/>
</module>
</module>
</checkstyleRules>
</configuration>
...
@Parameter(property="checkstyle.output.rules.file",
defaultValue="${project.build.directory}/checkstyle-rules.xml")
private java.io.File rulesFiles
@Parameter(defaultValue="false") private boolean omitIgnoredModules
ignore should be omitted during Checkstyle
invocation.private java.io.ByteArrayOutputStream stringOutputStream
private java.io.File outputXmlFile
public void execute()
throws org.apache.maven.plugin.MojoExecutionException,
org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureExceptionprivate void checkDeprecatedParameterUsage(java.lang.Object parameter,
java.lang.String name,
java.lang.String replacement)
throws org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoFailureExceptionprivate int countViolations(org.codehaus.plexus.util.xml.pull.XmlPullParser xpp)
throws org.codehaus.plexus.util.xml.pull.XmlPullParserException,
java.io.IOException
org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionjava.io.IOExceptionprivate void log(java.lang.String severity,
java.lang.String message)
private boolean isViolation(java.lang.String severity)
severity - The severity to checktrue if the given severity is a violation, otherwise falseprivate boolean ignore(RuleUtil.Matcher[] ignores, java.lang.String source)
private com.puppycrawl.tools.checkstyle.DefaultLogger getConsoleListener()
throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionExceptionprivate java.io.OutputStream getOutputStream(java.io.File file)
throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionExceptionprivate com.puppycrawl.tools.checkstyle.api.AuditListener getListener()
throws org.apache.maven.plugin.MojoFailureException,
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureExceptionorg.apache.maven.plugin.MojoExecutionExceptionprivate java.util.List<org.apache.maven.artifact.Artifact> collectArtifacts(java.lang.String hint)
private java.util.List<org.apache.maven.artifact.Artifact> getCheckstylePluginDependenciesAsArtifacts(java.util.Map<java.lang.String,org.apache.maven.model.Plugin> plugins,
java.lang.String hint)
private java.util.List<java.io.File> getSourceDirectories()
private java.util.List<java.io.File> getTestSourceDirectories()