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 Details

  • Method Details

    • getPath

      @Nonnull public Optional<Path> getPath(@Nonnull Project project)
      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 interface ProjectManager
      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

      @Nonnull public Collection<ProducedArtifact> getAttachedArtifacts(@Nonnull Project project)
      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 interface ProjectManager
      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

      @Nonnull public Collection<ProducedArtifact> getAllArtifacts(@Nonnull Project project)
      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
      The contents depend on the current lifecycle phase when this method is called, as artifacts are typically attached during specific phases (e.g., sources jar during package phase).
      Specified by:
      getAllArtifacts in interface ProjectManager
      Parameters:
      project - the project to get artifacts for
      Returns:
      an immutable ordered collection of all project artifacts
      See Also:
    • 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 interface ProjectManager
      Parameters:
      project - the project to attach the artifact to
      artifact - the produced artifact to attach
      path - the path to the artifact file
    • getSourceRoots

      @Nonnull public Collection<SourceRoot> getSourceRoots(@Nonnull Project project)
      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 interface ProjectManager
      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 is null, then this method returns the enabled sources for all scopes. If the given language is null, 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 interface ProjectManager
      Parameters:
      project - the project for which to get the enabled source roots
      scope - the scope of the sources to return, or null for all scopes
      language - the language of the sources to return, or null for all languages
      Returns:
      all enabled sources that provide files in the given language for the given scope
    • addSourceRoot

      public void addSourceRoot(@Nonnull Project project, @Nonnull SourceRoot source)
      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 the ProjectManager implementation. It may do nothing or thrown IllegalArgumentException.
      Specified by:
      addSourceRoot in interface ProjectManager
      Parameters:
      project - the project to update
      source - 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 new SourceRoot element. Otherwise (i.e., in case of potential conflict), the behavior depends on the ProjectManager. The default implementation does nothing in the latter case.
      Specified by:
      addSourceRoot in interface ProjectManager
      Parameters:
      project - the project to update
      scope - scope (main or test) of the directory to add
      language - language of the files contained in the directory to add
      directory - the directory to add if not already present in the source
      See Also:
    • getRemoteProjectRepositories

      @Nonnull public List<RemoteRepository> getRemoteProjectRepositories(@Nonnull Project project)
      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 interface ProjectManager
      Parameters:
      project - the project
      Returns:
      ordered list of remote repositories
    • getRemotePluginRepositories

      @Nonnull public List<RemoteRepository> getRemotePluginRepositories(@Nonnull Project project)
      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 interface ProjectManager
      Parameters:
      project - the project
      Returns:
      ordered list of remote repositories
    • setProperty

      public void setProperty(@Nonnull Project project, @Nonnull String key, String value)
      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 interface ProjectManager
      Parameters:
      project - the project to modify
      key - they property's key
      value - the value or null to unset the property
    • getProperties

      @Nonnull public Map<String,String> getProperties(@Nonnull Project project)
      Description copied from interface: ProjectManager
      Returns an immutable map of the project properties..
      Specified by:
      getProperties in interface ProjectManager
      Parameters:
      project - the project for which to get the properties
      Returns:
      an immutable map of the project properties
      See Also:
    • getExecutionProject

      @Nonnull public Optional<Project> getExecutionProject(@Nonnull Project project)
      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 interface ProjectManager
      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