Package org.apache.maven.internal.impl
Class DefaultProjectManager
java.lang.Object
org.apache.maven.internal.impl.DefaultProjectManager
- All Implemented Interfaces:
Service
,ProjectManager
@Named
@Typed
@SessionScoped
public class DefaultProjectManager
extends Object
implements ProjectManager
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultProjectManager
(InternalMavenSession session, ArtifactManager artifactManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSourceRoot
(Project project, ProjectScope scope, Language language, Path directory) Resolves and adds the given directory as a source with the given scope and language.void
addSourceRoot
(Project project, SourceRoot source) Adds the given source to the given project.void
attachArtifact
(Project project, ProducedArtifact artifact, Path path) Attaches a produced artifact to the project at the specified path.getAllArtifacts
(Project project) Returns project's all artifacts as an immutable ordered collection.getAttachedArtifacts
(Project project) Returns an immutable collection of attached artifacts for the given project.getEnabledSourceRoots
(Project project, ProjectScope scope, Language language) Returns all enabled sources that provide files in the given language for the given scope.getExecutionProject
(Project project) Returns the original project being built when the input project is a forked project.Returns the path to the built project artifact file, if the project has been built.getProperties
(Project project) Returns an immutable map of the project properties.getRemotePluginRepositories
(Project project) Returns an immutable list of project plugin remote repositories (directly specified or inherited).getRemoteProjectRepositories
(Project project) Returns an immutable list of project remote repositories (directly specified or inherited).getSourceRoots
(Project project) Returns all source root directories.void
setProperty
(Project project, String key, String value) Set a given project property.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.maven.api.services.ProjectManager
attachArtifact, attachArtifact
-
Constructor Details
-
DefaultProjectManager
-
-
Method Details
-
getPath
Description copied from interface:ProjectManager
Returns the path to the built project artifact file, if the project has been built. This path is only available after the artifact has been produced during the build lifecycle.- Specified by:
getPath
in interfaceProjectManager
- Parameters:
project
- the project to get the artifact path for- Returns:
- an Optional containing the path to the built artifact if available, or empty if the artifact hasn't been built yet
-
getAttachedArtifacts
Description copied from interface:ProjectManager
Returns an immutable collection of attached artifacts for the given project. Attached artifacts are secondary artifacts produced during the build (e.g., sources jar, javadoc jar, test jars). These artifacts are created and attached during specific lifecycle phases, so the collection contents depend on the build phase when this method is called.- Specified by:
getAttachedArtifacts
in interfaceProjectManager
- Parameters:
project
- the project to get attached artifacts for- Returns:
- an immutable collection of attached artifacts, may be empty if no artifacts have been attached yet
- See Also:
-
getAllArtifacts
Description copied from interface:ProjectManager
Returns project's all artifacts as an immutable ordered collection. The collection contains:- The project's artifacts (
Project.getArtifacts()
):- The POM artifact (always present)
- The main project artifact (if applicable based on packaging)
- All attached artifacts in the order they were attached
- Specified by:
getAllArtifacts
in interfaceProjectManager
- Parameters:
project
- the project to get artifacts for- Returns:
- an immutable ordered collection of all project artifacts
- See Also:
- The project's artifacts (
-
attachArtifact
public void attachArtifact(@Nonnull Project project, @Nonnull ProducedArtifact artifact, @Nonnull Path path) Description copied from interface:ProjectManager
Attaches a produced artifact to the project at the specified path. This is the base method that the other attachArtifact methods delegate to.- Specified by:
attachArtifact
in interfaceProjectManager
- Parameters:
project
- the project to attach the artifact toartifact
- the produced artifact to attachpath
- the path to the artifact file
-
getSourceRoots
Description copied from interface:ProjectManager
Returns all source root directories., including the disabled ones, for all languages and scopes. For listing only the enabled source roots, the following code can be used:List<SourceRoot> enabledRoots = project.getSourceRoots() .stream().filter(SourceRoot::enabled).toList();
The iteration order is the order in which the sources are declared in the POM file.- Specified by:
getSourceRoots
in interfaceProjectManager
- Parameters:
project
- the project for which to get the source roots- Returns:
- all source root directories
-
getEnabledSourceRoots
@Nonnull public Stream<SourceRoot> getEnabledSourceRoots(@Nonnull Project project, ProjectScope scope, Language language) Description copied from interface:ProjectManager
Returns all enabled sources that provide files in the given language for the given scope.. If the given scope isnull
, then this method returns the enabled sources for all scopes. If the given language isnull
, then this method returns the enabled sources for all languages. An arbitrary number of source roots may exist for the same scope and language. It may be, for example, the case of a multi-versions project. The iteration order is the order in which the sources are declared in the POM file.- Specified by:
getEnabledSourceRoots
in interfaceProjectManager
- Parameters:
project
- the project for which to get the enabled source rootsscope
- the scope of the sources to return, ornull
for all scopeslanguage
- the language of the sources to return, ornull
for all languages- Returns:
- all enabled sources that provide files in the given language for the given scope
-
addSourceRoot
Description copied from interface:ProjectManager
Adds the given source to the given project. If a source already exists for the given scope, language and directory, then the behavior depends on theProjectManager
implementation. It may do nothing or thrown IllegalArgumentException.- Specified by:
addSourceRoot
in interfaceProjectManager
- Parameters:
project
- the project to updatesource
- the source to add- See Also:
-
addSourceRoot
public void addSourceRoot(@Nonnull Project project, @Nonnull ProjectScope scope, @Nonnull Language language, @Nonnull Path directory) Description copied from interface:ProjectManager
Resolves and adds the given directory as a source with the given scope and language. First, this method resolves the given root against the project base directory, then normalizes the path. If no source already exists for the same scope, language and normalized directory, these arguments are added as a newSourceRoot
element. Otherwise (i.e., in case of potential conflict), the behavior depends on theProjectManager
. The default implementation does nothing in the latter case.- Specified by:
addSourceRoot
in interfaceProjectManager
- Parameters:
project
- the project to updatescope
- scope (main or test) of the directory to addlanguage
- language of the files contained in the directory to adddirectory
- the directory to add if not already present in the source- See Also:
-
getRemoteProjectRepositories
Description copied from interface:ProjectManager
Returns an immutable list of project remote repositories (directly specified or inherited). The repositories are ordered by declaration order, with inherited repositories appearing after directly specified ones.- Specified by:
getRemoteProjectRepositories
in interfaceProjectManager
- Parameters:
project
- the project- Returns:
- ordered list of remote repositories
-
getRemotePluginRepositories
Description copied from interface:ProjectManager
Returns an immutable list of project plugin remote repositories (directly specified or inherited). The repositories are ordered by declaration order, with inherited repositories appearing after directly specified ones.- Specified by:
getRemotePluginRepositories
in interfaceProjectManager
- Parameters:
project
- the project- Returns:
- ordered list of remote repositories
-
setProperty
Description copied from interface:ProjectManager
Set a given project property. Properties set through this method are only valid for the current build session and do not modify the underlying project model.- Specified by:
setProperty
in interfaceProjectManager
- Parameters:
project
- the project to modifykey
- they property's keyvalue
- the value ornull
to unset the property
-
getProperties
Description copied from interface:ProjectManager
Returns an immutable map of the project properties..- Specified by:
getProperties
in interfaceProjectManager
- Parameters:
project
- the project for which to get the properties- Returns:
- an immutable map of the project properties
- See Also:
-
getExecutionProject
Description copied from interface:ProjectManager
Returns the original project being built when the input project is a forked project. During certain lifecycle phases, particularly for aggregator mojos, Maven may create a forked project (a copy of the original project) to execute a subset of the lifecycle. This method allows retrieving the original project that initiated the build.- Specified by:
getExecutionProject
in interfaceProjectManager
- Parameters:
project
- the potentially forked project- Returns:
- an Optional containing the original project if the input is a forked project, or an empty Optional if the input is already the original project
-