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
RequirePropertyDiverges.CreateInvokingRuleDom
Creates the DOM of the invoking rule, but returns the children alphabetically sorted.
-
Field Summary
Fields Modifier and Type Field Description private org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
evaluator
(package private) static java.lang.String
MAVEN_ENFORCER_PLUGIN
private java.lang.String
message
private org.apache.maven.project.MavenProject
project
private java.lang.String
property
Specify the required property.private java.lang.String
regex
Match the property value to a given regular expression.private static java.lang.String
RULE_NAME
-
Constructor Summary
Constructors Constructor Description RequirePropertyDiverges(org.apache.maven.project.MavenProject project, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator evaluator)
-
Method Summary
All Methods Static 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, 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 aXpp3Dom
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()
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.org.apache.maven.enforcer.rule.api.EnforcerLogger
getLog()
(package private) java.lang.Object
getPropertyValue()
Extracted for easier testability.(package private) java.lang.Object
getPropertyValue(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) static java.lang.String
getRuleName()
Returns the configuration name of the rule.(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.void
setLog(org.apache.maven.enforcer.rule.api.EnforcerLogger arg0)
(package private) void
setMessage(java.lang.String message)
(package private) void
setProperty(java.lang.String property)
(package private) void
setRegex(java.lang.String regex)
-
-
-
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.
-
RULE_NAME
private static final java.lang.String RULE_NAME
-
project
private final org.apache.maven.project.MavenProject project
-
evaluator
private final org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator evaluator
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.enforcer.rule.api.EnforcerRuleException
Execute 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, 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
-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 aXpp3Dom
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
static 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 benull
.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() 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
java.lang.Object getPropertyValue(java.lang.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(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
-
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()
-
-