You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2008/02/14 07:08:10 UTC

svn commit: r627670 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/ maven-project/src/main/java/org/apache/maven/project/ maven-project/src/test/java/org/apache/maven/project/

Author: carlos
Date: Wed Feb 13 22:08:07 2008
New Revision: 627670

URL: http://svn.apache.org/viewvc?rev=627670&view=rev
Log:
[MNG-3400] MavenProject is not extensible

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StartForkedExecutionMojo.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StartForkedExecutionMojo.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StartForkedExecutionMojo.java?rev=627670&r1=627669&r2=627670&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StartForkedExecutionMojo.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/statemgmt/StartForkedExecutionMojo.java Wed Feb 13 22:08:07 2008
@@ -29,7 +29,7 @@
 
         if ( project != null )
         {
-            session.addForkedProject( new MavenProject( project ) );
+            session.addForkedProject( (MavenProject) project.clone() );
         }
     }
 

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?rev=627670&r1=627669&r2=627670&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java Wed Feb 13 22:08:07 2008
@@ -160,103 +160,107 @@
         model.setArtifactId( EMPTY_PROJECT_ARTIFACT_ID );
         model.setVersion( EMPTY_PROJECT_VERSION );
 
-        this.model = model;
+        this.setModel( model );
     }
 
     public MavenProject( Model model )
     {
-        this.model = model;
+        this.setModel( model );
     }
 
+    /**
+     * @deprecated use {@link #clone()}
+     */
     public MavenProject( MavenProject project )
     {
         // disown the parent
 
         // copy fields
-        file = project.file;
+        setFile( project.getFile() );
 
-        // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be sure!
-        if ( project.dependencyArtifacts != null )
+        // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be
+        // sure!
+        if ( project.getDependencyArtifacts() != null )
         {
-            dependencyArtifacts = Collections.unmodifiableSet( project.dependencyArtifacts );
+            setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) );
         }
 
-        if ( project.artifacts != null )
+        if ( project.getArtifacts() != null )
         {
-            artifacts = Collections.unmodifiableSet( project.artifacts );
+            setArtifacts( Collections.unmodifiableSet( project.getArtifacts() ) );
         }
 
-        if ( project.pluginArtifacts != null )
+        if ( project.getPluginArtifacts() != null )
         {
-            pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
+            setPluginArtifacts( Collections.unmodifiableSet( project.getPluginArtifacts() ) );
         }
 
-        if ( project.reportArtifacts != null )
+        if ( project.getReportArtifacts() != null )
         {
-            reportArtifacts = Collections.unmodifiableSet( project.reportArtifacts );
+            setReportArtifacts( Collections.unmodifiableSet( project.getReportArtifacts() ) );
         }
 
-        if ( project.extensionArtifacts != null )
+        if ( project.getExtensionArtifacts() != null )
         {
-            extensionArtifacts = Collections.unmodifiableSet( project.extensionArtifacts );
+            setExtensionArtifacts( Collections.unmodifiableSet( project.getExtensionArtifacts() ) );
         }
 
-        parentArtifact = project.parentArtifact;
+        setParentArtifact( ( project.getParentArtifact() ) );
 
-        if ( project.remoteArtifactRepositories != null )
+        if ( project.getRemoteArtifactRepositories() != null )
         {
-            remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
+            setRemoteArtifactRepositories( Collections.unmodifiableList( project.getRemoteArtifactRepositories() ) );
         }
 
-        if ( project.pluginArtifactRepositories != null )
+        if ( project.getPluginArtifactRepositories() != null )
         {
-            pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );
+            setPluginArtifactRepositories( ( Collections.unmodifiableList( project.getPluginArtifactRepositories() ) ) );
         }
 
-        if ( project.collectedProjects != null )
+        if ( project.getCollectedProjects() != null )
         {
-            collectedProjects = Collections.unmodifiableList( project.collectedProjects );
+            setCollectedProjects( ( Collections.unmodifiableList( project.getCollectedProjects() ) ) );
         }
 
-        if ( project.activeProfiles != null )
+        if ( project.getActiveProfiles() != null )
         {
-            activeProfiles = Collections.unmodifiableList( project.activeProfiles );
+            setActiveProfiles( ( Collections.unmodifiableList( project.getActiveProfiles() ) ) );
         }
 
         if ( project.getAttachedArtifacts() != null )
         {
             // clone properties modifyable by plugins in a forked lifecycle
-            attachedArtifacts = new ArrayList( project.getAttachedArtifacts() );
+            setAttachedArtifacts( new ArrayList( project.getAttachedArtifacts() ) );
         }
 
