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.
Version:
$Id: EnforceMojo.java 1696663 2015-08-19 20:20:14Z khmarbaise $
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static Hashtable<String,EnforcerRule>
    This is a static variable used to persist the cached results across plugin invocations.
    protected org.codehaus.plexus.PlexusContainer
     
    private boolean
    Flag to fail the build if a version check fails.
    private boolean
    Fail on the first rule that doesn't pass
    protected boolean
    Use this flag to disable rule result caching.
    protected org.apache.maven.plugin.MojoExecution
    MojoExecution needed by the ExpressionEvaluator
    protected org.apache.maven.project.MavenProject
    POM
    private EnforcerRule[]
    Array of objects that implement the EnforcerRule interface to execute.
    protected org.apache.maven.execution.MavenSession
    The MavenSession
    protected boolean
    Flag to easily skip all checks
    protected org.apache.maven.project.path.PathTranslator
    Path Translator needed by the ExpressionEvaluator

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    contextualize(org.codehaus.plexus.context.Context context)
     
    protected String
     
    void
    Entry point to the mojo
    Returns the level of the rule, defaults to EnforcerLevel.ERROR for backwards compatibility.
    org.apache.maven.project.MavenProject
     
     
    org.apache.maven.execution.MavenSession
     
    org.apache.maven.project.path.PathTranslator
     
    boolean
     
    boolean
     
    boolean
     
    void
    setFail(boolean theFail)
     
    void
    setFailFast(boolean theFailFast)
     
    void
    setProject(org.apache.maven.project.MavenProject theProject)
     
    void
    setRules(EnforcerRule[] theRules)
     
    void
    setSession(org.apache.maven.execution.MavenSession theSession)
     
    void
    setSkip(boolean theSkip)
     
    void
    setTranslator(org.apache.maven.project.path.PathTranslator theTranslator)
     
    protected boolean
    This method determines if a rule should execute based on the cache

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • cache

      protected static Hashtable<String,EnforcerRule> cache
      This is a static variable used to persist the cached results across plugin invocations.
    • translator

      @Component(role=org.apache.maven.project.path.PathTranslator.class) protected org.apache.maven.project.path.PathTranslator translator
      Path Translator needed by the ExpressionEvaluator
    • mojoExecution

      @Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) protected org.apache.maven.plugin.MojoExecution mojoExecution
      MojoExecution needed by the ExpressionEvaluator
    • session

      @Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession session
      The MavenSession
    • project

      @Parameter(defaultValue="${project}", readonly=true, required=true) protected org.apache.maven.project.MavenProject project
      POM
    • skip

      @Parameter(property="enforcer.skip", defaultValue="false") protected boolean skip
      Flag to easily skip all checks
    • fail

      @Parameter(property="enforcer.fail", defaultValue="true") private boolean fail
      Flag to fail the build if a version check fails.
    • failFast

      @Parameter(property="enforcer.failFast", defaultValue="false") private boolean failFast
      Fail on the first rule that doesn't pass
    • rules

      @Parameter(required=true) private EnforcerRule[] rules
      Array of objects that implement the EnforcerRule interface to execute.
    • ignoreCache

      @Parameter(property="enforcer.ignoreCache", defaultValue="false") protected boolean ignoreCache
      Use 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:
      contextualize in interface org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
      Throws:
      org.codehaus.plexus.context.ContextException
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Entry point to the mojo
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • 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:
      true if rule should be executed, otherwise false
    • isFail

      public boolean isFail()
      Returns:
      the fail
    • setFail

      public void setFail(boolean theFail)
      Parameters:
      theFail - the fail to set
    • getRules

      public EnforcerRule[] getRules()
      Returns:
      the rules
    • setRules

      public void setRules(EnforcerRule[] theRules)
      Parameters:
      theRules - the rules to set
    • setFailFast

      public void setFailFast(boolean theFailFast)
      Parameters:
      theFailFast - the failFast to set
    • isFailFast

      public boolean isFailFast()
    • createRuleMessage

      protected String createRuleMessage(int i, String currentRule, EnforcerRuleException e)
    • setTranslator

      public void setTranslator(org.apache.maven.project.path.PathTranslator theTranslator)
      Parameters:
      theTranslator - the translator to set
    • getLevel

      private EnforcerLevel getLevel(EnforcerRule rule)
      Returns the level of the rule, defaults to EnforcerLevel.ERROR for backwards compatibility.
      Parameters:
      rule - might be of type EnforcerRule2.
      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
    • getTranslator

      public org.apache.maven.project.path.PathTranslator getTranslator()
      Returns:
      the translator