Class Resolve.ArtifactConsumer

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.maven.resolver.internal.ant.tasks.Resolve.ArtifactConsumer
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Resolve.Files, Resolve.Path, Resolve.Props
Enclosing class:
Resolve

public abstract static class Resolve.ArtifactConsumer extends org.apache.tools.ant.ProjectComponent
Abstract base class for consumers of resolved artifacts in the Resolve task.

Subclasses of this class define how resolved artifacts are handled, such as copying them to a directory, adding them to a path, or storing their locations in properties. Each consumer may filter artifacts by Maven scope or classpath profile.

ArtifactConsumers are registered by the enclosing Resolve task and invoked after artifacts are resolved from the dependency graph.

Common subclasses include:

  • Resolve.Path – Adds artifacts to an Ant <path> reference
  • Resolve.Files – Copies artifacts to a directory and exposes a fileset or resource collection
  • Resolve.Props – Stores artifact file paths as Ant properties
See Also:
  • Field Summary

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for Ant task instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    accept(org.eclipse.aether.graph.DependencyNode node, List<org.eclipse.aether.graph.DependencyNode> parents)
    Determines whether the given dependency node should be accepted by this consumer based on its configured dependency filter (e.g., scope or classpath).
    Returns the classifier this consumer is interested in, if any.
    abstract void
    process(org.eclipse.aether.artifact.Artifact artifact, org.eclipse.aether.RepositorySystemSession session)
    Processes a resolved artifact after dependency resolution has completed.
    void
    setClasspath(String classpath)
    Sets a predefined classpath scope configuration using a shorthand string.
    void
    setScopes(String scopes)
    Specifies the scopes of dependencies to include or exclude during resolution.
    void
    Validates the configuration of this Resolve.ArtifactConsumer.

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArtifactConsumer

      public ArtifactConsumer()
      Default constructor for Ant task instantiation.

      This constructor is used by Ant to create instances of Resolve.ArtifactConsumer subclasses.

  • Method Details

    • accept

      public boolean accept(org.eclipse.aether.graph.DependencyNode node, List<org.eclipse.aether.graph.DependencyNode> parents)
      Determines whether the given dependency node should be accepted by this consumer based on its configured dependency filter (e.g., scope or classpath).
      Parameters:
      node - the dependency node to evaluate
      parents - the list of parent nodes leading to this node in the dependency graph
      Returns:
      true if the node passes the filter (or no filter is set); false otherwise
    • getClassifier

      public String getClassifier()
      Returns the classifier this consumer is interested in, if any.

      This is typically used to distinguish between main artifacts and attachments like sources or javadoc jars.

      Returns:
      the classifier string (e.g., "*-sources"), or null if none
    • validate

      public void validate()
      Validates the configuration of this Resolve.ArtifactConsumer.

      This default implementation does nothing. Subclasses may override this method to enforce that required attributes (e.g., refid) or configurations are present before artifact resolution begins.

      Throws:
      org.apache.tools.ant.BuildException - if the consumer configuration is invalid
    • process

      public abstract void process(org.eclipse.aether.artifact.Artifact artifact, org.eclipse.aether.RepositorySystemSession session)
      Processes a resolved artifact after dependency resolution has completed.

      This method is invoked for each artifact that has been accepted by the consumer's filter. Implementations may use this hook to copy files, register references, build paths, or store metadata.

      Parameters:
      artifact - the resolved Artifact, including a file location
      session - the RepositorySystemSession used during resolution, useful for repository information
    • setScopes

      public void setScopes(String scopes)
      Specifies the scopes of dependencies to include or exclude during resolution.

      The input string can contain a comma- or space-separated list of scopes. Scopes prefixed with - or ! will be excluded. For example, compile, -test will include only compile-scope dependencies, excluding those with scope test.

      Parameters:
      scopes - a string defining scopes to include/exclude, e.g., "compile, -test"
      Throws:
      org.apache.tools.ant.BuildException - if a scope filter was already set (e.g., via setClasspath(String))
    • setClasspath

      public void setClasspath(String classpath)
      Sets a predefined classpath scope configuration using a shorthand string.

      Accepted values are:

      • compile — includes provided, system, and compile scopes
      • runtime — includes compile and runtime scopes
      • test — includes provided, system, compile, runtime, and test scopes

      Internally, this method delegates to setScopes(String) with an appropriate scope string.

      Parameters:
      classpath - the classpath type to use (compile, runtime, or test)
      Throws:
      org.apache.tools.ant.BuildException - if the given classpath is not one of the allowed values