-        if ( project.compileSourceRoots != null )
+        if ( project.getCompileSourceRoots() != null )
         {
             // clone source roots
-            compileSourceRoots = new ArrayList( project.compileSourceRoots );
+            setCompileSourceRoots( ( new ArrayList( project.getCompileSourceRoots() ) ) );
         }
 
-        if ( project.testCompileSourceRoots != null )
+        if ( project.getTestCompileSourceRoots() != null )
         {
-            testCompileSourceRoots = new ArrayList( project.testCompileSourceRoots );
+            setTestCompileSourceRoots( ( new ArrayList( project.getTestCompileSourceRoots() ) ) );
         }
 
-        if ( project.scriptSourceRoots != null )
+        if ( project.getScriptSourceRoots() != null )
         {
-            scriptSourceRoots = new ArrayList( project.scriptSourceRoots );
+            setScriptSourceRoots( ( new ArrayList( project.getScriptSourceRoots() ) ) );
         }
 
-        model = ModelUtils.cloneModel( project.model );
+        setModel( ( ModelUtils.cloneModel( project.getModel() ) ) );
 
-        if ( project.originalModel != null )
+        if ( project.getOriginalModel() != null )
         {
-            originalModel = ModelUtils.cloneModel( project.originalModel );
+            setOriginalModel( ( ModelUtils.cloneModel( project.getOriginalModel() ) ) );
         }
 
-        executionRoot = project.executionRoot;
+        setExecutionRoot( project.isExecutionRoot() );
 
-        if ( project.artifact != null )
+        if ( project.getArtifact() != null )
         {
-            artifact = ArtifactUtils.copyArtifact( project.artifact );
+            setArtifact( ArtifactUtils.copyArtifact( project.getArtifact() ) );
         }
 
         if ( project.getManagedVersionMap() != null )
@@ -264,14 +268,14 @@
             setManagedVersionMap( new ManagedVersionMap( project.getManagedVersionMap() ) );
         }
 
-        if ( project.releaseArtifactRepository != null )
+        if ( project.getReleaseArtifactRepository() != null )
         {
-            releaseArtifactRepository = project.releaseArtifactRepository;
+            setReleaseArtifactRepository( project.getReleaseArtifactRepository() );
         }
 
-        if ( project.snapshotArtifactRepository != null )
+        if ( project.getSnapshotArtifactRepository() != null )
         {
-            snapshotArtifactRepository = project.snapshotArtifactRepository;
+            setSnapshotArtifactRepository( project.getSnapshotArtifactRepository() );
         }
     }
 
@@ -402,17 +406,17 @@
 
     public void setDependencies( List dependencies )
     {
-        model.setDependencies( dependencies );
+        getModel().setDependencies( dependencies );
     }
 
     public List getDependencies()
     {
-        return model.getDependencies();
+        return getModel().getDependencies();
     }
 
     public DependencyManagement getDependencyManagement()
     {
-        return model.getDependencyManagement();
+        return getModel().getDependencyManagement();
     }
 
     // ----------------------------------------------------------------------
@@ -426,9 +430,9 @@
             path = path.trim();
             if ( path.length() != 0 )
             {
-                if ( !compileSourceRoots.contains( path ) )
+                if ( !getCompileSourceRoots().contains( path ) )
                 {
-                    compileSourceRoots.add( path );
+                    getCompileSourceRoots().add( path );
                 }
             }
         }
@@ -441,9 +445,9 @@
             path = path.trim();
             if ( path.length() != 0 )
             {
-                if ( !scriptSourceRoots.contains( path ) )
+                if ( !getScriptSourceRoots().contains( path ) )
                 {
-                    scriptSourceRoots.add( path );
+                    getScriptSourceRoots().add( path );
                 }
             }
         }
@@ -456,9 +460,9 @@
             path = path.trim();
             if ( path.length() != 0 )
             {
-                if ( !testCompileSourceRoots.contains( path ) )
+                if ( !getTestCompileSourceRoots().contains( path ) )
                 {
-                    testCompileSourceRoots.add( path );
+                    getTestCompileSourceRoots().add( path );
                 }
             }
         }
