Class AbstractCheckstyleReport
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.reporting.AbstractMavenReport
-
- org.apache.maven.plugins.checkstyle.AbstractCheckstyleReport
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo,org.apache.maven.reporting.MavenMultiPageReport,org.apache.maven.reporting.MavenReport
- Direct Known Subclasses:
CheckstyleAggregateReport,CheckstyleReport
public abstract class AbstractCheckstyleReport extends org.apache.maven.reporting.AbstractMavenReportBase abstract class for Checkstyle reports.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcacheFileSpecifies the cache file used to speed up Checkstyle on successive runs.protected CheckstyleExecutorcheckstyleExecutorprivate org.codehaus.plexus.configuration.PlexusConfigurationcheckstyleRulesBy using this property, you can specify the whole Checkstyle rules inline directly inside this pom.private java.lang.StringcheckstyleRulesHeaderThe header to use for the inline configuration.protected java.lang.StringconfigLocationSpecifies the location of the XML configuration to use.protected booleanconsoleOutputOutput errors to console.private static java.lang.StringDEFAULT_CONFIG_LOCATIONprivate booleanenableFilesSummarySpecifies if the Files summary should be enabled or not.private booleanenableRulesSummarySpecifies if the Rules summary should be enabled or not.private booleanenableSeveritySummarySpecifies if the Severity summary should be enabled or not.private booleanexcludeGeneratedSourcesSpecifies whether generated source files should be excluded from Checkstyle.protected java.lang.StringexcludesSpecifies the names filter of the source files to be excluded for Checkstyle.protected booleanfailsOnErrorSpecifies if the build should fail upon a violation.protected java.lang.StringheaderLocationSpecifies the location of the License file (a.k.a.private org.codehaus.plexus.i18n.I18Ni18nInternationalization componentprotected booleanincludeResourcesSpecifies whether to include the resource directories in the check.protected java.lang.StringincludesSpecifies the names filter of the source files to be used for Checkstyle.protected booleanincludeTestResourcesSpecifies whether to include the test resource directories in the check.protected booleanincludeTestSourceDirectoryInclude or not the test source directory/directories to be used for Checkstyle.protected static java.lang.StringJAVA_FILESprivate booleanlinkXRefLink the violation line numbers to the (Test) Source XRef.protected org.codehaus.plexus.resource.ResourceManagerlocatorprivate booleanomitIgnoredModulesSpecifies whether modules with a configured severity ofignoreshould be omitted during Checkstyle invocation.private java.io.FileoutputFileSpecifies the path and filename to save the Checkstyle output.private java.lang.StringoutputFileFormatSpecifies the format of the output to be used when writing to the output file.private org.apache.maven.plugin.descriptor.PluginDescriptorpluginThe Plugin Descriptorprotected java.lang.StringpropertiesLocationSpecifies the location of the properties file.protected java.lang.StringpropertyExpansionAllows for specifying raw property expansion information.protected java.lang.StringresourceExcludesSpecifies the names filter of the resource files to be excluded for Checkstyle.protected java.lang.StringresourceIncludesSpecifies the names filter of the resource files to be used for Checkstyle.protected java.util.List<org.apache.maven.model.Resource>resourcesSpecifies the location of the resources to be used for Checkstyle.private java.io.FilerulesFilesDump file for inlined Checkstyle rules.private org.apache.maven.execution.MavenSessionsessionprotected booleanskipSkip entire check.private java.util.List<java.lang.String>sourceDirectoriesSpecifies the location of the source directories to be used for Checkstyle.private java.io.FilesourceDirectoryDeprecated.instead usesourceDirectories.protected java.io.ByteArrayOutputStreamstringOutputStreamprotected java.lang.StringsuppressionsFileExpressionThe key to be used in the properties for the suppressions file.protected java.lang.StringsuppressionsLocationSpecifies the location of the suppressions XML file to use.protected java.util.List<org.apache.maven.model.Resource>testResourcesSpecifies the location of the test resources to be used for Checkstyle.private java.util.List<java.lang.String>testSourceDirectoriesSpecifies the location of the test source directories to be used for Checkstyle.private java.io.FiletestSourceDirectoryDeprecated.instead usetestSourceDirectories.private java.util.List<java.lang.String>treeWalkerNamesWhen using custom treeWalkers, specify their names here so the checks inside the treeWalker end up the the rule-summary.private java.io.FileuseFileIfnull, the Checkstyle plugin will display violations on stdout.private java.io.FilexrefLocationLocation where Source XRef is generated for this project.private java.io.FilexrefTestLocationLocation where Test Source XRef is generated for this project.-
Fields inherited from class org.apache.maven.reporting.AbstractMavenReport
locale, mojoExecution, outputDirectory, outputFormat, outputTimestamp, project, reactorProjects, remoteProjectRepositories, repoSession, siteDirectory, siteRenderer, siteTool
-
-
Constructor Summary
Constructors Constructor Description AbstractCheckstyleReport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidcheckDeprecatedParameterUsage(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)protected abstract CheckstyleExecutorRequestcreateRequest()Create the Checkstyle executor request.private java.lang.StringdetermineRelativePath(java.io.File location)voidexecuteReport(java.util.Locale locale)private java.util.List<java.lang.String>filterBuildTarget(java.util.List<java.lang.String> sourceDirectories)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)protected com.puppycrawl.tools.checkstyle.DefaultLoggergetConsoleListener()Creates and returns the console listener.java.lang.StringgetDescription(java.util.Locale locale)protected java.lang.StringgetI18nString(java.util.Locale locale, java.lang.String key)protected com.puppycrawl.tools.checkstyle.api.AuditListenergetListener()Creates and returns the report generation listener.java.lang.StringgetName(java.util.Locale locale)private java.io.OutputStreamgetOutputStream(java.io.File file)protected org.apache.maven.project.MavenProjectgetProject()protected java.util.List<org.apache.maven.project.MavenProject>getReactorProjects()protected java.util.List<java.io.File>getSourceDirectories()protected java.util.List<java.io.File>getTestSourceDirectories()-
Methods inherited from class org.apache.maven.reporting.AbstractMavenReport
canGenerateReport, closeReport, constructXrefLocation, execute, generate, generate, getCategoryName, getInputEncoding, getLocale, getOutputDirectory, getOutputEncoding, getReportOutputDirectory, getSink, getSinkFactory, getSiteRenderer, getXrefLocation, isExternalReport, setReportOutputDirectory
-
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
-
-
-
Field Detail
-
JAVA_FILES
protected static final java.lang.String JAVA_FILES
- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_LOCATION
private static final java.lang.String DEFAULT_CONFIG_LOCATION
- See Also:
- Constant Field Values
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
-
cacheFile
@Parameter(defaultValue="${project.build.directory}/checkstyle-cachefile") protected java.lang.String cacheFileSpecifies the cache file used to speed up Checkstyle on successive runs.
-
configLocation
@Parameter(property="checkstyle.config.location", defaultValue="sun_checks.xml") protected java.lang.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 included in Maven Checkstyle Plugin:
sun_checks.xml: Sun Checks.google_checks.xml: Google Checks.
-
consoleOutput
@Parameter(property="checkstyle.consoleOutput", defaultValue="false") protected boolean consoleOutputOutput errors to console.
-
failsOnError
@Parameter(defaultValue="false") protected boolean failsOnError
Specifies if the build should fail upon a violation.
-
headerLocation
@Parameter(property="checkstyle.header.file", defaultValue="LICENSE.txt") protected java.lang.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
-
skip
@Parameter(property="checkstyle.skip", defaultValue="false") protected boolean skipSkip entire check.- Since:
- 2.2
-
outputFile
@Parameter(property="checkstyle.output.file", defaultValue="${project.build.directory}/checkstyle-result.xml") private java.io.File outputFileSpecifies the path and filename to save the Checkstyle output. The format of the output file is determined by theoutputFileFormatparameter.
-
propertiesLocation
@Parameter(property="checkstyle.properties.location") protected 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.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.0-beta-2
-
propertyExpansion
@Parameter protected java.lang.String propertyExpansion
Allows for specifying raw property expansion information.
-
resources
@Parameter(defaultValue="${project.resources}", readonly=true) protected java.util.List<org.apache.maven.model.Resource> resourcesSpecifies the location of the resources to be used for Checkstyle.- Since:
- 2.10
-
testResources
@Parameter(defaultValue="${project.testResources}", readonly=true) protected java.util.List<org.apache.maven.model.Resource> testResourcesSpecifies the location of the test resources to be used for Checkstyle.- Since:
- 2.11
-
includes
@Parameter(property="checkstyle.includes", defaultValue="**\\/*.java", required=true) protected java.lang.String includesSpecifies the names filter of the source files to be used for Checkstyle.
-
excludes
@Parameter(property="checkstyle.excludes") protected java.lang.String excludes
Specifies the names filter of the source files to be excluded for Checkstyle.
-
resourceIncludes
@Parameter(property="checkstyle.resourceIncludes", defaultValue="**/*.properties", required=true) protected java.lang.String resourceIncludesSpecifies the names filter of the resource files to be used for Checkstyle.- Since:
- 2.11
-
resourceExcludes
@Parameter(property="checkstyle.resourceExcludes") protected java.lang.String resourceExcludes
Specifies the names filter of the resource files to be excluded for Checkstyle.- Since:
- 2.11
-
includeResources
@Parameter(property="checkstyle.includeResources", defaultValue="true", required=true) protected boolean includeResourcesSpecifies whether to include the resource directories in the check.- Since:
- 2.11
-
includeTestResources
@Parameter(property="checkstyle.includeTestResources", defaultValue="true", required=true) protected boolean includeTestResourcesSpecifies whether to include the test resource directories in the check.- Since:
- 2.11
-
sourceDirectory
@Deprecated @Parameter private java.io.File 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
@Parameter private java.util.List<java.lang.String> sourceDirectories
Specifies the location of the source directories to be used for Checkstyle. Default value is${project.compileSourceRoots}.- Since:
- 2.13
-
testSourceDirectory
@Parameter @Deprecated private java.io.File 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
@Parameter private java.util.List<java.lang.String> 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") protected boolean includeTestSourceDirectory
Include or not the test source directory/directories to be used for Checkstyle.- Since:
- 2.2
-
suppressionsFileExpression
@Parameter(property="checkstyle.suppression.expression", defaultValue="checkstyle.suppressions.file") protected java.lang.String suppressionsFileExpressionThe key to be used in the properties for the suppressions file.- Since:
- 2.1
-
suppressionsLocation
@Parameter(property="checkstyle.suppressions.location") protected 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-supressions.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
-
useFile
@Parameter private java.io.File useFile
Ifnull, the Checkstyle plugin will display violations on stdout. Otherwise, a text file will be created with the violations.
-
outputFileFormat
@Parameter(property="checkstyle.output.format", defaultValue="xml") private java.lang.String outputFileFormatSpecifies the format of the output to be used when writing to the output file. Valid values are "plain", "sarif" and "xml".
-
enableRulesSummary
@Parameter(property="checkstyle.enable.rules.summary", defaultValue="true") private boolean enableRulesSummarySpecifies if the Rules summary should be enabled or not.
-
enableSeveritySummary
@Parameter(property="checkstyle.enable.severity.summary", defaultValue="true") private boolean enableSeveritySummarySpecifies if the Severity summary should be enabled or not.
-
enableFilesSummary
@Parameter(property="checkstyle.enable.files.summary", defaultValue="true") private boolean enableFilesSummarySpecifies if the Files summary should be enabled or not.
-
plugin
@Parameter(defaultValue="${plugin}", readonly=true, required=true) private org.apache.maven.plugin.descriptor.PluginDescriptor pluginThe Plugin Descriptor
-
linkXRef
@Parameter(property="linkXRef", defaultValue="true") private boolean linkXRefLink the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is being used.- Since:
- 2.1
-
xrefLocation
@Parameter private java.io.File xrefLocation
Location where Source XRef is generated for this project.
Default:AbstractMavenReport.getReportOutputDirectory()+/xref
-
xrefTestLocation
@Parameter private java.io.File xrefTestLocation
Location where Test Source XRef is generated for this project.
Default:AbstractMavenReport.getReportOutputDirectory()+/xref-test
-
treeWalkerNames
@Parameter private java.util.List<java.lang.String> treeWalkerNames
When using custom treeWalkers, specify their names here so the checks inside the treeWalker end up the the rule-summary.- Since:
- 2.11
-
omitIgnoredModules
@Parameter(defaultValue="false") private boolean omitIgnoredModules
Specifies whether modules with a configured severity ofignoreshould be omitted during Checkstyle invocation.- Since:
- 3.0.0
-
checkstyleRules
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration checkstyleRules
By 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 java.io.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 java.lang.String checkstyleRulesHeader
The header to use for the inline configuration. Only used when you specifycheckstyleRules.
-
excludeGeneratedSources
@Parameter(property="checkstyle.excludeGeneratedSources", defaultValue="false") private boolean excludeGeneratedSourcesSpecifies whether generated source files should be excluded from Checkstyle.- Since:
- 3.3.1
-
locator
@Component protected org.codehaus.plexus.resource.ResourceManager locator
-
checkstyleExecutor
@Component(role=CheckstyleExecutor.class, hint="default") protected CheckstyleExecutor checkstyleExecutor
- Since:
- 2.5
-
i18n
@Component private org.codehaus.plexus.i18n.I18N i18n
Internationalization component
-
stringOutputStream
protected java.io.ByteArrayOutputStream stringOutputStream
-
-
Method Detail
-
getName
public java.lang.String getName(java.util.Locale locale)
-
getDescription
public java.lang.String getDescription(java.util.Locale locale)
-
getI18nString
protected java.lang.String getI18nString(java.util.Locale locale, java.lang.String key)- Parameters:
locale- The localekey- The key to search for- Returns:
- The text appropriate for the locale.
-
getProject
protected org.apache.maven.project.MavenProject getProject()
- Overrides:
getProjectin classorg.apache.maven.reporting.AbstractMavenReport
-
getReactorProjects
protected java.util.List<org.apache.maven.project.MavenProject> getReactorProjects()
-
executeReport
public void executeReport(java.util.Locale locale) throws org.apache.maven.reporting.MavenReportException- Specified by:
executeReportin classorg.apache.maven.reporting.AbstractMavenReport- Throws:
org.apache.maven.reporting.MavenReportException
-
checkDeprecatedParameterUsage
private void checkDeprecatedParameterUsage(java.lang.Object parameter, java.lang.String name, java.lang.String replacement) throws org.apache.maven.reporting.MavenReportException- Throws:
org.apache.maven.reporting.MavenReportException
-
createRequest
protected abstract CheckstyleExecutorRequest createRequest() throws org.apache.maven.reporting.MavenReportException
Create the Checkstyle executor request.- Returns:
- The executor request.
- Throws:
org.apache.maven.reporting.MavenReportException- If something goes wrong during creation.
-
collectArtifacts
private java.util.List<org.apache.maven.artifact.Artifact> collectArtifacts(java.lang.String hint)
-
getCheckstylePluginDependenciesAsArtifacts
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)
-
getListener
protected com.puppycrawl.tools.checkstyle.api.AuditListener getListener() throws org.apache.maven.reporting.MavenReportExceptionCreates and returns the report generation listener.- Returns:
- The audit listener.
- Throws:
org.apache.maven.reporting.MavenReportException- If something goes wrong.
-
getOutputStream
private java.io.OutputStream getOutputStream(java.io.File file) throws org.apache.maven.reporting.MavenReportException- Throws:
org.apache.maven.reporting.MavenReportException
-
getConsoleListener
protected com.puppycrawl.tools.checkstyle.DefaultLogger getConsoleListener() throws org.apache.maven.reporting.MavenReportExceptionCreates and returns the console listener.- Returns:
- The console listener.
- Throws:
org.apache.maven.reporting.MavenReportException- If something goes wrong.
-
determineRelativePath
private java.lang.String determineRelativePath(java.io.File location)
-
getSourceDirectories
protected java.util.List<java.io.File> getSourceDirectories()
-
getTestSourceDirectories
protected java.util.List<java.io.File> getTestSourceDirectories()
-
filterBuildTarget
private java.util.List<java.lang.String> filterBuildTarget(java.util.List<java.lang.String> sourceDirectories)
-
-