java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.types.DataType
org.apache.maven.resolver.internal.ant.types.Mirror
All Implemented Interfaces:
Cloneable

public class Mirror extends org.apache.tools.ant.types.DataType
Defines a mirror repository configuration for use in Maven Ant tasks.

A mirror allows you to redirect requests for one or more remote repositories to a different repository URL. This is useful for using internal repositories, caching proxies (e.g., Nexus, Artifactory), or selectively replacing external repositories.

This type can be used inline or as a referenced <mirror> data type elsewhere in the build. When included in an Ant project, the mirror will be registered with the AntRepoSys instance associated with the current project.

Attributes:

  • id — unique identifier for the mirror (optional)
  • url — base URL of the mirror (required)
  • mirrorOf — pattern matching the repositories to be mirrored (required)
  • type — optional repository layout type (defaults to "default")

Nested Elements:

  • <authentication> — optional credentials for accessing the mirror

Usage Example:


 <mirror id="company-mirror" url="https://repo.mycompany.com/maven2" mirrorOf="*" />
 

Notes:

  • Only one <authentication> element is allowed per mirror
  • If this element is a reference (refid), attributes and nested elements are disallowed
  • This mirror will automatically be added to the AntRepoSys upon being assigned a project
See Also:
  • Field Summary

    Fields inherited from class org.apache.tools.ant.types.DataType

    checked, ref

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

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor used by Ant to create a Mirror instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds an <authentication> element to the mirror.
    Returns the authentication configuration for this mirror, if any.
    Returns the identifier of this mirror.
    Returns the repository pattern that this mirror applies to.
    protected Mirror
    Resolves this object if defined as a reference and verifies that it is a Mirror instance.
    Returns the layout type of the mirror repository.
    Returns the URL of the mirror repository.
    void
    setAuthRef(org.apache.tools.ant.types.Reference ref)
    Sets a reference to a previously defined <authentication> element.
    void
    Sets the identifier of the mirror.
    void
    setMirrorOf(String mirrorOf)
    Specifies the repository IDs that this mirror should apply to.
    void
    setProject(org.apache.tools.ant.Project project)
    Sets the Ant project associated with this mirror.
    void
    setRefid(org.apache.tools.ant.types.Reference ref)
     
    void
    Sets the layout type of the mirror repository.
    void
    Sets the base URL of the mirror repository.

    Methods inherited from class org.apache.tools.ant.types.DataType

    checkAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes, toString

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

    getDescription, getLocation, getProject, log, log, setDescription, setLocation

    Methods inherited from class java.lang.Object

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

    • Mirror

      public Mirror()
      Default constructor used by Ant to create a Mirror instance.

      This constructor is required for Ant to instantiate this type when defined inline or referenced in an Ant build script.

  • Method Details

    • setProject

      public void setProject(org.apache.tools.ant.Project project)
      Sets the Ant project associated with this mirror.

      In addition to associating the mirror with the current build context, this method registers the mirror with the AntRepoSys instance for the project. This allows the mirror to influence repository resolution globally.

      Overrides:
      setProject in class org.apache.tools.ant.ProjectComponent
      Parameters:
      project - the Ant project
      See Also:
    • getRef

      protected Mirror getRef()
      Resolves this object if defined as a reference and verifies that it is a Mirror instance.
      Returns:
      the referenced Mirror instance
      Throws:
      org.apache.tools.ant.BuildException - if the reference is invalid
      See Also:
    • setRefid

      public void setRefid(org.apache.tools.ant.types.Reference ref)
      Overrides:
      setRefid in class org.apache.tools.ant.types.DataType
    • getId

      public String getId()
      Returns the identifier of this mirror.

      The ID is typically used for identification and logging purposes. It does not affect repository resolution but may appear in debug output or reports to help distinguish mirrors.

      If this mirror is defined as a reference (refid), the ID is retrieved from the referenced Mirror instance.

      Returns:
      the mirror ID, or null if not set
      See Also:
    • setId

      public void setId(String id)
      Sets the identifier of the mirror.

      The ID is optional and is primarily used for identification and logging purposes. It does not affect resolution behavior but can help distinguish multiple mirrors.

      This method must not be used if the mirror is defined via refid.

      Parameters:
      id - the identifier for this mirror
      See Also:
    • getUrl

      public String getUrl()
      Returns the URL of the mirror repository.

      This is the base URL where artifacts will be downloaded from when a matched repository is redirected to this mirror. For example: https://repo.example.org/mirror.

      If this Mirror is defined as a reference (refid), the URL is resolved from the referenced Mirror instance.

      Returns:
      the mirror repository URL, or null if not set
      See Also:
    • setUrl

      public void setUrl(String url)
      Sets the base URL of the mirror repository.

      This URL must be a valid repository root (e.g., https://repo.example.com/maven2). It is used to redirect requests from repositories matched by setMirrorOf(String).

      This method must not be used if the mirror is defined via refid.

      Parameters:
      url - the URL of the mirror repository
      Throws:
      org.apache.tools.ant.BuildException - if this instance is a reference
      See Also:
    • getType

      public String getType()
      Returns the layout type of the mirror repository.

      If no type is explicitly set, this method returns "default", which is the standard Maven 2 layout.

      If this mirror is defined as a reference, the type is resolved from the referenced instance.

      Returns:
      the repository layout type, or "default" if not specified
      See Also:
    • setType

      public void setType(String type)
      Sets the layout type of the mirror repository.

      The default value is "default", which corresponds to the standard Maven 2 layout. Other values are rarely used and typically not necessary unless working with custom or legacy repository formats.

      This method must not be called if this mirror is defined via refid.

      Parameters:
      type - the layout type of the mirror repository
      Throws:
      org.apache.tools.ant.BuildException - if this instance is a reference
      See Also:
    • getMirrorOf

      public String getMirrorOf()
      Returns the repository pattern that this mirror applies to.

      The value is typically a pattern or comma-separated list of repository IDs, such as *, external:*, or central,!snapshots. It determines which repositories should be redirected to this mirror.

      If this Mirror is defined as a reference (refid), the value is retrieved from the referenced instance.

      Returns:
      the mirrorOf pattern, or null if not set
      See Also:
    • setMirrorOf

      public void setMirrorOf(String mirrorOf)
      Specifies the repository IDs that this mirror should apply to.

      The value can be a single repository ID, a comma-separated list, or a pattern (e.g., *, external:*, central,!snapshots).

      This value is required unless set via a reference. If this Mirror is defined as a reference, this method must not be called.

      Parameters:
      mirrorOf - a pattern or list of repository IDs to be mirrored
      Throws:
      org.apache.tools.ant.BuildException - if this instance is a reference
      See Also:
    • addAuthentication

      public void addAuthentication(Authentication authentication)
      Adds an <authentication> element to the mirror.

      This is used to configure credentials for accessing the mirrored repository. Only one <authentication> child is allowed. Attempting to add multiple will result in a BuildException.

      This method must not be used if the mirror is defined via refid.

      Parameters:
      authentication - the Authentication object to associate with this mirror
      Throws:
      org.apache.tools.ant.BuildException - if an authentication has already been set, or if this instance is a reference
      See Also:
    • getAuthentication

      public Authentication getAuthentication()
      Returns the authentication configuration for this mirror, if any.

      If this Mirror is defined as a reference, the authentication is resolved from the referenced instance.

      Returns:
      the associated Authentication or null if none
    • setAuthRef

      public void setAuthRef(org.apache.tools.ant.types.Reference ref)
      Sets a reference to a previously defined <authentication> element.

      This allows the mirror to reuse shared credentials declared elsewhere in the build script. If no authentication object exists yet, one is created automatically.

      Parameters:
      ref - a reference to an Authentication instance