Class 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  RequirePropertyDiverges.CreateInvokingRuleDom
      Creates the DOM of the invoking rule, but returns the children alphabetically sorted.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.lang.String MAVEN_ENFORCER_PLUGIN  
      private java.lang.String message  
      private java.lang.String property
      Specify the required property.
      private java.lang.String regex
      Match the property value to a given regular expression.
      private java.lang.String ruleName  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addRules​(org.codehaus.plexus.util.xml.Xpp3Dom configuration, java.util.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, java.lang.Object propValue)
      Checks the value of the project against the one given in the defining ancestor project.
      (package private) void checkAgainstRegex​(java.lang.Object propValue)
      Checks the value of the project against the given regex.
      (package private) void checkPropValueNotBlank​(java.lang.Object propValue)
      Checks that the property is not null or empty string
      (package private) org.codehaus.plexus.util.xml.Xpp3Dom createInvokingRuleDom()
      Creates a Xpp3Dom which corresponds to the configuration of the invocation.
      (package private) java.lang.String createResultingErrorMessage​(java.lang.String errorMessage)
      Either return the submitted errorMessage or replace it with the custom message set in the rule extended by the property name.
      private java.util.List<org.codehaus.plexus.util.xml.Xpp3Dom> createRuleListWithNameSortedChildren​(java.util.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) org.apache.maven.project.MavenProject findDefiningParent​(org.apache.maven.project.MavenProject project)
      Finds the ancestor project which defines the rule.
      java.lang.String getCacheId()
      (package private) org.apache.maven.project.MavenProject getMavenProject​(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper)
      Extracted for easier testability.
      (package private) java.lang.Object getPropertyValue​(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper)
      Extracted for easier testability.
      (package private) java.lang.Object getPropertyValue​(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper, java.lang.String propertyName)
      Extracted for easier testability.
      (package private) java.util.List<org.codehaus.plexus.util.xml.Xpp3Dom> getRuleConfigurations​(java.util.Map<java.lang.String,​org.apache.maven.model.Plugin> plugins)
      Returns the list of requirePropertyDiverges configurations from the map of plugins.
      (package private) java.util.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) java.lang.String getRuleName()
      Returns the configuration name of the rule.
      boolean isCacheable()
      (package private) boolean isDefiningProject​(java.util.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​(java.lang.String message)  
      (package private) void setProperty​(java.lang.String property)  
      (package private) void setRegex​(java.lang.String regex)  
      • Methods inherited from class java.lang.Object

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

      • message

        private java.lang.String message
      • MAVEN_ENFORCER_PLUGIN

        static final java.lang.String MAVEN_ENFORCER_PLUGIN
        See Also:
        Constant Field Values
      • property

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

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

        private final java.lang.String ruleName
    • Constructor Detail

      • RequirePropertyDiverges

        public RequirePropertyDiverges()
    • Method Detail

      • 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,
                                     java.lang.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​(java.lang.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​(java.util.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 java.lang.String getRuleName()
        Returns the configuration name of the rule.
        Returns:
        configuration name.
      • getRuleConfigurations

        final java.util.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

        java.util.List<org.codehaus.plexus.util.xml.Xpp3Dom> getRuleConfigurations​(java.util.Map<java.lang.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,
                              java.util.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 java.util.List<org.codehaus.plexus.util.xml.Xpp3Dom> createRuleListWithNameSortedChildren​(java.util.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

        java.lang.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

        java.lang.Object getPropertyValue​(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper,
                                          java.lang.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​(java.lang.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

        java.lang.String createResultingErrorMessage​(java.lang.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​(java.lang.String property)
        Parameters:
        property - the property to set
      • setRegex

        void setRegex​(java.lang.String regex)
        Parameters:
        regex - the regex to set
      • setMessage

        void setMessage​(java.lang.String message)
        Parameters:
        message - the message to set
      • getCacheId

        public java.lang.String getCacheId()
      • isCacheable

        public boolean isCacheable()
      • isResultValid

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