Package org.apache.maven.enforcer.rules
Class ExternalRules
java.lang.Object
org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleConfigProvider
org.apache.maven.enforcer.rules.ExternalRules
- All Implemented Interfaces:
EnforcerRuleBase
An enforcer rule that will provide rules configuration from an external resource.
- Since:
- 3.2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ExpressionEvaluator
private String
The external rules location.private static final String
private final org.apache.maven.plugin.MojoExecution
private String
An optional location of an XSLT file used to transform the rule document available vialocation
before it is applied. -
Constructor Summary
ConstructorsConstructorDescriptionExternalRules
(org.apache.maven.plugin.MojoExecution mojoExecution, ExpressionEvaluator evaluator) -
Method Summary
Modifier and TypeMethodDescriptionorg.codehaus.plexus.util.xml.Xpp3Dom
Produce rule configuration.private InputStream
resolveDescriptor
(String path) void
setLocation
(String location) void
setXsltLocation
(String xsltLocation) toString()
(package private) InputStream
transform
(String sourceLocation, InputStream sourceXml, String xsltLocation) Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
getLog, setLog
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.maven.enforcer.rule.api.EnforcerRuleBase
getLevel, getRuleName
-
Field Details
-
LOCATION_PREFIX_CLASSPATH
- See Also:
-
location
The external rules location. If it starts withclasspath:
the resource is read from the classpath. Otherwise, it is handled as a filesystem path, either absolute, or relative to${project.basedir}
- Since:
- 3.2.0
-
xsltLocation
An optional location of an XSLT file used to transform the rule document available vialocation
before it is applied. If it starts withclasspath:
the resource is read from the classpath. Otherwise, it is handled as a filesystem path, either absolute, or relative to${project.basedir}
This is useful, when you want to consume rules defined in an external project, but you need to remove or adapt some of those for the local circumstances.
Example
If
location
points at the following rule set:
And if<enforcer> <rules> <bannedDependencies> <excludes> <exclude>com.google.code.findbugs:jsr305</exclude> <exclude>com.google.guava:listenablefuture</exclude> </excludes> </bannedDependencies> </rules> </enforcer>
xsltLocation
points at the following transformation
Then the effective rule set will look like to following:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <!-- Copy everything unless there is a template with a more specific matcher --> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <!-- An empty template will effectively remove the matching nodes --> <xsl:template match= "//bannedDependencies/excludes/exclude[contains(text(), 'com.google.code.findbugs:jsr305')]"/> </xsl:stylesheet>
<enforcer> <rules> <bannedDependencies> <excludes> <exclude>com.google.guava:listenablefuture</exclude> </excludes> </bannedDependencies> </rules> </enforcer>
- Since:
- 3.6.0
-
mojoExecution
private final org.apache.maven.plugin.MojoExecution mojoExecution -
evaluator
-
-
Constructor Details
-
ExternalRules
@Inject public ExternalRules(org.apache.maven.plugin.MojoExecution mojoExecution, ExpressionEvaluator evaluator)
-
-
Method Details
-
setLocation
-
setXsltLocation
-
getRulesConfig
Description copied from class:AbstractEnforcerRuleConfigProvider
Produce rule configuration.Returned configuration must contain rules configuration as in example:
<rules> <ruleName/> <ruleName> <ruleConfig>config value</ruleConfig> </ruleName> </rules>
- Specified by:
getRulesConfig
in classAbstractEnforcerRuleConfigProvider
- Returns:
- a rules configuration
- Throws:
EnforcerRuleError
- the error during executing
-
resolveDescriptor
- Throws:
EnforcerRuleError
-
toString
-
transform
-