Class ArtifactUtils
- java.lang.Object
-
- org.apache.maven.enforcer.rules.utils.ArtifactUtils
-
public final class ArtifactUtils extends java.lang.Object- Since:
- 3.0.0
-
-
Constructor Summary
Constructors Constructor Description ArtifactUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.util.stream.Stream<java.lang.String>cleansePatterns(java.util.Collection<java.lang.String> patterns)Cleans the patterns provided ready for use inArtifactMatcher.Patternstatic booleancompareDependency(java.lang.String pattern, org.apache.maven.artifact.Artifact artifact)Compares the given pattern against the given artifact.static java.util.Set<org.apache.maven.artifact.Artifact>filterDependencyArtifacts(java.util.Set<org.apache.maven.artifact.Artifact> dependencies, java.util.Collection<java.lang.String> patterns)Returns a subset of dependency artifacts that match the given collection of patternsstatic java.util.function.Predicate<org.apache.maven.artifact.Artifact>prepareDependencyArtifactMatcher(java.util.Collection<java.lang.String> patterns)Prepares patterns directly into a reusable predicate.static org.apache.maven.artifact.ArtifacttoArtifact(org.eclipse.aether.graph.DependencyNode node)ConvertsDependencyNodetoArtifact; in comparison toRepositoryUtils.toArtifact(org.eclipse.aether.artifact.Artifact), this method assignsArtifact.getScope()andArtifact.isOptional()based on the dependency information from the node.
-
-
-
Method Detail
-
toArtifact
public static org.apache.maven.artifact.Artifact toArtifact(org.eclipse.aether.graph.DependencyNode node)
ConvertsDependencyNodetoArtifact; in comparison toRepositoryUtils.toArtifact(org.eclipse.aether.artifact.Artifact), this method assignsArtifact.getScope()andArtifact.isOptional()based on the dependency information from the node.- Parameters:
node-DependencyNodeto convert toArtifact- Returns:
- target artifact
-
filterDependencyArtifacts
public static java.util.Set<org.apache.maven.artifact.Artifact> filterDependencyArtifacts(java.util.Set<org.apache.maven.artifact.Artifact> dependencies, java.util.Collection<java.lang.String> patterns) throws EnforcerRuleExceptionReturns a subset of dependency artifacts that match the given collection of patterns- Parameters:
dependencies- dependency artifacts to match against patternspatterns- patterns to match against the artifacts- Returns:
- a set containing artifacts matching one of the patterns or
null - Throws:
EnforcerRuleException- the enforcer rule exception
-
prepareDependencyArtifactMatcher
public static java.util.function.Predicate<org.apache.maven.artifact.Artifact> prepareDependencyArtifactMatcher(java.util.Collection<java.lang.String> patterns)
Prepares patterns directly into a reusable predicate. This can improve efficiency where there are lots of patterns and/or artifacts to match.- Parameters:
patterns- the patterns to use for the predicate- Returns:
- a re-usable predicate.
-
cleansePatterns
private static java.util.stream.Stream<java.lang.String> cleansePatterns(java.util.Collection<java.lang.String> patterns)
Cleans the patterns provided ready for use inArtifactMatcher.Pattern- Parameters:
patterns- the patterns to be cleaned- Returns:
- a Stream of the patterns prepared for use.
-
compareDependency
public static boolean compareDependency(java.lang.String pattern, org.apache.maven.artifact.Artifact artifact)Compares the given pattern against the given artifact. The pattern should follow the formatgroupId:artifactId:version:type:scope:classifier.- Parameters:
pattern- The pattern to compare the artifact with.artifact- the artifact- Returns:
trueif the artifact matches one of the patterns
-
-