Class RequirePropertyDiverges

java.lang.Object
org.apache.maven.plugins.enforcer.AbstractMojoHausEnforcerRule
org.apache.maven.plugins.enforcer.RequirePropertyDiverges
All Implemented Interfaces:
org.apache.maven.enforcer.rule.api.EnforcerRule, org.apache.maven.enforcer.rule.api.EnforcerRule2

public class RequirePropertyDiverges extends AbstractMojoHausEnforcerRule
This rule checks that certain properties are set and diverge from the ones given in another project. This allows to enforce that a property is e.g. overridden in a child project.
Since:
1.0-alpha-3
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    Creates the DOM of the invoking rule, but returns the children alphabetically sorted.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
     
    private String
     
    private String
    Specify the required property.
    private String
    Match the property value to a given regular expression.
    private final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addRules(org.codehaus.plexus.util.xml.Xpp3Dom configuration, List<org.codehaus.plexus.util.xml.Xpp3Dom> ruleConfigurations)
    Add the rules found in the given configuration to the list of rule configurations.
    (package private) void
    checkAgainstParentValue(org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parent, org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper, Object propValue)
    Checks the value of the project against the one given in the defining ancestor project.
    (package private) void
    Checks the value of the project against the given regex.
    (package private) void
    Checks that the property is not null or empty string
    (package private) org.codehaus.plexus.util.xml.Xpp3Dom
    Creates a Xpp3Dom which corresponds to the configuration of the invocation.
    (package private) String
    Either return the submitted errorMessage or replace it with the custom message set in the rule extended by the property name.
    private List<org.codehaus.plexus.util.xml.Xpp3Dom>
    createRuleListWithNameSortedChildren(List<org.codehaus.plexus.util.xml.Xpp3Dom> originalListFromPom)
    As Xpp3Dom is very picky about the order of children while comparing, create a new list where the children are added in alphabetical order.
    void
    execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper)
    Execute the rule.
    (package private) final org.apache.maven.project.MavenProject
    findDefiningParent(org.apache.maven.project.MavenProject project)
    Finds the ancestor project which defines the rule.
    (package private) org.apache.maven.project.MavenProject
    getMavenProject(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper)
    Extracted for easier testability.
    (package private) Object
    getPropertyValue(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper)
    Extracted for easier testability.
    (package private) Object
    getPropertyValue(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper, String propertyName)
    Extracted for easier testability.
    (package private) List<org.codehaus.plexus.util.xml.Xpp3Dom>
    getRuleConfigurations(Map<String,org.apache.maven.model.Plugin> plugins)
    Returns the list of requirePropertyDiverges configurations from the map of plugins.
    (package private) final List<org.codehaus.plexus.util.xml.Xpp3Dom>
    getRuleConfigurations(org.apache.maven.model.Build build)
    Returns the rule configurations from the pluginManagement as well as the plugins section.
    (package private) final String
    Returns the configuration name of the rule.
    boolean
    (package private) final boolean
    isDefiningProject(List<org.codehaus.plexus.util.xml.Xpp3Dom> rulesFromModel, org.codehaus.plexus.util.xml.Xpp3Dom invokingRule)
    Checks whether ruleDom is in the list of rules from the model.
    boolean
    isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule cachedRule)
    (package private) void
    setMessage(String message)
     
    (package private) void
    setProperty(String property)
     
    (package private) void
     

    Methods inherited from class org.apache.maven.plugins.enforcer.AbstractMojoHausEnforcerRule

    getLevel, setLevel

    Methods inherited from class java.lang.Object

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

    • message

      private String message
    • MAVEN_ENFORCER_PLUGIN

      static final String MAVEN_ENFORCER_PLUGIN
      See Also:
    • property

      private String property
      Specify the required property. Must be given.
    • regex

      private String regex
      Match the property value to a given regular expression. Defaults to value of defining project.
    • ruleName

      private final String ruleName
  • Constructor Details

    • RequirePropertyDiverges

      public RequirePropertyDiverges()
  • Method Details

    • execute

      public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Execute the rule.
      Parameters:
      helper - the helper
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException - the enforcer rule exception
    • checkAgainstParentValue

      void checkAgainstParentValue(org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parent, org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper, Object propValue) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Checks the value of the project against the one given in the defining ancestor project.
      Parameters:
      project -
      parent -
      helper -
      propValue -
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • checkAgainstRegex

      void checkAgainstRegex(Object propValue) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Checks the value of the project against the given regex.
      Parameters:
      propValue -
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • findDefiningParent

      final org.apache.maven.project.MavenProject findDefiningParent(org.apache.maven.project.MavenProject project)
      Finds the ancestor project which defines the rule.
      Parameters:
      project - to inspect
      Returns:
      the defining ancestor project.
    • createInvokingRuleDom

      org.codehaus.plexus.util.xml.Xpp3Dom createInvokingRuleDom()
      Creates a Xpp3Dom which corresponds to the configuration of the invocation.
      Returns:
      dom of the invoker.
    • isDefiningProject

      final boolean isDefiningProject(List<org.codehaus.plexus.util.xml.Xpp3Dom> rulesFromModel, org.codehaus.plexus.util.xml.Xpp3Dom invokingRule)
      Checks whether ruleDom is in the list of rules from the model.
      Parameters:
      rulesFromModel -
      invokingRule -
      Returns:
      true when the rules contain the invoking rule.
    • getRuleName

      final String getRuleName()
      Returns the configuration name of the rule.
      Returns:
      configuration name.
    • getRuleConfigurations

      final List<org.codehaus.plexus.util.xml.Xpp3Dom> getRuleConfigurations(org.apache.maven.model.Build build)
      Returns the rule configurations from the pluginManagement as well as the plugins section.
      Parameters:
      build - the build to inspect.
      Returns:
      configuration of the rules, may be an empty list.
    • getRuleConfigurations

      List<org.codehaus.plexus.util.xml.Xpp3Dom> getRuleConfigurations(Map<String,org.apache.maven.model.Plugin> plugins)
      Returns the list of requirePropertyDiverges configurations from the map of plugins.
      Parameters:
      plugins -
      Returns:
      list of requirePropertyDiverges configurations.
    • addRules

      private void addRules(org.codehaus.plexus.util.xml.Xpp3Dom configuration, List<org.codehaus.plexus.util.xml.Xpp3Dom> ruleConfigurations)
      Add the rules found in the given configuration to the list of rule configurations.
      Parameters:
      configuration - configuration from which the rules are copied. May be null.
      ruleConfigurations - List to which the rules will be added.
    • createRuleListWithNameSortedChildren

      private List<org.codehaus.plexus.util.xml.Xpp3Dom> createRuleListWithNameSortedChildren(List<org.codehaus.plexus.util.xml.Xpp3Dom> originalListFromPom)
      As Xpp3Dom is very picky about the order of children while comparing, create a new list where the children are added in alphabetical order. See MOJO-1931.
      Parameters:
      originalListFromPom - order not specified
      Returns:
      a list where children's member are alphabetically sorted.
    • getPropertyValue

      Object getPropertyValue(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Extracted for easier testability.
      Parameters:
      helper -
      Returns:
      the value of the property.
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • getPropertyValue

      Object getPropertyValue(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper, String propertyName) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Extracted for easier testability.
      Parameters:
      helper -
      propertyName - name of the property to extract.
      Returns:
      the value of the property.
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • getMavenProject

      org.apache.maven.project.MavenProject getMavenProject(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Extracted for easier testability.
      Parameters:
      helper -
      Returns:
      the MavenProject enforcer is running on.
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • checkPropValueNotBlank

      void checkPropValueNotBlank(Object propValue) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Checks that the property is not null or empty string
      Parameters:
      propValue - value of the property from the project.
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • createResultingErrorMessage

      String createResultingErrorMessage(String errorMessage)
      Either return the submitted errorMessage or replace it with the custom message set in the rule extended by the property name.
      Parameters:
      errorMessage -
      Returns:
    • setProperty

      void setProperty(String property)
      Parameters:
      property - the property to set
    • setRegex

      void setRegex(String regex)
      Parameters:
      regex - the regex to set
    • setMessage

      void setMessage(String message)
      Parameters:
      message - the message to set
    • getCacheId

      public String getCacheId()
    • isCacheable

      public boolean isCacheable()
    • isResultValid

      public boolean isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule cachedRule)