Class EnforceMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.enforcer.EnforceMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
@Mojo(name="enforce",
defaultPhase=VALIDATE,
requiresDependencyCollection=TEST,
threadSafe=true)
public class EnforceMojo
extends org.apache.maven.plugin.AbstractMojo
This goal executes the defined enforcer-rules once per module.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Hashtable
<String, EnforcerRule> This is a static variable used to persist the cached results across plugin invocations.private org.codehaus.plexus.PlexusContainer
private EnforcerRuleManager
private boolean
Flag to fail the build if at least one check fails.private boolean
Fail on the first rule that doesn't passprivate boolean
Flag to fail the build if no rules are presentprotected boolean
Use this flag to disable rule result caching.protected org.apache.maven.plugin.MojoExecution
MojoExecution needed by the ExpressionEvaluatorprotected org.apache.maven.project.MavenProject
POMprivate EnforcerRuleCache
private org.codehaus.plexus.configuration.PlexusConfiguration
Rules configuration to execute as XML.List of strings that matches the EnforcerRules to skip.protected org.apache.maven.execution.MavenSession
The MavenSessionprotected boolean
Flag to easily skip all checksFields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
createRuleMessage
(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerLevel level, EnforcerRuleException e) private Optional
<org.codehaus.plexus.configuration.PlexusConfiguration> Create rules configuration based on command line provided rules list.void
execute()
private void
executeRule
(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerRuleHelper helper) private org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration
executeRuleConfigProvider
(EnforcerRuleDesc ruleDesc) private void
executeRuleNew
(int ruleIndex, EnforcerRuleDesc ruleDesc) private void
executeRuleOld
(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerRuleHelper helper) private List
<EnforcerRuleDesc> filterOutRuleConfigProviders
(List<EnforcerRuleDesc> rulesList) private List
<EnforcerRuleDesc> filterOutSkippedRules
(List<EnforcerRuleDesc> allRules) Filter out (remove) rules that have been specifically skipped via additional configuration.private String
getRuleName
(EnforcerRuleDesc ruleDesc) private List
<EnforcerRuleDesc> processRuleConfigProviders
(List<EnforcerRuleDesc> rulesList) void
setCommandLineRules
(List<String> rulesToExecute) Deprecated.void
setFail
(boolean theFail) void
setFailFast
(boolean theFailFast) void
setFailIfNoRules
(boolean thefailIfNoRules) void
setRulesToExecute
(List<String> rulesToExecute) List of strings that matches the EnforcerRules to execute.void
setRulesToSkip
(List<String> rulesToSkip) Set rule list to skip.protected boolean
shouldExecute
(EnforcerRule rule) This method determines if a rule should execute based on the cacheMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
cache
This is a static variable used to persist the cached results across plugin invocations. -
mojoExecution
@Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) protected org.apache.maven.plugin.MojoExecution mojoExecutionMojoExecution needed by the ExpressionEvaluator -
session
@Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession sessionThe MavenSession -
project
@Parameter(defaultValue="${project}", readonly=true, required=true) protected org.apache.maven.project.MavenProject projectPOM -
skip
@Parameter(property="enforcer.skip", defaultValue="false") protected boolean skipFlag to easily skip all checks -
fail
@Parameter(property="enforcer.fail", defaultValue="true") private boolean failFlag to fail the build if at least one check fails. -
failFast
@Parameter(property="enforcer.failFast", defaultValue="false") private boolean failFastFail on the first rule that doesn't pass -
failIfNoRules
@Parameter(property="enforcer.failIfNoRules", defaultValue="true") private boolean failIfNoRulesFlag to fail the build if no rules are present- Since:
- 3.2.0
-
rules
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration rulesRules configuration to execute as XML. Each first level tag represents rule name to execute. Inner tags are configurations for rule. Eg:<rules> <alwaysFail/> <alwaysPass> <message>message for rule</message> </alwaysPass> <myRule implementation="org.example.MyRule"/> </rules>
- Since:
- 1.0.0
-
rulesToSkip
List of strings that matches the EnforcerRules to skip.- Since:
- 3.2.0
-
ignoreCache
@Parameter(property="enforcer.ignoreCache", defaultValue="false") protected boolean ignoreCacheUse this flag to disable rule result caching. This will cause all rules to execute on each project even if the rule indicates it can safely be cached. -
container
@Component private org.codehaus.plexus.PlexusContainer container -
enforcerRuleManager
-
ruleCache
-
rulesToExecute
-
-
Constructor Details
-
EnforceMojo
public EnforceMojo()
-
-
Method Details
-
setRulesToExecute
@Parameter(required=false, property="enforcer.rules") public void setRulesToExecute(List<String> rulesToExecute) throws org.apache.maven.plugin.MojoExecutionException List of strings that matches the EnforcerRules to execute. Replacement for therules
property.- Parameters:
rulesToExecute
- a rules to execute- Throws:
org.apache.maven.plugin.MojoExecutionException
- when values are incorrect- Since:
- 3.2.0
-
setCommandLineRules
@Parameter(required=false, property="rules") @Deprecated public void setCommandLineRules(List<String> rulesToExecute) throws org.apache.maven.plugin.MojoExecutionException Deprecated.Useenforcer.rules
property insteadList of strings that matches the EnforcerRules to execute.- Parameters:
rulesToExecute
- a rules to execute- Throws:
org.apache.maven.plugin.MojoExecutionException
- when values are incorrect
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
processRuleConfigProviders
-
filterOutRuleConfigProviders
-
executeRuleConfigProvider
private org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration executeRuleConfigProvider(EnforcerRuleDesc ruleDesc) -
executeRule
private void executeRule(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerRuleHelper helper) throws EnforcerRuleException - Throws:
EnforcerRuleException
-
executeRuleOld
private void executeRuleOld(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerRuleHelper helper) throws EnforcerRuleException - Throws:
EnforcerRuleException
-
executeRuleNew
- Throws:
EnforcerRuleException
-
createRulesFromCommandLineOptions
private Optional<org.codehaus.plexus.configuration.PlexusConfiguration> createRulesFromCommandLineOptions()Create rules configuration based on command line provided rules list.- Returns:
- an configuration in case where rules list is present or empty
-
filterOutSkippedRules
Filter out (remove) rules that have been specifically skipped via additional configuration.- Parameters:
allRules
- list of enforcer rules to go through and filter- Returns:
- list of filtered rules
-
shouldExecute
This method determines if a rule should execute based on the cache- Parameters:
rule
- the rule to verify- Returns:
true
if rule should be executed, otherwisefalse
-
setRulesToSkip
Set rule list to skip.- Parameters:
rulesToSkip
- a rule list
-
setFail
public void setFail(boolean theFail) - Parameters:
theFail
- the fail to set
-
setFailFast
public void setFailFast(boolean theFailFast) - Parameters:
theFailFast
- the failFast to set
-
createRuleMessage
private String createRuleMessage(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerLevel level, EnforcerRuleException e) -
getRuleName
-
setFailIfNoRules
public void setFailIfNoRules(boolean thefailIfNoRules) - Parameters:
thefailIfNoRules
- the failIfNoRules to set
-
enforcer.rules
property instead