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 ClassesModifier and TypeClassDescriptionprivate static class
Creates the DOM of the invoking rule, but returns the children alphabetically sorted. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsConstructorDescriptionRequirePropertyDiverges
(org.apache.maven.project.MavenProject project, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator evaluator) -
Method Summary
Modifier and TypeMethodDescriptionprivate 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
checkAgainstRegex
(Object propValue) Checks the value of the project against the given regex.(package private) void
checkPropValueNotBlank
(Object propValue) Checks that the property is not null or empty string(package private) org.codehaus.plexus.util.xml.Xpp3Dom
Creates aXpp3Dom
which corresponds to the configuration of the invocation.(package private) 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.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()
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
getLog()
(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
-
Field Details
-
message
-
MAVEN_ENFORCER_PLUGIN
- See Also:
-
property
Specify the required property. Must be given. -
regex
Match the property value to a given regular expression. Defaults to value of defining project. -
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.EnforcerRuleExceptionExecute the rule.- Specified by:
execute
in classorg.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 aXpp3Dom
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
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 benull
.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
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
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
- Parameters:
property
- the property to set
-
setRegex
- Parameters:
regex
- the regex to set
-
setMessage
- Parameters:
message
- the message to set
-
setLog
public void setLog(org.apache.maven.enforcer.rule.api.EnforcerLogger arg0) - Specified by:
setLog
in interfaceorg.apache.maven.enforcer.rule.api.EnforcerRuleBase
-
getLog
public org.apache.maven.enforcer.rule.api.EnforcerLogger getLog()
-