Class CheckstyleViolationCheckMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringSpecifies the cache file used to speed up Checkstyle on successive runs.protected CheckstyleExecutorprivate org.codehaus.plexus.configuration.PlexusConfigurationBy using this property, you can specify the whole Checkstyle rules inline directly inside this pom.private StringThe header to use for the inline configuration.private StringSpecifies the location of the XML configuration to use.private booleanOutput errors to console.private static final Stringprivate booleanSpecifies whether generated source files should be excluded from Checkstyle.private StringSpecifies the names filter of the source files to be excluded for Checkstyle.private booleanFail the build on a violation.private booleanIf this is true, and Checkstyle reported any violations or errors, the build fails immediately after running Checkstyle, before checking the log forlogViolationsToConsole.private StringSpecifies the location of the License file (a.k.a.private booleanWhether to apply Checkstyle to resource directories.private StringSpecifies the names filter of the source files to be used for Checkstyle.private booleanWhether to apply Checkstyle to test resource directories.private booleanInclude or not the test source directory to be used for Checkstyle.private StringThe file encoding to use when reading the source files.private static final Stringprivate booleanOutput the detected violation count to the console.private booleanOutput the detected violations to the console.private intThe maximum number of allowed violations.private booleanSpecifies whether modules with a configured severity ofignoreshould be omitted during Checkstyle invocation.private FileSpecifies the path and filename to save the Checkstyle output.private StringSpecifies the format of the output to be used when writing to the output file.private Fileprivate org.apache.maven.plugin.descriptor.PluginDescriptorThe Plugin Descriptorprotected org.apache.maven.project.MavenProjectThe Maven Project Object.private StringSpecifies the location of the properties file.private StringAllows for specifying raw property expansion information.private StringSpecifies the names filter of the files to be excluded for Checkstyle when checking resources.private StringSpecifies the names filter of the files to be used for Checkstyle when checking resources.protected List<org.apache.maven.model.Resource> Specifies the location of the resources to be used for Checkstyle.private FileDump file for inlined Checkstyle rules.private booleanSkip entire check.private booleanSkip Checkstyle execution will only scan the outputFile.Specifies the location of the source directories to be used for Checkstyle.private FileDeprecated.private ByteArrayOutputStreamprivate StringThe key to be used in the properties for the suppressions file.private StringSpecifies the location of the suppressions XML file to use.protected List<org.apache.maven.model.Resource> Specifies the location of the test resources to be used for Checkstyle.Specifies the location of the test source directories to be used for Checkstyle.private FileDeprecated.instead usetestSourceDirectories.private FileIfnull, the Checkstyle plugin will display violations on stdout.private StringViolations to ignore.private StringThe lowest severity level that is considered a violation.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckDeprecatedParameterUsage(Object parameter, String name, String replacement) private List<org.apache.maven.artifact.Artifact> collectArtifacts(String hint) private intcountViolations(List<Violation> violations) voidexecute()filterBuildTarget(List<String> sourceDirectories) private List<org.apache.maven.artifact.Artifact> getCheckstylePluginDependenciesAsArtifacts(Map<String, org.apache.maven.model.Plugin> plugins, String hint) private com.puppycrawl.tools.checkstyle.DefaultLoggerprivate com.puppycrawl.tools.checkstyle.api.AuditListenerprivate OutputStreamgetOutputStream(File file) getViolations(org.codehaus.plexus.util.xml.pull.XmlPullParser xpp) private booleanignore(List<RuleUtil.Matcher> ignores, String source) private booleanisViolation(String severity) Checks if the given severity is considered a violation.private voidprivate voidprintViolations(List<Violation> violations) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
JAVA_FILES
- See Also:
-
DEFAULT_CONFIG_LOCATION
- See Also:
-
outputFile
@Parameter(property="checkstyle.output.file", defaultValue="${project.build.directory}/checkstyle-result.xml") private File outputFileSpecifies the path and filename to save the Checkstyle output. The format of the output file is determined by theoutputFileFormatparameter. -
outputFileFormat
Specifies the format of the output to be used when writing to the output file. Valid values are "plain", "sarif" and "xml". -
failOnViolation
@Parameter(property="checkstyle.failOnViolation", defaultValue="true") private boolean failOnViolationFail the build on a violation. The goal checks for the violations after logging them (iflogViolationsToConsoleistrue). Compare this tofailsOnErrorwhich fails the build immediately before examining the output log. -
maxAllowedViolations
@Parameter(property="checkstyle.maxAllowedViolations", defaultValue="0") private int maxAllowedViolationsThe maximum number of allowed violations. The execution fails only if the number of violations is above this limit.- Since:
- 2.3
-
violationSeverity
@Parameter(property="checkstyle.violationSeverity", defaultValue="error") private String violationSeverityThe lowest severity level that is considered a violation. Valid values are "error", "warning" and "info".- Since:
- 2.2
-
violationIgnore
Violations to ignore. This is a comma-separated list, each value being either a rule name, a rule category or a java package name of rule class.- Since:
- 2.13
-
skip
@Parameter(property="checkstyle.skip", defaultValue="false") private boolean skipSkip entire check.- Since:
- 2.2
-
skipExec
@Parameter(property="checkstyle.skipExec", defaultValue="false") private boolean skipExecSkip Checkstyle execution will only scan the outputFile.- Since:
- 2.5
-
logViolationsToConsole
@Parameter(property="checkstyle.console", defaultValue="true") private boolean logViolationsToConsoleOutput the detected violations to the console.- Since:
- 2.3
-
logViolationCountToConsole
@Parameter(property="checkstyle.logViolationCount", defaultValue="true") private boolean logViolationCountToConsoleOutput the detected violation count to the console.- Since:
- 3.0.1
-
resources
@Parameter(defaultValue="${project.resources}", readonly=true) protected List<org.apache.maven.model.Resource> resourcesSpecifies the location of the resources to be used for Checkstyle.- Since:
- 2.11
-
testResources
@Parameter(defaultValue="${project.testResources}", readonly=true) protected List<org.apache.maven.model.Resource> testResourcesSpecifies the location of the test resources to be used for Checkstyle.- Since:
- 2.16
-
configLocation
@Parameter(property="checkstyle.config.location", defaultValue="sun_checks.xml") private String configLocationSpecifies 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.xmlfile before being passed to Checkstyle as a configuration.There are 2 predefined rulesets.
sun_checks.xml: Sun Checks.google_checks.xml: Google Checks.
- Since:
- 2.5
-
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.propertiesfile before being passed to Checkstyle for loading.The contents of the
propertiesLocationwill be made available to Checkstyle for specifying values for parameters within the xml configuration (specified in theconfigLocationparameter).- Since:
- 2.5
-
propertyExpansion
Allows for specifying raw property expansion information. -
headerLocation
@Parameter(property="checkstyle.header.file", defaultValue="LICENSE.txt") private String headerLocationSpecifies 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>- Since:
- 2.0-beta-2
-
cacheFile
Specifies the cache file used to speed up Checkstyle on successive runs. -
suppressionsFileExpression
@Parameter(property="checkstyle.suppression.expression", defaultValue="checkstyle.suppressions.file") private String suppressionsFileExpressionThe key to be used in the properties for the suppressions file.- Since:
- 2.1
-
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.xmlfile before being passed to Checkstyle for loading.See
suppressionsFileExpressionfor the property that will be made available to your Checkstyle configuration.- Since:
- 2.0-beta-2
-
inputEncoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") private String inputEncodingThe file encoding to use when reading the source files. If the propertyproject.build.sourceEncodingis not set, the platform default encoding is used. Note: This parameter always overrides the propertycharsetfrom Checkstyle'sTreeWalkermodule.- Since:
- 2.2
-
checkstyleExecutor
@Component(role=CheckstyleExecutor.class, hint="default") protected CheckstyleExecutor checkstyleExecutor- Since:
- 2.5
-
consoleOutput
@Parameter(property="checkstyle.consoleOutput", defaultValue="false") private boolean consoleOutputOutput errors to console. -
project
@Parameter(defaultValue="${project}", readonly=true, required=true) protected org.apache.maven.project.MavenProject projectThe Maven Project Object. -
plugin
@Parameter(defaultValue="${plugin}", readonly=true, required=true) private org.apache.maven.plugin.descriptor.PluginDescriptor pluginThe Plugin Descriptor -
useFile
Ifnull, the Checkstyle plugin will display violations on stdout. Otherwise, a text file will be created with the violations. -
excludes
Specifies the names filter of the source files to be excluded for Checkstyle. -
includes
@Parameter(property="checkstyle.includes", defaultValue="**\\/*.java", required=true) private String includesSpecifies the names filter of the source files to be used for Checkstyle. -
resourceExcludes
Specifies the names filter of the files to be excluded for Checkstyle when checking resources.- Since:
- 2.11
-
resourceIncludes
@Parameter(property="checkstyle.resourceIncludes", defaultValue="**/*.properties", required=true) private String resourceIncludesSpecifies the names filter of the files to be used for Checkstyle when checking resources.- Since:
- 2.11
-
failsOnError
@Parameter(defaultValue="false") private boolean failsOnErrorIf this is true, and Checkstyle reported any violations or errors, the build fails immediately after running Checkstyle, before checking the log forlogViolationsToConsole. If you want to uselogViolationsToConsole, usefailOnViolationinstead of this. -
testSourceDirectory
Deprecated.instead usetestSourceDirectories. For version 3.0.0, this parameter is only defined to break the build if you use it!Specifies the location of the test source directory to be used for Checkstyle.- Since:
- 2.2
-
testSourceDirectories
Specifies the location of the test source directories to be used for Checkstyle. Default value is${project.testCompileSourceRoots}.- Since:
- 2.13
-
includeTestSourceDirectory
@Parameter(defaultValue="false") private boolean includeTestSourceDirectoryInclude or not the test source directory to be used for Checkstyle.- Since:
- 2.2
-
sourceDirectory
Deprecated.instead usesourceDirectories. For version 3.0.0, this parameter is only defined to break the build if you use it!Specifies the location of the source directory to be used for Checkstyle. -
sourceDirectories
Specifies the location of the source directories to be used for Checkstyle. Default value is${project.compileSourceRoots}.- Since:
- 2.13
-
includeResources
@Parameter(property="checkstyle.includeResources", defaultValue="true", required=true) private boolean includeResourcesWhether to apply Checkstyle to resource directories.- Since:
- 2.11
-
includeTestResources
@Parameter(property="checkstyle.includeTestResources", defaultValue="true", required=true) private boolean includeTestResourcesWhether to apply Checkstyle to test resource directories.- Since:
- 2.11
-
checkstyleRules
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration checkstyleRulesBy using this property, you can specify the whole Checkstyle rules inline directly inside this pom.<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> ...- Since:
- 2.12
-
rulesFiles
@Parameter(property="checkstyle.output.rules.file", defaultValue="${project.build.directory}/checkstyle-rules.xml") private File rulesFilesDump file for inlined Checkstyle rules. -
checkstyleRulesHeader
@Parameter(defaultValue="<?xml version=\"1.0\"?>\n<!DOCTYPE module PUBLIC \"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN\"\n \"https://checkstyle.org/dtds/configuration_1_3.dtd\">\n") private String checkstyleRulesHeaderThe header to use for the inline configuration. Only used when you specifycheckstyleRules. -
omitIgnoredModules
@Parameter(defaultValue="false") private boolean omitIgnoredModulesSpecifies whether modules with a configured severity ofignoreshould be omitted during Checkstyle invocation.- Since:
- 3.0.0
-
excludeGeneratedSources
@Parameter(property="checkstyle.excludeGeneratedSources", defaultValue="false") private boolean excludeGeneratedSourcesSpecifies whether generated source files should be excluded from Checkstyle.- Since:
- 3.3.1
-
stringOutputStream
-
outputXmlFile
-
-
Constructor Details
-
CheckstyleViolationCheckMojo
public CheckstyleViolationCheckMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
checkDeprecatedParameterUsage
private void checkDeprecatedParameterUsage(Object parameter, String name, String replacement) throws org.apache.maven.plugin.MojoFailureException - Throws:
org.apache.maven.plugin.MojoFailureException
-
getViolations
private List<Violation> getViolations(org.codehaus.plexus.util.xml.pull.XmlPullParser xpp) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, IOException - Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionIOException
-
countViolations
-
printViolations
-
log
-
isViolation
Checks if the given severity is considered a violation.- Parameters:
severity- The severity to check- Returns:
trueif the given severity is a violation, otherwisefalse
-
ignore
-
getConsoleListener
private com.puppycrawl.tools.checkstyle.DefaultLogger getConsoleListener() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getOutputStream
private OutputStream getOutputStream(File file) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
getListener
private com.puppycrawl.tools.checkstyle.api.AuditListener getListener() throws org.apache.maven.plugin.MojoFailureException, org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoFailureExceptionorg.apache.maven.plugin.MojoExecutionException
-
collectArtifacts
-
getCheckstylePluginDependenciesAsArtifacts
-
getSourceDirectories
-
getTestSourceDirectories
-
filterBuildTarget
-
sourceDirectories.