Class RequirePropertyDiverges

java.lang.Object
org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
org.codehaus.mojo.extraenforcer.model.RequirePropertyDiverges
All Implemented Interfaces:
org.apache.maven.enforcer.rule.api.EnforcerRuleBase

@Named("requirePropertyDiverges") public class RequirePropertyDiverges extends org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
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
    private final org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
     
    (package private) static final String
     
    private String
     
    private final org.apache.maven.project.MavenProject
     
    private String
    Specify the required property.
    private String
    Match the property value to a given regular expression.
    private static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RequirePropertyDiverges(org.apache.maven.project.MavenProject project, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator evaluator)
     
  • 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, 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 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.
    org.apache.maven.enforcer.rule.api.EnforcerLogger
     
    (package private) Object
    Extracted for easier testability.
    (package private) Object
    getPropertyValue(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) static final String
    Returns the configuration name of the rule.
    (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.
    void
    setLog(org.apache.maven.enforcer.rule.api.EnforcerLogger arg0)
     
    (package private) void
    setMessage(String message)
     
    (package private) void
    setProperty(String property)
     
    (package private) void
     

    Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRule

    getCacheId, getLevel

    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.
    • RULE_NAME

      private static final String RULE_NAME
    • project

      private final org.apache.maven.project.MavenProject project
    • evaluator

      private final org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator evaluator
  • Constructor Details

    • RequirePropertyDiverges

      @Inject public RequirePropertyDiverges(org.apache.maven.project.MavenProject project, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator evaluator)
  • Method Details

    • execute

      public void execute() throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Execute the rule.
      Specified by:
      execute in class org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
      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, 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 -
      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

      static 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() throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Extracted for easier testability.
      Returns:
      the value of the property.
      Throws:
      org.apache.maven.enforcer.rule.api.EnforcerRuleException
    • getPropertyValue

      Object getPropertyValue(String propertyName) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
      Extracted for easier testability.
      Parameters:
      propertyName - name of the property to extract.
      Returns:
      the value of the property.
      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
    • setLog

      public void setLog(org.apache.maven.enforcer.rule.api.EnforcerLogger arg0)
      Specified by:
      setLog in interface org.apache.maven.enforcer.rule.api.EnforcerRuleBase
    • getLog

      public org.apache.maven.enforcer.rule.api.EnforcerLogger getLog()