Class Context

java.lang.Object
eu.maveniverse.maven.mima.context.Context
All Implemented Interfaces:
Closeable, AutoCloseable

public final class Context extends Object implements Closeable
The MIMA context holds references to RepositorySystem, RepositorySystemSession and list of RemoteRepository. Context is Closeable, ideally used in try-with-resource constructs.

The very first context instance application creates using Runtime.create(ContextOverrides) is called "root context", and creation of it can be considered "heavy" operation (runtime dependent). Root context should be kept open as long as application is expected to make use of Resolver.

Context instances may be customized with customize(ContextOverrides) method, in that case the returned context is "derived" from this context. In those cases the context instances should be handled "as nested", so closed in opposite order as they were obtained. Creating customized contexts can be considered "light" operation, as they merely alter the RepositorySystemSession instance and repositories, while the RepositorySystem is just inherited from this instance (is not reconstructed).

See Also:
  • Constructor Details

  • Method Details

    • contextOverrides

      public ContextOverrides contextOverrides()
      Returns the effective ContextOverrides, never null. This instance MAY be different from the user supplied one to Runtime.create(ContextOverrides), as it will contain discovered configuration as well.
      Since:
      2.1.0
    • basedir

      public Path basedir()
      The basedir ("cwd"), never null.
      Since:
      2.3.0
    • mavenUserHome

      public MavenUserHome mavenUserHome()
      Returns effective MavenUserHome, never null.
      Since:
      2.1.0
    • mavenSystemHome

      public MavenSystemHome mavenSystemHome()
      Returns effective MavenSystemHome, may be null, if no Maven Home discovered.
      Since:
      2.1.0
    • repositorySystemSession

      public org.eclipse.aether.RepositorySystemSession repositorySystemSession()
      Returns the RepositorySystemSession, never null.
    • repositorySystem

      public org.eclipse.aether.RepositorySystem repositorySystem()
      Returns the RepositorySystem, never null.
    • remoteRepositories

      public List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories()
      Returns the list of RemoteRepository, never null.
    • httpProxy

      public HTTPProxy httpProxy()
      Returns HTTP Proxy that Resolver will use, or null. This configuration may come from user settings.xml.
      Since:
      2.4.0
    • lookup

      public Lookup lookup()
      Returns Lookup instance usable to look up resolver components, never null.
      Since:
      2.4.10
    • customize

      public Context customize(ContextOverrides overrides)
      Returns a new Context instance, that is customized using passed in ContextOverrides, using this instance as "base".
    • getRuntime

      public Runtime getRuntime()
      Exposes Runtime instance used to create this context instance.
    • close

      public void close()
      Closes the context. Once closed context instance should not be used anymore.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable