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,org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
@Mojo(name="enforce",
defaultPhase=VALIDATE,
requiresDependencyCollection=TEST,
threadSafe=true)
public class EnforceMojo
extends org.apache.maven.plugin.AbstractMojo
implements org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
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 String[]Array of Strings that matches the EnforcerRules to execute.protected org.codehaus.plexus.PlexusContainerprivate booleanFlag to fail the build if a version check fails.private booleanFail on the first rule that doesn't passprotected booleanUse this flag to disable rule result caching.protected org.apache.maven.plugin.MojoExecutionMojoExecution needed by the ExpressionEvaluatorprotected org.apache.maven.project.MavenProjectPOMprivate EnforcerRule[]Array of objects that implement the EnforcerRule interface to execute.protected org.apache.maven.execution.MavenSessionThe MavenSessionprotected booleanFlag to easily skip all checksFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcontextualize(org.codehaus.plexus.context.Context context) protected StringcreateRuleMessage(int i, String currentRule, EnforcerRuleException e) private EnforcerRule[]voidexecute()private EnforcerLevelgetLevel(EnforcerRule rule) Returns the level of the rule, defaults toEnforcerLevel.ERRORfor backwards compatibility.org.apache.maven.project.MavenProjectgetRules()org.apache.maven.execution.MavenSessionprivate booleanbooleanisFail()booleanbooleanisSkip()voidsetFail(boolean theFail) voidsetFailFast(boolean theFailFast) voidsetProject(org.apache.maven.project.MavenProject theProject) voidsetRules(EnforcerRule[] theRules) voidsetSession(org.apache.maven.execution.MavenSession theSession) voidsetSkip(boolean theSkip) protected booleanshouldExecute(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 a version check fails. -
failFast
@Parameter(property="enforcer.failFast", defaultValue="false") private boolean failFastFail on the first rule that doesn't pass -
rules
Array of objects that implement the EnforcerRule interface to execute. -
commandLineRules
Array of Strings that matches the EnforcerRules to execute. -
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
protected org.codehaus.plexus.PlexusContainer container
-
-
Constructor Details
-
EnforceMojo
public EnforceMojo()
-
-
Method Details
-
contextualize
public void contextualize(org.codehaus.plexus.context.Context context) throws org.codehaus.plexus.context.ContextException - Specified by:
contextualizein interfaceorg.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable- Throws:
org.codehaus.plexus.context.ContextException
-
havingRules
private boolean havingRules() -
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Specified by:
executein interfaceorg.apache.maven.plugin.Mojo- Throws:
org.apache.maven.plugin.MojoExecutionException
-
createRulesFromCommandLineOptions
private EnforcerRule[] createRulesFromCommandLineOptions() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
shouldExecute
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
-
isFail
public boolean isFail()- Returns:
- the fail
-
setFail
public void setFail(boolean theFail) - Parameters:
theFail- the fail to set
-
getRules
- Returns:
- the rules
-
setRules
- Parameters:
theRules- the rules to set
-
setFailFast
public void setFailFast(boolean theFailFast) - Parameters:
theFailFast- the failFast to set
-
isFailFast
public boolean isFailFast() -
createRuleMessage
-
getLevel
Returns the level of the rule, defaults toEnforcerLevel.ERRORfor backwards compatibility.- Parameters:
rule- might be of typeEnforcerRule2.- Returns:
- level of the rule.
-
isSkip
public boolean isSkip()- Returns:
- the skip
-
setSkip
public void setSkip(boolean theSkip) - Parameters:
theSkip- the skip to set
-
getProject
public org.apache.maven.project.MavenProject getProject()- Returns:
- the project
-
setProject
public void setProject(org.apache.maven.project.MavenProject theProject) - Parameters:
theProject- the project to set
-
getSession
public org.apache.maven.execution.MavenSession getSession()- Returns:
- the session
-
setSession
public void setSession(org.apache.maven.execution.MavenSession theSession) - Parameters:
theSession- the session to set
-