Package org.apache.maven.api
Interface Session
- All Known Subinterfaces:
InternalSession
- All Known Implementing Classes:
AbstractSession
,DefaultSession
The session to install / deploy / resolve artifacts and dependencies.
- Since:
- 4.0.0
-
Method Summary
Modifier and TypeMethodDescriptioncollectDependencies
(Artifact artifact) Shortcut forgetService(DependencyCollector.class).collect(...)
collectDependencies
(DependencyCoordinate dependency) Collects the transitive dependencies of some artifacts and builds a dependency graph.collectDependencies
(Project project) Shortcut forgetService(DependencyCollector.class).collect(...)
createArtifact
(String groupId, String artifactId, String version, String extension) Shortcut forgetService(ArtifactFactory.class).create(...)
.createArtifact
(String groupId, String artifactId, String version, String classifier, String extension, String type) Shortcut forgetService(ArtifactFactory.class).create(...)
.createArtifactCoordinate
(String coordString) Creates a coordinate out of string that is formatted like:<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
createArtifactCoordinate
(String groupId, String artifactId, String version, String extension) Shortcut forgetService(ArtifactFactory.class).create(...)
.createArtifactCoordinate
(String groupId, String artifactId, String version, String classifier, String extension, String type) Shortcut forgetService(ArtifactFactory.class).create(...)
.createArtifactCoordinate
(Artifact artifact) Shortcut forgetService(ArtifactFactory.class).create(...)
.createDependencyCoordinate
(ArtifactCoordinate coordinate) Shortcut forgetService(DependencyFactory.class).create(...)
.createDependencyCoordinate
(Dependency dependency) Shortcut forgetService(DependencyFactory.class).create(...)
.createLocalRepository
(Path path) Shortcut forgetService(RepositoryFactory.class).createLocal(...)
.createRemoteRepository
(String id, String url) Shortcut forgetService(RepositoryFactory.class).createRemote(...)
.createRemoteRepository
(Repository repository) Shortcut forgetService(RepositoryFactory.class).createRemote(...)
.void
deployArtifact
(RemoteRepository repository, Artifact... artifacts) Shortcut forgetService(ArtifactDeployer.class).deploy(...)
.flattenDependencies
(Node node, ResolutionScope scope) Shortcut forgetService(DependencyResolver.class).flatten(...)
.getArtifactPath
(Artifact artifact) Shortcut forgetService(ArtifactManager.class).getPath(...)
.getData()
int
Returns the list of registered listeners.Returns the current maven versiongetPathForLocalArtifact
(Artifact artifact) Gets the relative path for a locally installed artifact.getPathForRemoteArtifact
(RemoteRepository remote, Artifact artifact) Gets the relative path for an artifact cached from a remote repository.getPluginContext
(Project project) Returns the plugin context for mojo being executed and the specifiedProject
, never returnsnull
as if context not present, creates it.Gets the root directory of the session, which is the root directory for the top directory project.<T extends Service>
TgetService
(Class<T> clazz) Retrieves the service for the interfaceGets the system properties to use for interpolation.Gets the directory of the topmost project being built, usually the current directory or the directory pointed at by the-f/--file
command line argument.Gets the user properties to use for interpolation.void
installArtifacts
(Collection<Artifact> artifacts) Shortcut forgetService(ArtifactInstaller.class).install(...)
.void
installArtifacts
(Artifact... artifacts) Shortcut forgetService(ArtifactInstaller.class).install(...)
.boolean
isVersionSnapshot
(String version) Checks whether a given artifact version is considered aSNAPSHOT
or not.parseVersion
(String version) Parses the specified version string, for example "1.0".parseVersionRange
(String versionRange) Parses the specified version range specification, for example "[1.0,2.0)".void
registerListener
(Listener listener) Register the given listener which will receive all events.resolveArtifact
(Artifact artifact) Shortcut forgetService(ArtifactResolver.class).resolve(...)
.resolveArtifact
(ArtifactCoordinate coordinate) Shortcut forgetService(ArtifactResolver.class).resolve(...)
.resolveArtifacts
(Collection<? extends ArtifactCoordinate> coordinates) Shortcut forgetService(ArtifactResolver.class).resolve(...)
.resolveArtifacts
(Artifact... artifacts) Shortcut forgetService(ArtifactResolver.class).resolve(...)
.resolveArtifacts
(ArtifactCoordinate... coordinates) Shortcut forgetService(ArtifactResolver.class).resolve(...)
.resolveDependencies
(List<DependencyCoordinate> dependencyCoordinates) resolveDependencies
(DependencyCoordinate dependencyCoordinate) resolveDependencies
(Project project, ResolutionScope scope) resolveVersion
(ArtifactCoordinate artifact) Resolves an artifact's meta version (if any) to a concrete version.resolveVersionRange
(ArtifactCoordinate artifact) Expands a version range to a list of matching versions, in ascending order.void
setArtifactPath
(Artifact artifact, Path path) Shortcut forgetService(ArtifactManager.class).setPath(...)
.void
unregisterListener
(Listener listener) Unregisters a previously registered listener.withLocalRepository
(LocalRepository localRepository) Creates a derived session using the given local repository.withRemoteRepositories
(List<RemoteRepository> repositories) Creates a derived session using the given remote repositories.
-
Method Details
-
getSettings
-
getLocalRepository
-
getRemoteRepositories
-
getData
-
getUserProperties
Gets the user properties to use for interpolation. The user properties have been configured directly by the user, e.g. via the-Dkey=value
parameter on the command line.- Returns:
- the user properties, never
null
-
getSystemProperties
Gets the system properties to use for interpolation. The system properties are collected from the runtime environment such asSystem.getProperties()
and environment variables.- Returns:
- the system properties, never
null
-
getMavenVersion
Returns the current maven version- Returns:
- the maven version, never
null
-
getDegreeOfConcurrency
int getDegreeOfConcurrency() -
getStartTime
-
getTopDirectory
Gets the directory of the topmost project being built, usually the current directory or the directory pointed at by the-f/--file
command line argument. -
getRootDirectory
Gets the root directory of the session, which is the root directory for the top directory project.- Throws:
IllegalStateException
- if the root directory could not be found- See Also:
-
getProjects
-
getPluginContext
Returns the plugin context for mojo being executed and the specifiedProject
, never returnsnull
as if context not present, creates it. Implementation note: while this method return type isMap
, the returned map instance implementsConcurrentMap
as well.- Throws:
MavenException
- if not called from the within a mojo execution
-
getService
Retrieves the service for the interface- Throws:
NoSuchElementException
- if the service could not be found
-
withLocalRepository
Creates a derived session using the given local repository.- Parameters:
localRepository
- the new local repository- Returns:
- the derived session
- Throws:
NullPointerException
- iflocalRepository
is null
-
withRemoteRepositories
Creates a derived session using the given remote repositories.- Parameters:
repositories
- the new list of remote repositories- Returns:
- the derived session
- Throws:
NullPointerException
- ifrepositories
is null
-
registerListener
Register the given listener which will receive all events.- Parameters:
listener
- the listener to register- Throws:
NullPointerException
- iflistener
is null
-
unregisterListener
Unregisters a previously registered listener.- Parameters:
listener
- the listener to unregister- Throws:
NullPointerException
- iflistener
is null
-
getListeners
Returns the list of registered listeners.- Returns:
- an immutable collection of listeners, never
null
-
createLocalRepository
Shortcut forgetService(RepositoryFactory.class).createLocal(...)
.- See Also:
-
createRemoteRepository
Shortcut forgetService(RepositoryFactory.class).createRemote(...)
. -
createRemoteRepository
Shortcut forgetService(RepositoryFactory.class).createRemote(...)
. -
createArtifactCoordinate
ArtifactCoordinate createArtifactCoordinate(String groupId, String artifactId, String version, String extension) Shortcut forgetService(ArtifactFactory.class).create(...)
. -
createArtifactCoordinate
Creates a coordinate out of string that is formatted like:<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
Shortcut for
getService(ArtifactFactory.class).create(...)
.- Parameters:
coordString
- the string having "standard" coordinate.- Returns:
- an
ArtifactCoordinate
, nevernull
- See Also:
-
createArtifactCoordinate
ArtifactCoordinate createArtifactCoordinate(String groupId, String artifactId, String version, String classifier, String extension, String type) Shortcut forgetService(ArtifactFactory.class).create(...)
. -
createArtifactCoordinate
Shortcut forgetService(ArtifactFactory.class).create(...)
. -
createDependencyCoordinate
Shortcut forgetService(DependencyFactory.class).create(...)
. -
createDependencyCoordinate
Shortcut forgetService(DependencyFactory.class).create(...)
. -
createArtifact
Shortcut forgetService(ArtifactFactory.class).create(...)
. -
createArtifact
Artifact createArtifact(String groupId, String artifactId, String version, String classifier, String extension, String type) Shortcut forgetService(ArtifactFactory.class).create(...)
. -
resolveArtifact
Shortcut forgetService(ArtifactResolver.class).resolve(...)
.- Throws:
ArtifactResolverException
- if the artifact resolution failed- See Also:
-
resolveArtifacts
Shortcut forgetService(ArtifactResolver.class).resolve(...)
.- Throws:
ArtifactResolverException
- if the artifact resolution failed- See Also:
-
resolveArtifacts
Shortcut forgetService(ArtifactResolver.class).resolve(...)
.- Throws:
ArtifactResolverException
- if the artifact resolution failed- See Also:
-
resolveArtifact
Shortcut forgetService(ArtifactResolver.class).resolve(...)
.- Throws:
ArtifactResolverException
- if the artifact resolution failed- See Also:
-
resolveArtifacts
Shortcut forgetService(ArtifactResolver.class).resolve(...)
.- Throws:
ArtifactResolverException
- if the artifact resolution failed- See Also:
-
installArtifacts
Shortcut forgetService(ArtifactInstaller.class).install(...)
.- Throws:
ArtifactInstallerException
- if the artifacts installation failed- See Also:
-
installArtifacts
Shortcut forgetService(ArtifactInstaller.class).install(...)
.- Throws:
ArtifactInstallerException
- if the artifacts installation failed- See Also:
-
deployArtifact
Shortcut forgetService(ArtifactDeployer.class).deploy(...)
.- Throws:
ArtifactDeployerException
- if the artifacts deployment failed- See Also:
-
setArtifactPath
Shortcut forgetService(ArtifactManager.class).setPath(...)
.- See Also:
-
getArtifactPath
Shortcut forgetService(ArtifactManager.class).getPath(...)
.- See Also:
-
getPathForLocalArtifact
Gets the relative path for a locally installed artifact. Note that the artifact need not actually exist yet at the returned location, the path merely indicates where the artifact would eventually be stored.Shortcut for
getService(LocalArtifactManager.class).getPathForLocalArtitact(...)
. -
getPathForRemoteArtifact
@Nonnull Path getPathForRemoteArtifact(@Nonnull RemoteRepository remote, @Nonnull Artifact artifact) Gets the relative path for an artifact cached from a remote repository. Note that the artifact need not actually exist yet at the returned location, the path merely indicates where the artifact would eventually be stored.Shortcut for
getService(LocalArtifactManager.class).getPathForRemoteArtifact(...)
. -
isVersionSnapshot
Checks whether a given artifact version is considered aSNAPSHOT
or not.Shortcut for
getService(ArtifactManager.class).isSnapshot(...)
.- See Also:
-
collectDependencies
Shortcut forgetService(DependencyCollector.class).collect(...)
- Throws:
DependencyCollectorException
- if the dependency collection failed- See Also:
-
collectDependencies
Shortcut forgetService(DependencyCollector.class).collect(...)
- Throws:
DependencyCollectorException
- if the dependency collection failed- See Also:
-
collectDependencies
Collects the transitive dependencies of some artifacts and builds a dependency graph. Note that this operation is only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the artifact files.Shortcut for
getService(DependencyCollector.class).resolve(...)
- Throws:
DependencyCollectorException
- if the dependency collection failed- See Also:
-
flattenDependencies
Shortcut forgetService(DependencyResolver.class).flatten(...)
.- Throws:
DependencyResolverException
- if the dependency flattening failed- See Also:
-
resolveDependencies
-
resolveDependencies
-
resolveDependencies
-
resolveVersion
Resolves an artifact's meta version (if any) to a concrete version. For example, resolves "1.0-SNAPSHOT" to "1.0-20090208.132618-23" or "RELEASE"/"LATEST" to "2.0".Shortcut for
getService(VersionResolver.class).resolve(...)
- Throws:
VersionResolverException
- if the resolution failed- See Also:
-
resolveVersionRange
Expands a version range to a list of matching versions, in ascending order. For example, resolves "[3.8,4.0)" to "3.8", "3.8.1", "3.8.2". The returned list of versions is only dependent on the configured repositories and their contents. The supplied request may also refer to a single concrete version rather than a version range. In this case though, the result contains simply the (parsed) input version, regardless of the repositories and their contents.- Returns:
- a list of resolved
Version
s. - Throws:
VersionRangeResolverException
- if the resolution failed- See Also:
-
parseVersion
Parses the specified version string, for example "1.0".Shortcut for
getService(VersionParser.class).parseVersion(...)
.- Throws:
VersionParserException
- if the parsing failed- See Also:
-
parseVersionRange
Parses the specified version range specification, for example "[1.0,2.0)".Shortcut for
getService(VersionParser.class).parseVersionRange(...)
.- Throws:
VersionParserException
- if the parsing failed- See Also:
-