@@ -820,31 +824,31 @@
 
     public void setModelVersion( String pomVersion )
     {
-        model.setModelVersion( pomVersion );
+        getModel().setModelVersion( pomVersion );
     }
 
     public String getModelVersion()
     {
-        return model.getModelVersion();
+        return getModel().getModelVersion();
     }
 
     public String getId()
     {
-        return model.getId();
+        return getModel().getId();
     }
 
     public void setGroupId( String groupId )
     {
-        model.setGroupId( groupId );
+        getModel().setGroupId( groupId );
     }
 
     public String getGroupId()
     {
-        String groupId = model.getGroupId();
+        String groupId = getModel().getGroupId();
 
-        if ( ( groupId == null ) && ( model.getParent() != null ) )
+        if ( ( groupId == null ) && ( getModel().getParent() != null ) )
         {
-            groupId = model.getParent().getGroupId();
+            groupId = getModel().getParent().getGroupId();
         }
 
         return groupId;
@@ -852,25 +856,25 @@
 
     public void setArtifactId( String artifactId )
     {
-        model.setArtifactId( artifactId );
+        getModel().setArtifactId( artifactId );
     }
 
     public String getArtifactId()
     {
-        return model.getArtifactId();
+        return getModel().getArtifactId();
     }
 
     public void setName( String name )
     {
-        model.setName( name );
+        getModel().setName( name );
     }
 
     public String getName()
     {
         // TODO: this should not be allowed to be null.
-        if ( model.getName() != null )
+        if ( getModel().getName() != null )
         {
-            return model.getName();
+            return getModel().getName();
         }
         else
         {
@@ -880,16 +884,16 @@
 
     public void setVersion( String version )
     {
-        model.setVersion( version );
+        getModel().setVersion( version );
     }
 
     public String getVersion()
     {
-        String version = model.getVersion();
+        String version = getModel().getVersion();
 
-        if ( ( version == null ) && ( model.getParent() != null ) )
+        if ( ( version == null ) && ( getModel().getParent() != null ) )
         {
-            version = model.getParent().getVersion();
+            version = getModel().getParent().getVersion();
         }
 
         return version;
@@ -897,147 +901,147 @@
 
     public String getPackaging()
     {
-        return model.getPackaging();
+        return getModel().getPackaging();
     }
 
     public void setPackaging( String packaging )
     {
-        model.setPackaging( packaging );
+        getModel().setPackaging( packaging );
     }
 
     public void setInceptionYear( String inceptionYear )
     {
-        model.setInceptionYear( inceptionYear );
+        getModel().setInceptionYear( inceptionYear );
     }
 
     public String getInceptionYear()
     {
-        return model.getInceptionYear();
+        return getModel().getInceptionYear();
     }
 
     public void setUrl( String url )
     {
-        model.setUrl( url );
+        getModel().setUrl( url );
     }
 
     public String getUrl()
     {
-        return model.getUrl();
+        return getModel().getUrl();
     }
 
     public Prerequisites getPrerequisites()
     {
-        return model.getPrerequisites();
+        return getModel().getPrerequisites();
     }
 
     public void setIssueManagement( IssueManagement issueManagement )
     {
-        model.setIssueManagement( issueManagement );
+        getModel().setIssueManagement( issueManagement );
     }
 
     public CiManagement getCiManagement()
     {
-        return model.getCiManagement();
+        return getModel().getCiManagement();
     }
 
     public void setCiManagement( CiManagement ciManagement )
     {
-        model.setCiManagement( ciManagement );
+        getModel().setCiManagement( ciManagement );
     }
 
     public IssueManagement getIssueManagement()
     {
-        return model.getIssueManagement();
+        return getModel().getIssueManagement();
     }
 
     public void setDistributionManagement( DistributionManagement distributionManagement )
     {
-        model.setDistributionManagement( distributionManagement );
+        getModel().setDistributionManagement( distributionManagement );
     }
 
     public DistributionManagement getDistributionManagement()
     {
-        return model.getDistributionManagement();
+        return getModel().getDistributionManagement();
     }
 
     public void setDescription( String description )
     {
-        model.setDescription( description );
+        getModel().setDescription( description );
     }
 
     public String getDescription()
     {
-        return model.getDescription();
+        return getModel().getDescription();
     }
 
     public void setOrganization( Organization organization )
     {
-        model.setOrganization( organization );
+        getModel().setOrganization( organization );
     }
 
     public Organization getOrganization()
     {
-        return model.getOrganization();
+        return getModel().getOrganization();
     }
 
     public void setScm( Scm scm )
     {
-        model.setScm( scm );
+        getModel().setScm( scm );
     }
 
     public Scm getScm()
     {
-        return model.getScm();
+        return getModel().getScm();
     }
 
     public void setMailingLists( List mailingLists )
     {
-        model.setMailingLists( mailingLists );
+        getModel().setMailingLists( mailingLists );
     }
 
     public List getMailingLists()
     {
-        return model.getMailingLists();
+        return getModel().getMailingLists();
     }
 
     public void addMailingList( MailingList mailingList )
     {
-        model.addMailingList( mailingList );
+        getModel().addMailingList( mailingList );
     }
 
     public void setDevelopers( List developers )
     {
-        model.setDevelopers( developers );
+        getModel().setDevelopers( developers );
     }
 
     public List getDevelopers()
     {
-        return model.getDevelopers();
+        return getModel().getDevelopers();
     }
 
     public void addDeveloper( Developer developer )
     {
-        model.addDeveloper( developer );
+        getModel().addDeveloper( developer );
     }
 
     public void setContributors( List contributors )
     {
-        model.setContributors( contributors );
+        getModel().setContributors( contributors );
     }
 
     public List getContributors()
     {
-        return model.getContributors();
+        return getModel().getContributors();
     }
 
     public void addContributor( Contributor contributor )
     {
-        model.addContributor( contributor );
+        getModel().addContributor( contributor );
     }
 
     public void setBuild( Build build )
     {
-        model.setBuild( build );
+        getModel().setBuild( build );
     }
 
     public Build getBuild()
@@ -1067,27 +1071,27 @@
 
     public void setReporting( Reporting reporting )
     {
-        model.setReporting( reporting );
+        getModel().setReporting( reporting );
     }
 
     public Reporting getReporting()
     {
-        return model.getReporting();
+        return getModel().getReporting();
     }
 
     public void setLicenses( List licenses )
     {
-        model.setLicenses( licenses );
+        getModel().setLicenses( licenses );
     }
 
     public List getLicenses()
     {
-        return model.getLicenses();
+        return getModel().getLicenses();
     }
 
     public void addLicense( License license )
     {
-        model.addLicense( license );
+        getModel().addLicense( license );
     }
 
     public void setArtifacts( Set artifacts )
@@ -1198,7 +1202,7 @@
 
     public List getRepositories()
     {
-        return model.getRepositories();
+        return getModel().getRepositories();
     }
 
     // ----------------------------------------------------------------------
@@ -1207,33 +1211,33 @@
 
     public List getReportPlugins()
     {
-        if ( model.getReporting() == null )
+        if ( getModel().getReporting() == null )
         {
             return null;
         }
-        return model.getReporting().getPlugins();
+        return getModel().getReporting().getPlugins();
 
     }
 
     public List getBuildPlugins()
     {
-        if ( model.getBuild() == null )
+        if ( getModel().getBuild() == null )
         {
             return null;
         }
-        return model.getBuild().getPlugins();
+        return getModel().getBuild().getPlugins();
     }
 
     public List getModules()
     {
-        return model.getModules();
+        return getModel().getModules();
     }
 
     public PluginManagement getPluginManagement()
     {
         PluginManagement pluginMgmt = null;
 
-        Build build = model.getBuild();
+        Build build = getModel().getBuild();
         if ( build != null )
         {
             pluginMgmt = build.getPluginManagement();
@@ -1244,13 +1248,13 @@
 
     private Build getModelBuild()
     {
-        Build build = model.getBuild();
+        Build build = getModel().getBuild();
 
         if ( build == null )
         {
             build = new Build();
 
-            model.setBuild( build );
+            getModel().setBuild( build );
         }
 
         return build;
@@ -1315,14 +1319,14 @@
 
     public ArtifactRepository getDistributionManagementArtifactRepository()
     {
-        return getArtifact().isSnapshot() && ( snapshotArtifactRepository != null ) ? snapshotArtifactRepository
-            : releaseArtifactRepository;
+        return getArtifact().isSnapshot() && ( getSnapshotArtifactRepository() != null ) ? getSnapshotArtifactRepository()
+            : getReleaseArtifactRepository();
     }
 
     public List getPluginRepositories()
     {
 //        return model.getPluginRepositories();
-        return model.getRepositories();
+        return getModel().getRepositories();
     }
 
     public void setActiveProfiles( List activeProfiles )
@@ -1623,6 +1627,42 @@
         return getBuild() != null ? getBuild().getDefaultGoal() : null;
     }
 
+
+    protected void setModel( Model model )
+    {
+        this.model = model;
+    }
+
+    protected void setAttachedArtifacts( List attachedArtifacts )
+    {
+        this.attachedArtifacts = attachedArtifacts;
+    }
+
+    protected void setCompileSourceRoots( List compileSourceRoots )
+    {
+        this.compileSourceRoots = compileSourceRoots;
+    }
+
+    protected void setTestCompileSourceRoots( List testCompileSourceRoots )
+    {
+        this.testCompileSourceRoots = testCompileSourceRoots;
+    }
+
+    protected void setScriptSourceRoots( List scriptSourceRoots )
+    {
+        this.scriptSourceRoots = scriptSourceRoots;
+    }
+
+    protected ArtifactRepository getReleaseArtifactRepository()
+    {
+        return releaseArtifactRepository;
+    }
+
+    protected ArtifactRepository getSnapshotArtifactRepository()
+    {
+        return snapshotArtifactRepository;
+    }
+
     public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
     {
         if ( ( getProjectReferences() != null ) && !getProjectReferences().isEmpty() )
@@ -1782,6 +1822,14 @@
         }
 
         return sb.toString();
+    }
+
+    /**
+     * @since 2.0.9
+     */
+    public Object clone()
+    {
+        return new MavenProject( this );
     }
 
 }

Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java?rev=627670&r1=627669&r2=627670&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/MavenProjectTest.java Wed Feb 13 22:08:07 2008
@@ -19,17 +19,15 @@
  * under the License.
  */
 
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.DependencyManagement;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.artifact.versioning.ManagedVersionMap;
-
 import java.io.File;
 import java.io.IOException;
-import java.util.Map;
-import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.artifact.versioning.ManagedVersionMap;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
 
 public class MavenProjectTest
     extends AbstractMavenProjectTestCase
@@ -90,20 +88,20 @@
                         + MavenProject.EMPTY_PROJECT_VERSION, project.getId() );
     }
 
-    public void testCopyConstructor()
+    public void testClone()
         throws Exception
     {
         File f = getFileForClasspathResource( "canonical-pom.xml" );
         MavenProject projectToClone = getProject( f );
 
-        MavenProject clonedProject = new MavenProject( projectToClone );
+        MavenProject clonedProject = (MavenProject) projectToClone.clone();
         assertEquals( "maven-core", clonedProject.getArtifactId() );
         Map clonedMap = clonedProject.getManagedVersionMap();
         assertNotNull( "ManagedVersionMap not copied", clonedMap );
         assertTrue( "ManagedVersionMap is not empty", clonedMap.isEmpty() );
     }
 
-    public void testCopyConstructorWithDependencyManagement()
+    public void testCloneWithDependencyManagement()
         throws Exception
     {
         File f = getFileForClasspathResource( "dependencyManagement-pom.xml" );
@@ -118,7 +116,7 @@
         assertNotNull( "No ManagedVersionMap", map );
         assertTrue( "ManagedVersionMap is empty", !map.isEmpty() );
 
-        MavenProject clonedProject = new MavenProject( projectToClone );
+        MavenProject clonedProject = (MavenProject) projectToClone.clone();
         assertEquals( "maven-core", clonedProject.getArtifactId() );
         Map clonedMap = clonedProject.getManagedVersionMap();
         assertNotNull( "ManagedVersionMap not copied", clonedMap );
@@ -147,13 +145,13 @@
         assertEquals( "..", pathAdjustment );
     }
     
-    public void testCopyConstructorWithDistributionManagement() throws Exception
+    public void testCloneWithDistributionManagement() throws Exception
     {
         
         File f = getFileForClasspathResource( "distributionManagement-pom.xml" );
         MavenProject projectToClone = getProject( f );
 
-        MavenProject clonedProject = new MavenProject( projectToClone );
+        MavenProject clonedProject = (MavenProject) projectToClone.clone();
         assertNotNull( "clonedProject - distributionManagement", clonedProject.getDistributionManagementArtifactRepository() );
     }
 }