Class Mirror
- All Implemented Interfaces:
Cloneable
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
AntRepoSysupon being assigned a project
- See Also:
-
Field Summary
Fields inherited from class org.apache.tools.ant.types.DataType
checked, refFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuthentication(Authentication authentication) Adds an<authentication>element to the mirror.Returns the authentication configuration for this mirror, if any.getId()Returns the identifier of this mirror.Returns the repository pattern that this mirror applies to.protected MirrorgetRef()Resolves this object if defined as a reference and verifies that it is aMirrorinstance.getType()Returns the layout type of the mirror repository.getUrl()Returns the URL of the mirror repository.voidsetAuthRef(org.apache.tools.ant.types.Reference ref) Sets a reference to a previously defined<authentication>element.voidSets the identifier of the mirror.voidsetMirrorOf(String mirrorOf) Specifies the repository IDs that this mirror should apply to.voidsetProject(org.apache.tools.ant.Project project) Sets the Ant project associated with this mirror.voidsetRefid(org.apache.tools.ant.types.Reference ref) voidSets the layout type of the mirror repository.voidSets 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, toStringMethods inherited from class org.apache.tools.ant.ProjectComponent
getDescription, getLocation, getProject, log, log, setDescription, setLocation
-
Constructor Details
-
Mirror
public Mirror()Default constructor used by Ant to create aMirrorinstance.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
AntRepoSysinstance for the project. This allows the mirror to influence repository resolution globally.- Overrides:
setProjectin classorg.apache.tools.ant.ProjectComponent- Parameters:
project- the Ant project- See Also:
-
getRef
Resolves this object if defined as a reference and verifies that it is aMirrorinstance.- Returns:
- the referenced
Mirrorinstance - 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:
setRefidin classorg.apache.tools.ant.types.DataType
-
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 referencedMirrorinstance.- Returns:
- the mirror ID, or
nullif not set - See Also:
-
setId
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
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
Mirroris defined as a reference (refid), the URL is resolved from the referencedMirrorinstance.- Returns:
- the mirror repository URL, or
nullif not set - See Also:
-
setUrl
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 bysetMirrorOf(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
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
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
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:*, orcentral,!snapshots. It determines which repositories should be redirected to this mirror.If this
Mirroris defined as a reference (refid), the value is retrieved from the referenced instance.- Returns:
- the
mirrorOfpattern, ornullif not set - See Also:
-
setMirrorOf
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
Mirroris 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
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 aBuildException.This method must not be used if the mirror is defined via
refid.- Parameters:
authentication- theAuthenticationobject 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
Returns the authentication configuration for this mirror, if any.If this
Mirroris defined as a reference, the authentication is resolved from the referenced instance.- Returns:
- the associated
Authenticationornullif 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 anAuthenticationinstance
-