Class BannedDependenciesBase
- java.lang.Object
-
- org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
-
- org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
-
- org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule
-
- org.apache.maven.enforcer.rules.dependency.BannedDependenciesBase
-
- All Implemented Interfaces:
EnforcerRuleBase
- Direct Known Subclasses:
BannedDependencies
,RequireReleaseDeps
abstract class BannedDependenciesBase extends AbstractStandardEnforcerRule
Abstract base class for rules which validate the transitive dependency tree by traversing all children and validating every dependency artifact.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
excludes
Specify the banned dependencies.private java.util.List<java.lang.String>
includes
Specify the allowed dependencies.private ResolverUtil
resolverUtil
private boolean
searchTransitive
Specify if transitive dependencies should be searched (default) or only look at direct dependencies.private org.apache.maven.execution.MavenSession
session
-
Constructor Summary
Constructors Constructor Description BannedDependenciesBase(org.apache.maven.execution.MavenSession session, ResolverUtil resolverUtil)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
execute()
This is the interface into the rule.protected abstract java.lang.String
getErrorMessage()
java.util.List<java.lang.String>
getExcludes()
Gets the excludes.java.util.List<java.lang.String>
getIncludes()
Gets the includes.protected org.apache.maven.execution.MavenSession
getSession()
boolean
isSearchTransitive()
void
setExcludes(java.util.List<java.lang.String> excludes)
Specify the banned dependencies.void
setIncludes(java.util.List<java.lang.String> includes)
Specify the allowed dependencies.void
setSearchTransitive(boolean searchTransitive)
Sets the search transitive.protected abstract boolean
validate(org.apache.maven.artifact.Artifact dependency)
Validates a dependency artifact if it fulfills the enforcer ruleprotected boolean
validate(org.eclipse.aether.graph.DependencyNode node, int level, java.lang.StringBuilder messageBuilder, java.util.Set<ArtifactMatcher.MatchingArtifact> visitedArtifacts)
-
Methods inherited from class org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule
formatLocation, getMessage, setMessage
-
Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
getCacheId, getLevel, getRuleName
-
Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
getLog, setLog
-
-
-
-
Field Detail
-
excludes
private java.util.List<java.lang.String> excludes
Specify the banned dependencies. This can be a list of artifacts in the formatgroupId[:artifactId][:version]
. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
The rule will fail if any dependency matches any exclude, unless it also matches an include rule.- See Also:
setExcludes(List)
,getExcludes()
-
includes
private java.util.List<java.lang.String> includes
Specify the allowed dependencies. This can be a list of artifacts in the formatgroupId[:artifactId][:version]
. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
Includes override the exclude rules. It is meant to allow wide exclusion rules with wildcards and still allow a smaller set of includes.
For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api"- See Also:
setIncludes(List)
,getIncludes()
-
searchTransitive
private boolean searchTransitive
Specify if transitive dependencies should be searched (default) or only look at direct dependencies.
-
session
private final org.apache.maven.execution.MavenSession session
-
resolverUtil
private final ResolverUtil resolverUtil
-
-
Constructor Detail
-
BannedDependenciesBase
BannedDependenciesBase(org.apache.maven.execution.MavenSession session, ResolverUtil resolverUtil)
-
-
Method Detail
-
getSession
protected org.apache.maven.execution.MavenSession getSession()
-
execute
public void execute() throws EnforcerRuleException
Description copied from class:AbstractEnforcerRule
This is the interface into the rule. This method should throw an exception containing a reason message if the rule fails the check. The plugin will then decide based on the fail flag and rule level if it should stop or just log the message as a warning.- Specified by:
execute
in classAbstractEnforcerRule
- Throws:
EnforcerRuleException
- the enforcer rule exceptionEnforcerRuleError
- in order to brake a build immediately
-
validate
protected boolean validate(org.eclipse.aether.graph.DependencyNode node, int level, java.lang.StringBuilder messageBuilder, java.util.Set<ArtifactMatcher.MatchingArtifact> visitedArtifacts)
-
getErrorMessage
protected abstract java.lang.String getErrorMessage()
-
validate
protected abstract boolean validate(org.apache.maven.artifact.Artifact dependency)
Validates a dependency artifact if it fulfills the enforcer rule- Parameters:
dependency
- dependency to be checked against the list of excludes- Returns:
true
if the dependency passes the rule,false
if the dependency triggers a validation error
-
setSearchTransitive
public void setSearchTransitive(boolean searchTransitive)
Sets the search transitive.- Parameters:
searchTransitive
- the searchTransitive to set
-
getExcludes
public java.util.List<java.lang.String> getExcludes()
Gets the excludes.- Returns:
- the excludes
-
setExcludes
public void setExcludes(java.util.List<java.lang.String> excludes)
Specify the banned dependencies. This can be a list of artifacts in the formatgroupId[:artifactId][:version]
. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
The rule will fail if any dependency matches any exclude, unless it also matches an include rule.- Parameters:
excludes
- the excludes to set- See Also:
getExcludes()
-
getIncludes
public java.util.List<java.lang.String> getIncludes()
Gets the includes.- Returns:
- the includes
-
setIncludes
public void setIncludes(java.util.List<java.lang.String> includes)
Specify the allowed dependencies. This can be a list of artifacts in the formatgroupId[:artifactId][:version]
. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
Includes override the exclude rules. It is meant to allow wide exclusion rules with wildcards and still allow a smaller set of includes.
For example, to ban all xerces except xerces-api → exclude "xerces", include "xerces:xerces-api"- Parameters:
includes
- the includes to set- See Also:
setIncludes(List)
-
isSearchTransitive
public boolean isSearchTransitive()
-
-