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.AbstractMojoThis goal executes the defined enforcer-rules once per module.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.Map<java.lang.String,EnforcerRule>cacheThis is a static variable used to persist the cached results across plugin invocations.private org.codehaus.plexus.PlexusContainercontainerprivate EnforcerRuleManagerenforcerRuleManagerprivate booleanfailFlag to fail the build if at least one check fails.private booleanfailFastFail on the first rule that doesn't passprivate booleanfailIfNoRulesFlag to fail the build if no rules are presentprotected booleanignoreCacheUse this flag to disable rule result caching.protected org.apache.maven.plugin.MojoExecutionmojoExecutionMojoExecution needed by the ExpressionEvaluatorprotected org.apache.maven.project.MavenProjectprojectPOMprivate EnforcerRuleCacheruleCacheprivate org.codehaus.plexus.configuration.PlexusConfigurationrulesRules configuration to execute as XML.private java.util.List<java.lang.String>rulesToExecuteprivate java.util.List<java.lang.String>rulesToSkipList of strings that matches the EnforcerRules to skip.protected org.apache.maven.execution.MavenSessionsessionThe MavenSessionprotected booleanskipFlag to easily skip all checks
-
Constructor Summary
Constructors Constructor Description EnforceMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private java.lang.StringcreateRuleMessage(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerLevel level, EnforcerRuleException e)private java.util.Optional<org.codehaus.plexus.configuration.PlexusConfiguration>createRulesFromCommandLineOptions()Create rules configuration based on command line provided rules list.voidexecute()private voidexecuteRule(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerRuleHelper helper)private org.codehaus.plexus.configuration.xml.XmlPlexusConfigurationexecuteRuleConfigProvider(EnforcerRuleDesc ruleDesc)private voidexecuteRuleNew(int ruleIndex, EnforcerRuleDesc ruleDesc)private voidexecuteRuleOld(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerRuleHelper helper)private java.util.List<EnforcerRuleDesc>filterOutRuleConfigProviders(java.util.List<EnforcerRuleDesc> rulesList)private java.util.List<EnforcerRuleDesc>filterOutSkippedRules(java.util.List<EnforcerRuleDesc> allRules)Filter out (remove) rules that have been specifically skipped via additional configuration.private java.lang.StringgetRuleName(EnforcerRuleDesc ruleDesc)private java.util.List<EnforcerRuleDesc>processRuleConfigProviders(java.util.List<EnforcerRuleDesc> rulesList)voidsetCommandLineRules(java.util.List<java.lang.String> rulesToExecute)Deprecated.Useenforcer.rulesproperty insteadvoidsetFail(boolean fail)voidsetFailFast(boolean failFast)voidsetFailIfNoRules(boolean failIfNoRules)voidsetRulesToExecute(java.util.List<java.lang.String> rulesToExecute)List of strings that matches the EnforcerRules to execute.voidsetRulesToSkip(java.util.List<java.lang.String> rulesToSkip)Set rule list to skip.protected booleanshouldExecute(EnforcerRule rule)This method determines if a rule should execute based on the cache
-
-
-
Field Detail
-
cache
protected static java.util.Map<java.lang.String,EnforcerRule> 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 rules
Rules 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
@Parameter(required=false, property="enforcer.skipRules") private java.util.List<java.lang.String> rulesToSkipList 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
@Component private EnforcerRuleManager enforcerRuleManager
-
ruleCache
@Component private EnforcerRuleCache ruleCache
-
rulesToExecute
private java.util.List<java.lang.String> rulesToExecute
-
-
Method Detail
-
setRulesToExecute
@Parameter(required=false, property="enforcer.rules") public void setRulesToExecute(java.util.List<java.lang.String> rulesToExecute) throws org.apache.maven.plugin.MojoExecutionExceptionList of strings that matches the EnforcerRules to execute. Replacement for therulesproperty.- 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(java.util.List<java.lang.String> rulesToExecute) throws org.apache.maven.plugin.MojoExecutionExceptionDeprecated.Useenforcer.rulesproperty 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
private java.util.List<EnforcerRuleDesc> processRuleConfigProviders(java.util.List<EnforcerRuleDesc> rulesList)
-
filterOutRuleConfigProviders
private java.util.List<EnforcerRuleDesc> filterOutRuleConfigProviders(java.util.List<EnforcerRuleDesc> rulesList)
-
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
private void executeRuleNew(int ruleIndex, EnforcerRuleDesc ruleDesc) throws EnforcerRuleException- Throws:
EnforcerRuleException
-
createRulesFromCommandLineOptions
private java.util.Optional<org.codehaus.plexus.configuration.PlexusConfiguration> createRulesFromCommandLineOptions()
Create rules configuration based on command line provided rules list.- Returns:
- a configuration in case where rules list is present or empty
-
filterOutSkippedRules
private java.util.List<EnforcerRuleDesc> filterOutSkippedRules(java.util.List<EnforcerRuleDesc> allRules)
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
protected boolean shouldExecute(EnforcerRule rule)
This method determines if a rule should execute based on the cache- Parameters:
rule- the rule to verify- Returns:
trueif rule should be executed, otherwisefalse
-
setRulesToSkip
public void setRulesToSkip(java.util.List<java.lang.String> rulesToSkip)
Set rule list to skip.- Parameters:
rulesToSkip- a rule list
-
setFail
public void setFail(boolean fail)
- Parameters:
fail- whether to fail
-
setFailFast
public void setFailFast(boolean failFast)
- Parameters:
failFast- whether to fail fast
-
createRuleMessage
private java.lang.String createRuleMessage(int ruleIndex, EnforcerRuleDesc ruleDesc, EnforcerLevel level, EnforcerRuleException e)
-
getRuleName
private java.lang.String getRuleName(EnforcerRuleDesc ruleDesc)
-
setFailIfNoRules
public void setFailIfNoRules(boolean failIfNoRules)
- Parameters:
failIfNoRules- whether to fail if there are no rules
-
-