Class MavenProject

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class MavenProject
    extends java.lang.Object
    implements java.lang.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).

    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • EMPTY_PROJECT_GROUP_ID

        public static final java.lang.String EMPTY_PROJECT_GROUP_ID
        See Also:
        Constant Field Values
      • EMPTY_PROJECT_ARTIFACT_ID

        public static final java.lang.String EMPTY_PROJECT_ARTIFACT_ID
        See Also:
        Constant Field Values
      • EMPTY_PROJECT_VERSION

        public static final java.lang.String EMPTY_PROJECT_VERSION
        See Also:
        Constant Field Values
      • model

        private Model model
      • file

        private java.io.File file
      • basedir

        private java.io.File basedir
      • resolvedArtifacts

        private java.util.Set<Artifact> resolvedArtifacts
      • artifacts

        private java.util.Set<Artifact> artifacts
      • parentArtifact

        private Artifact parentArtifact
      • pluginArtifacts

        private java.util.Set<Artifact> pluginArtifacts
      • remoteArtifactRepositories

        private java.util.List<ArtifactRepository> remoteArtifactRepositories
      • pluginArtifactRepositories

        private java.util.List<ArtifactRepository> pluginArtifactRepositories
      • remoteProjectRepositories

        private java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories
      • remotePluginRepositories

        private java.util.List<org.eclipse.aether.repository.RemoteRepository> remotePluginRepositories
      • attachedArtifacts

        private java.util.List<Artifact> attachedArtifacts
      • collectedProjects

        private java.util.List<MavenProject> collectedProjects
      • compileSourceRoots

        private java.util.List<java.lang.String> compileSourceRoots
      • testCompileSourceRoots

        private java.util.List<java.lang.String> testCompileSourceRoots
      • scriptSourceRoots

        private java.util.List<java.lang.String> scriptSourceRoots
      • activeProfiles

        private java.util.List<Profile> activeProfiles
      • injectedProfileIds

        private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> injectedProfileIds
      • dependencyArtifacts

        private java.util.Set<Artifact> dependencyArtifacts
      • artifactMap

        private java.util.Map<java.lang.String,​Artifact> artifactMap
      • originalModel

        private Model originalModel
      • pluginArtifactMap

        private java.util.Map<java.lang.String,​Artifact> pluginArtifactMap
      • reportArtifacts

        private java.util.Set<Artifact> reportArtifacts
      • reportArtifactMap

        private java.util.Map<java.lang.String,​Artifact> reportArtifactMap
      • extensionArtifacts

        private java.util.Set<Artifact> extensionArtifacts
      • extensionArtifactMap

        private java.util.Map<java.lang.String,​Artifact> extensionArtifactMap
      • managedVersionMap

        private java.util.Map<java.lang.String,​Artifact> managedVersionMap
      • projectReferences

        private java.util.Map<java.lang.String,​MavenProject> projectReferences
      • executionRoot

        private boolean executionRoot
      • parentFile

        private java.io.File parentFile
      • context

        private java.util.Map<java.lang.String,​java.lang.Object> context
      • classRealm

        private org.codehaus.plexus.classworlds.realm.ClassRealm classRealm
      • extensionDependencyFilter

        private org.eclipse.aether.graph.DependencyFilter extensionDependencyFilter
      • lifecyclePhases

        private final java.util.Set<java.lang.String> lifecyclePhases
      • moduleAdjustments

        private java.util.Map<java.lang.String,​java.lang.String> moduleAdjustments
    • Constructor Detail

      • MavenProject

        public MavenProject()
      • MavenProject

        public MavenProject​(Model model)
      • MavenProject

        public MavenProject​(MavenProject project)
    • Method Detail

      • getParentFile

        public java.io.File getParentFile()
      • setParentFile

        public void setParentFile​(java.io.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 java.io.File getFile()
      • setFile

        public void setFile​(java.io.File file)
      • setPomFile

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

        public java.io.File getBasedir()
      • setDependencies

        public void setDependencies​(java.util.List<Dependency> dependencies)
      • getDependencies

        public java.util.List<Dependency> getDependencies()
      • addPath

        private void addPath​(java.util.List<java.lang.String> paths,
                             java.lang.String path)
      • addCompileSourceRoot

        public void addCompileSourceRoot​(java.lang.String path)
      • addTestCompileSourceRoot

        public void addTestCompileSourceRoot​(java.lang.String path)
      • getCompileSourceRoots

        public java.util.List<java.lang.String> getCompileSourceRoots()
      • getTestCompileSourceRoots

        public java.util.List<java.lang.String> getTestCompileSourceRoots()
      • setModelVersion

        public void setModelVersion​(java.lang.String pomVersion)
      • getModelVersion

        public java.lang.String getModelVersion()
      • getId

        public java.lang.String getId()
      • setGroupId

        public void setGroupId​(java.lang.String groupId)
      • getGroupId

        public java.lang.String getGroupId()
      • setArtifactId

        public void setArtifactId​(java.lang.String artifactId)
      • getArtifactId

        public java.lang.String getArtifactId()
      • setName

        public void setName​(java.lang.String name)
      • getName

        public java.lang.String getName()
      • setVersion

        public void setVersion​(java.lang.String version)
      • getVersion

        public java.lang.String getVersion()
      • getPackaging

        public java.lang.String getPackaging()
      • setPackaging

        public void setPackaging​(java.lang.String packaging)
      • setInceptionYear

        public void setInceptionYear​(java.lang.String inceptionYear)
      • getInceptionYear

        public java.lang.String getInceptionYear()
      • setUrl

        public void setUrl​(java.lang.String url)
      • getUrl

        public java.lang.String getUrl()
      • setIssueManagement

        public void setIssueManagement​(IssueManagement issueManagement)
      • setCiManagement

        public void setCiManagement​(CiManagement ciManagement)
      • setDistributionManagement

        public void setDistributionManagement​(DistributionManagement distributionManagement)
      • setDescription

        public void setDescription​(java.lang.String description)
      • getDescription

        public java.lang.String getDescription()
      • setOrganization

        public void setOrganization​(Organization organization)
      • setScm

        public void setScm​(Scm scm)
      • getScm

        public Scm getScm()
      • setMailingLists

        public void setMailingLists​(java.util.List<MailingList> mailingLists)
      • getMailingLists

        public java.util.List<MailingList> getMailingLists()
      • addMailingList

        public void addMailingList​(MailingList mailingList)
      • setDevelopers

        public void setDevelopers​(java.util.List<Developer> developers)
      • getDevelopers

        public java.util.List<Developer> getDevelopers()
      • addDeveloper

        public void addDeveloper​(Developer developer)
      • setContributors

        public void setContributors​(java.util.List<Contributor> contributors)
      • getContributors

        public java.util.List<Contributor> getContributors()
      • addContributor

        public void addContributor​(Contributor contributor)
      • setBuild

        public void setBuild​(Build build)
      • getBuild

        public Build getBuild()
      • getResources

        public java.util.List<Resource> getResources()
      • getTestResources

        public java.util.List<Resource> getTestResources()
      • addResource

        public void addResource​(Resource resource)
      • addTestResource

        public void addTestResource​(Resource testResource)
      • setLicenses

        public void setLicenses​(java.util.List<License> licenses)
      • getLicenses

        public java.util.List<License> getLicenses()
      • addLicense

        public void addLicense​(License license)
      • setArtifacts

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

        public java.util.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
      • getArtifactMap

        public java.util.Map<java.lang.String,​Artifact> getArtifactMap()
      • setPluginArtifacts

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

        public java.util.Set<Artifact> getPluginArtifacts()
      • getPluginArtifactMap

        public java.util.Map<java.lang.String,​Artifact> getPluginArtifactMap()
      • setParentArtifact

        public void setParentArtifact​(Artifact parentArtifact)
      • getParentArtifact

        public Artifact getParentArtifact()
      • getRepositories

        public java.util.List<Repository> getRepositories()
      • getBuildPlugins

        public java.util.List<Plugin> getBuildPlugins()
      • getModules

        public java.util.List<java.lang.String> getModules()
      • getModelBuild

        private Build getModelBuild()
      • setRemoteArtifactRepositories

        public void setRemoteArtifactRepositories​(java.util.List<ArtifactRepository> remoteArtifactRepositories)
      • getRemoteArtifactRepositories

        public java.util.List<ArtifactRepository> getRemoteArtifactRepositories()
      • setPluginArtifactRepositories

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

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

        public ArtifactRepository getDistributionManagementArtifactRepository()
      • getPluginRepositories

        public java.util.List<Repository> getPluginRepositories()
      • getRemoteProjectRepositories

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

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

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

        public java.util.List<Profile> getActiveProfiles()
      • setInjectedProfileIds

        public void setInjectedProfileIds​(java.lang.String source,
                                          java.util.List<java.lang.String> injectedProfileIds)
      • getInjectedProfileIds

        public java.util.Map<java.lang.String,​java.util.List<java.lang.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 java.util.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​(java.lang.String pluginGroupId,
                                                                         java.lang.String pluginArtifactId,
                                                                         java.lang.String executionId,
                                                                         java.lang.String goalId)
      • getExecutionProject

        public MavenProject getExecutionProject()
      • setExecutionProject

        public void setExecutionProject​(MavenProject executionProject)
      • getCollectedProjects

        public java.util.List<MavenProject> getCollectedProjects()
      • setCollectedProjects

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

        @Deprecated
        public void setDependencyArtifacts​(java.util.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​(java.util.Map<java.lang.String,​Artifact> map)
      • getManagedVersionMap

        public java.util.Map<java.lang.String,​Artifact> getManagedVersionMap()
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.util.List<Extension> getBuildExtensions()
      • addProjectReference

        public void addProjectReference​(MavenProject project)
      • getProperties

        public java.util.Properties getProperties()
      • getFilters

        public java.util.List<java.lang.String> getFilters()
      • getProjectReferences

        public java.util.Map<java.lang.String,​MavenProject> getProjectReferences()
      • isExecutionRoot

        public boolean isExecutionRoot()
      • setExecutionRoot

        public void setExecutionRoot​(boolean executionRoot)
      • getDefaultGoal

        public java.lang.String getDefaultGoal()
      • getPlugin

        public Plugin getPlugin​(java.lang.String pluginKey)
      • toString

        public java.lang.String toString()
        Default toString
        Overrides:
        toString in class java.lang.Object
      • clone

        public MavenProject clone()
        Overrides:
        clone in class java.lang.Object
        Since:
        2.0.9
      • setModel

        public void setModel​(Model model)
      • setAttachedArtifacts

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

        protected void setCompileSourceRoots​(java.util.List<java.lang.String> compileSourceRoots)
      • setTestCompileSourceRoots

        protected void setTestCompileSourceRoots​(java.util.List<java.lang.String> testCompileSourceRoots)
      • getReleaseArtifactRepository

        protected ArtifactRepository getReleaseArtifactRepository()
      • getSnapshotArtifactRepository

        protected ArtifactRepository getSnapshotArtifactRepository()
      • deepCopy

        private void deepCopy​(MavenProject project)
      • addArtifactPath

        private void addArtifactPath​(Artifact artifact,
                                     java.util.List<java.lang.String> classpath)
      • getProjectReferenceId

        private static java.lang.String getProjectReferenceId​(java.lang.String groupId,
                                                              java.lang.String artifactId,
                                                              java.lang.String version)
      • setContextValue

        public void setContextValue​(java.lang.String key,
                                    java.lang.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 java.lang.Object getContextValue​(java.lang.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​(java.util.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​(java.lang.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​(java.lang.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.
      • getModulePathAdjustment

        @Deprecated
        public java.lang.String getModulePathAdjustment​(MavenProject moduleProject)
                                                 throws java.io.IOException
        Deprecated.
        Throws:
        java.io.IOException
      • setScriptSourceRoots

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

        @Deprecated
        public void addScriptSourceRoot​(java.lang.String path)
        Deprecated.
      • getScriptSourceRoots

        @Deprecated
        public java.util.List<java.lang.String> getScriptSourceRoots()
        Deprecated.
      • getCompileArtifacts

        @Deprecated
        public java.util.List<Artifact> getCompileArtifacts()
        Deprecated.
      • getCompileDependencies

        @Deprecated
        public java.util.List<Dependency> getCompileDependencies()
        Deprecated.
      • getTestArtifacts

        @Deprecated
        public java.util.List<Artifact> getTestArtifacts()
        Deprecated.
      • getTestDependencies

        @Deprecated
        public java.util.List<Dependency> getTestDependencies()
        Deprecated.
      • getRuntimeDependencies

        @Deprecated
        public java.util.List<Dependency> getRuntimeDependencies()
        Deprecated.
      • getRuntimeArtifacts

        @Deprecated
        public java.util.List<Artifact> getRuntimeArtifacts()
        Deprecated.
      • getSystemArtifacts

        @Deprecated
        public java.util.List<Artifact> getSystemArtifacts()
        Deprecated.
      • getSystemDependencies

        @Deprecated
        public java.util.List<Dependency> getSystemDependencies()
        Deprecated.
      • setReporting

        @Deprecated
        public void setReporting​(Reporting reporting)
        Deprecated.
      • getReporting

        @Deprecated
        public Reporting getReporting()
        Deprecated.
      • setReportArtifacts

        @Deprecated
        public void setReportArtifacts​(java.util.Set<Artifact> reportArtifacts)
        Deprecated.
      • getReportArtifacts

        @Deprecated
        public java.util.Set<Artifact> getReportArtifacts()
        Deprecated.
      • getReportArtifactMap

        @Deprecated
        public java.util.Map<java.lang.String,​Artifact> getReportArtifactMap()
        Deprecated.
      • setExtensionArtifacts

        @Deprecated
        public void setExtensionArtifacts​(java.util.Set<Artifact> extensionArtifacts)
        Deprecated.
      • getExtensionArtifacts

        @Deprecated
        public java.util.Set<Artifact> getExtensionArtifacts()
        Deprecated.
      • getExtensionArtifactMap

        @Deprecated
        public java.util.Map<java.lang.String,​Artifact> getExtensionArtifactMap()
        Deprecated.
      • getReportPlugins

        @Deprecated
        public java.util.List<ReportPlugin> getReportPlugins()
        Deprecated.
      • getReportConfiguration

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

        @Deprecated
        public void attachArtifact​(java.lang.String type,
                                   java.lang.String classifier,
                                   java.io.File file)
        Deprecated.
        Use MavenProjectHelper.attachArtifact(..) instead.
      • writeModel

        @Deprecated
        public void writeModel​(java.io.Writer writer)
                        throws java.io.IOException
        Deprecated.
        Throws:
        java.io.IOException
      • writeOriginalModel

        @Deprecated
        public void writeOriginalModel​(java.io.Writer writer)
                                throws java.io.IOException
        Deprecated.
        Throws:
        java.io.IOException
      • replaceWithActiveArtifact

        @Deprecated
        public Artifact replaceWithActiveArtifact​(Artifact pluginArtifact)
        Deprecated.
      • 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