Class AntRepoSys

java.lang.Object
org.apache.maven.resolver.internal.ant.AntRepoSys

public class AntRepoSys extends Object
Central utility for managing Maven repository system configuration and sessions within Ant builds.

This class handles the lifecycle of a RepositorySystem and provides access to its components, such as mirror selectors, proxy selectors, authentication, session management, and settings resolution. It also provides methods for resolving dependencies, installing, and deploying artifacts.

An instance of this class is typically retrieved via getInstance(Project) and registered under a predefined reference ID for reuse throughout the Ant build.

This class supports merging default and user-defined repositories and processing settings from settings.xml files, including mirrors, proxies, and server credentials.

  • Method Details

    • getInstance

      public static AntRepoSys getInstance(org.apache.tools.ant.Project project)
      Returns the singleton instance of AntRepoSys associated with the given Ant Project. Registers a new instance if not already present.
      Parameters:
      project - the current Ant project
      Returns:
      the AntRepoSys instance
    • getSystem

      public org.eclipse.aether.RepositorySystem getSystem()
      Returns the RepositorySystem used for dependency resolution and repository operations.
      Returns:
      the repository system instance
    • getSession

      public org.eclipse.aether.RepositorySystemSession getSession(org.apache.tools.ant.Task task, LocalRepository localRepo)
      Creates and returns a new RepositorySystemSession for the given task and local repository. Configures authentication, mirrors, proxies, offline mode, and repository listeners.
      Parameters:
      task - the invoking Ant task (used for logging and listeners)
      localRepo - optional local repository configuration
      Returns:
      a configured repository system session
    • setUserSettings

      public void setUserSettings(File file)
      Sets the path to the user-level settings.xml file. If changed, forces reloading of settings.
      Parameters:
      file - the user settings file
    • setGlobalSettings

      public void setGlobalSettings(File file)
      Sets the path to the global settings.xml file. If changed, forces reloading of settings.
      Parameters:
      file - the global settings file
    • addProxy

      public void addProxy(Proxy proxy)
      Registers a Proxy to be considered when building the proxy selector.
      Parameters:
      proxy - the proxy configuration
    • addMirror

      public void addMirror(Mirror mirror)
      Registers a Mirror to be included in the mirror selector.
      Parameters:
      mirror - the mirror configuration
    • addAuthentication

      public void addAuthentication(Authentication authentication)
      Registers an Authentication instance to be used during authentication selection.
      Parameters:
      authentication - the authentication configuration
    • setLocalRepository

      public void setLocalRepository(LocalRepository localRepository)
      Sets the local repository configuration.
      Parameters:
      localRepository - the local repository configuration
    • loadModel

      public org.apache.maven.model.Model loadModel(org.apache.tools.ant.Task task, File pomFile, boolean local, RemoteRepositories remoteRepositories)
      Resolves a Model from a pom.xml file, optionally validating it as a local or remote model.
      Parameters:
      task - the Ant task context
      pomFile - the POM file
      local - whether to load the model in strict/local mode
      remoteRepositories - optional custom remote repositories
      Returns:
      the effective Maven model
      Throws:
      org.apache.tools.ant.BuildException - if the POM cannot be loaded or resolved
    • setDefaultPom

      public void setDefaultPom(Pom pom)
      Sets the default Pom used for artifact operations when none is explicitly provided.
      Parameters:
      pom - the default POM
    • getDefaultPom

      public Pom getDefaultPom()
      Returns the default Pom, if set.
      Returns:
      the default POM or null
    • collectDependencies

      public org.eclipse.aether.collection.CollectResult collectDependencies(org.apache.tools.ant.Task task, Dependencies dependencies, LocalRepository localRepository, RemoteRepositories remoteRepositories)
      Performs dependency resolution by collecting transitive dependencies for the given configuration.
      Parameters:
      task - the Ant task context
      dependencies - the root dependencies
      localRepository - optional local repository override
      remoteRepositories - optional custom remote repositories
      Returns:
      the result of dependency collection
      Throws:
      org.apache.tools.ant.BuildException - if the dependency collection fails
    • install

      public void install(org.apache.tools.ant.Task task, Pom pom, Artifacts artifacts)
      Installs the specified artifacts to the local Maven repository.
      Parameters:
      task - the Ant task context
      pom - the associated POM metadata
      artifacts - the artifacts to install
      Throws:
      org.apache.tools.ant.BuildException - if the installation fails
    • deploy

      public void deploy(org.apache.tools.ant.Task task, Pom pom, Artifacts artifacts, RemoteRepository releaseRepository, RemoteRepository snapshotRepository)
      Deploys the specified artifacts to the configured remote repository (release or snapshot).
      Parameters:
      task - the Ant task context
      pom - the associated POM metadata
      artifacts - the artifacts to deploy
      releaseRepository - the repository for release artifacts
      snapshotRepository - the repository for snapshot artifacts
      Throws:
      org.apache.tools.ant.BuildException - if the deployment fails