Class MavenProject

  • All Implemented Interfaces:
    Cloneable

    public class MavenProject
    extends Object
    implements Cloneable
    The concern of the project is provide runtime values based on the model.

    The values in the model remain untouched but during the process of building a project notions like inheritance and interpolation can be added. This allows to have an entity which is useful in a runtime while preserving the model so that it can be marshalled and unmarshalled without being tainted by runtime requirements.

    With changes during 3.2.2 release MavenProject is closer to being immutable after construction with the removal of all components from this class, and the upfront construction taken care of entirely by the ProjectBuilder. There is still the issue of having to run the lifecycle in order to find all the compile source roots and resource directories but I hope to take care of this during the Maven 4.0 release (jvz).

    • Constructor Detail

      • MavenProject

        public MavenProject()
      • MavenProject

        public MavenProject​(Model model)
      • MavenProject

        public MavenProject​(MavenProject project)
    • Method Detail

      • getParentFile

        public File getParentFile()
      • setParentFile

        public void setParentFile​(File parentFile)
      • getArtifact

        public Artifact getArtifact()
      • setArtifact

        public void setArtifact​(Artifact artifact)
      • getModel

        public Model getModel()
      • getParent

        public MavenProject getParent()
        Returns the project corresponding to a declared parent.
        Returns:
        the parent, or null if no parent is declared or there was an error building it
      • setParent

        public void setParent​(MavenProject parent)
      • hasParent

        public boolean hasParent()
      • getFile

        public File getFile()
      • setFile

        public void setFile​(File file)
      • setPomFile

        public void setPomFile​(File file)
        Sets project file without changing project basedir.
        Since:
        3.2.4
      • getBasedir

        public File getBasedir()
      • setDependencies

        public void setDependencies​(List<Dependency> dependencies)
      • addCompileSourceRoot

        public void addCompileSourceRoot​(String path)
      • addTestCompileSourceRoot

        public void addTestCompileSourceRoot​(String path)
      • getCompileSourceRoots

        public List<String> getCompileSourceRoots()
      • getTestCompileSourceRoots

        public List<String> getTestCompileSourceRoots()
      • setModelVersion

        public void setModelVersion​(String pomVersion)
      • getModelVersion

        public String getModelVersion()
      • getId

        public String getId()
      • setGroupId

        public void setGroupId​(String groupId)
      • getGroupId

        public String getGroupId()
      • setArtifactId

        public void setArtifactId​(String artifactId)
      • getArtifactId

        public String getArtifactId()
      • setName

        public void setName​(String name)
      • getName

        public String getName()
      • setVersion

        public void setVersion​(String version)
      • getVersion

        public String getVersion()
      • getPackaging

        public String getPackaging()
      • setPackaging

        public void setPackaging​(String packaging)
      • setInceptionYear

        public void setInceptionYear​(String inceptionYear)
      • getInceptionYear

        public String getInceptionYear()
      • setUrl

        public void setUrl​(String url)
      • getUrl

        public String getUrl()
      • setIssueManagement

        public void setIssueManagement​(IssueManagement issueManagement)
      • setCiManagement

        public void setCiManagement​(CiManagement ciManagement)
      • setDistributionManagement

        public void setDistributionManagement​(DistributionManagement distributionManagement)
      • setDescription

        public void setDescription​(String description)
      • getDescription

        public String getDescription()
      • setOrganization

        public void setOrganization​(Organization organization)
      • setScm

        public void setScm​(Scm scm)
      • getScm

        public Scm getScm()
      • setMailingLists

        public void setMailingLists​(List<MailingList> mailingLists)
      • addMailingList

        public void addMailingList​(MailingList mailingList)
      • setDevelopers

        public void setDevelopers​(List<Developer> developers)
      • addDeveloper

        public void addDeveloper​(Developer developer)
      • setContributors

        public void setContributors​(List<Contributor> contributors)
      • addContributor

        public void addContributor​(Contributor contributor)
      • setBuild

        public void setBuild​(Build build)
      • getBuild

        public Build getBuild()
      • getTestResources

        public List<Resource> getTestResources()
      • addResource

        public void addResource​(Resource resource)
      • addTestResource

        public void addTestResource​(Resource testResource)
      • setLicenses

        public void setLicenses​(List<License> licenses)
      • addLicense

        public void addLicense​(License license)
      • setArtifacts

        public void setArtifacts​(Set<Artifact> artifacts)
      • getArtifacts

        public Set<Artifact> getArtifacts()
        All dependencies that this project has, including transitive ones. Contents are lazily populated, so depending on what phases have run dependencies in some scopes won't be included. eg. if only compile phase has run, dependencies with scope test won't be included.
        Returns:
        Set < Artifact >
        See Also:
        to get only direct dependencies
      • setPluginArtifacts

        public void setPluginArtifacts​(Set<Artifact> pluginArtifacts)
      • getPluginArtifacts

        public Set<Artifact> getPluginArtifacts()
      • setParentArtifact

        public void setParentArtifact​(Artifact parentArtifact)
      • getParentArtifact

        public Artifact getParentArtifact()
      • getBuildPlugins

        public List<Plugin> getBuildPlugins()
      • setRemoteArtifactRepositories

        public void setRemoteArtifactRepositories​(List<ArtifactRepository> remoteArtifactRepositories)
      • setPluginArtifactRepositories

        public void setPluginArtifactRepositories​(List<ArtifactRepository> pluginArtifactRepositories)
      • getPluginArtifactRepositories

        public List<ArtifactRepository> getPluginArtifactRepositories()
        Returns:
        a list of ArtifactRepository objects constructed from the Repository objects returned by getPluginRepositories.
      • getDistributionManagementArtifactRepository

        public ArtifactRepository getDistributionManagementArtifactRepository()
      • getPluginRepositories

        public List<Repository> getPluginRepositories()
      • getRemoteProjectRepositories

        public List<org.eclipse.aether.repository.RemoteRepository> getRemoteProjectRepositories()
      • getRemotePluginRepositories

        public List<org.eclipse.aether.repository.RemoteRepository> getRemotePluginRepositories()
      • setActiveProfiles

        public void setActiveProfiles​(List<Profile> activeProfiles)
      • getActiveProfiles

        public List<Profile> getActiveProfiles()
      • setInjectedProfileIds

        public void setInjectedProfileIds​(String source,
                                          List<String> injectedProfileIds)
      • getInjectedProfileIds

        public Map<String,​List<String>> getInjectedProfileIds()
        Gets the identifiers of all profiles that contributed to this project's effective model. This includes active profiles from the project's POM and all its parent POMs as well as from external sources like the settings.xml. The profile identifiers are grouped by the identifier of their source, e.g. <groupId>:<artifactId>:<version> for a POM profile or external for profiles from the settings.xml.
        Returns:
        The identifiers of all injected profiles, indexed by the source from which the profiles originated, never null.
      • addAttachedArtifact

        public void addAttachedArtifact​(Artifact artifact)
                                 throws DuplicateArtifactAttachmentException
        Deprecated.
        Add or replace an artifact. This method is now deprecated. Use the @{MavenProjectHelper} to attach artifacts to a project. In spite of the 'throws' declaration on this API, this method has never thrown an exception since Maven 3.0.x. Historically, it logged and ignored a second addition of the same g/a/v/c/t. Now it replaces the file for the artifact, so that plugins (e.g. shade) can change the pathname of the file for a particular set of coordinates.
        Parameters:
        artifact - the artifact to add or replace.
        Throws:
        DuplicateArtifactAttachmentException - will never happen but leave it for backward compatibility
      • getAttachedArtifacts

        public List<Artifact> getAttachedArtifacts()
        Returns a mutable list of the attached artifacts to this project. It is highly advised not to modify this list, but rather use the MavenProjectHelper.

        Note: This list will be made read-only in Maven 4.

        Returns:
        the attached artifacts of this project
      • getGoalConfiguration

        public org.codehaus.plexus.util.xml.Xpp3Dom getGoalConfiguration​(String pluginGroupId,
                                                                         String pluginArtifactId,
                                                                         String executionId,
                                                                         String goalId)
      • getExecutionProject

        public MavenProject getExecutionProject()
      • setExecutionProject

        public void setExecutionProject​(MavenProject executionProject)
      • setCollectedProjects

        public void setCollectedProjects​(List<MavenProject> collectedProjects)
      • setDependencyArtifacts

        @Deprecated
        public void setDependencyArtifacts​(Set<Artifact> dependencyArtifacts)
        Deprecated.
      • setReleaseArtifactRepository

        public void setReleaseArtifactRepository​(ArtifactRepository releaseArtifactRepository)
      • setSnapshotArtifactRepository

        public void setSnapshotArtifactRepository​(ArtifactRepository snapshotArtifactRepository)
      • setOriginalModel

        public void setOriginalModel​(Model originalModel)
      • getOriginalModel

        public Model getOriginalModel()
      • setManagedVersionMap

        public void setManagedVersionMap​(Map<String,​Artifact> map)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getBuildExtensions

        public List<Extension> getBuildExtensions()
      • addProjectReference

        public void addProjectReference​(MavenProject project)
      • getProperties

        public Properties getProperties()
      • isExecutionRoot

        public boolean isExecutionRoot()
      • setExecutionRoot

        public void setExecutionRoot​(boolean executionRoot)
      • getDefaultGoal

        public String getDefaultGoal()
      • setModel

        public void setModel​(Model model)
      • setAttachedArtifacts

        protected void setAttachedArtifacts​(List<Artifact> attachedArtifacts)
      • setCompileSourceRoots

        protected void setCompileSourceRoots​(List<String> compileSourceRoots)
      • setTestCompileSourceRoots

        protected void setTestCompileSourceRoots​(List<String> testCompileSourceRoots)
      • getReleaseArtifactRepository

        protected ArtifactRepository getReleaseArtifactRepository()
      • getSnapshotArtifactRepository

        protected ArtifactRepository getSnapshotArtifactRepository()
      • setContextValue

        public void setContextValue​(String key,
                                    Object value)
        Sets the value of the context value of this project identified by the given key. If the supplied value is null, the context value is removed from this project. Context values are intended to allow core extensions to associate derived state with project instances.
      • getContextValue

        public Object getContextValue​(String key)
        Returns context value of this project associated with the given key or null if this project has no such value.
      • setClassRealm

        public void setClassRealm​(org.codehaus.plexus.classworlds.realm.ClassRealm classRealm)
        Sets the project's class realm. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Parameters:
        classRealm - The class realm hosting the build extensions of this project, may be null.
      • getClassRealm

        public org.codehaus.plexus.classworlds.realm.ClassRealm getClassRealm()
        Gets the project's class realm. This class realm hosts the build extensions of the project. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Returns:
        The project's class realm or null.
      • setExtensionDependencyFilter

        public void setExtensionDependencyFilter​(org.eclipse.aether.graph.DependencyFilter extensionDependencyFilter)
        Sets the artifact filter used to exclude shared extension artifacts from plugin realms. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Parameters:
        extensionDependencyFilter - The dependency filter to apply to plugins, may be null.
      • getExtensionDependencyFilter

        public org.eclipse.aether.graph.DependencyFilter getExtensionDependencyFilter()
        Gets the dependency filter used to exclude shared extension artifacts from plugin realms. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Returns:
        The dependency filter or null.
      • setResolvedArtifacts

        public void setResolvedArtifacts​(Set<Artifact> artifacts)
        Sets the transitive dependency artifacts that have been resolved/collected for this project. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Parameters:
        artifacts - The set of artifacts, may be null.
      • setArtifactFilter

        public void setArtifactFilter​(ArtifactFilter artifactFilter)
        Sets the scope filter to select the artifacts being exposed to the currently executed mojo. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Parameters:
        artifactFilter - The artifact filter, may be null to exclude all artifacts.
      • hasLifecyclePhase

        public boolean hasLifecyclePhase​(String phase)
        Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Parameters:
        phase - The phase to check for, must not be null.
        Returns:
        true if the phase has been seen.
      • addLifecyclePhase

        public void addLifecyclePhase​(String lifecyclePhase)
        Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
        Parameters:
        lifecyclePhase - The lifecycle phase to add, must not be null.
      • setScriptSourceRoots

        @Deprecated
        protected void setScriptSourceRoots​(List<String> scriptSourceRoots)
        Deprecated.
      • addScriptSourceRoot

        @Deprecated
        public void addScriptSourceRoot​(String path)
        Deprecated.
      • setReportArtifacts

        @Deprecated
        public void setReportArtifacts​(Set<Artifact> reportArtifacts)
        Deprecated.
      • setExtensionArtifacts

        @Deprecated
        public void setExtensionArtifacts​(Set<Artifact> extensionArtifacts)
        Deprecated.
      • getReportConfiguration

        @Deprecated
        public org.codehaus.plexus.util.xml.Xpp3Dom getReportConfiguration​(String pluginGroupId,
                                                                           String pluginArtifactId,
                                                                           String reportSetId)
        Deprecated.
      • attachArtifact

        @Deprecated
        public void attachArtifact​(String type,
                                   String classifier,
                                   File file)
        Deprecated.
        Use MavenProjectHelper.attachArtifact(..) instead.
      • getProjectBuildingRequest

        @Deprecated
        public ProjectBuildingRequest getProjectBuildingRequest()
        Deprecated.
        Gets the project building request from which this project instance was created. Warning: This is an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
        Returns:
        The project building request or null.
        Since:
        2.1
      • setProjectBuildingRequest

        @Deprecated
        public void setProjectBuildingRequest​(ProjectBuildingRequest projectBuildingRequest)
        Deprecated.
        Sets the project building request from which this project instance was created. Warning: This is an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
        Parameters:
        projectBuildingRequest - The project building request, may be null.
        Since:
        2.1