You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2014/07/06 03:18:25 UTC

[1/2] MNG-5661: First step toward an immutable Maven Project. This removes all compentry from MavenProject. There's a note at the top of the class which describes the rest of the work.

Repository: maven
Updated Branches:
  refs/heads/master ce6fc6237 -> 6cf932094


http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
index 1b25db5..040d3a3 100644
--- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
@@ -19,11 +19,24 @@ package org.apache.maven.project;
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
 import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.artifact.InvalidRepositoryException;
+// remove once createArtifacts() is removed
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
@@ -54,42 +67,24 @@ import org.apache.maven.model.Scm;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.apache.maven.project.artifact.MavenMetadataSource;
-import org.apache.maven.repository.RepositorySystem;
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.eclipse.aether.graph.DependencyFilter;
 import org.eclipse.aether.repository.RemoteRepository;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
 /**
  * The concern of the project is provide runtime values based on the model.
  * <p/>
- * 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.
+ * 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.
  * <p/>
- * We need to leave the model intact because we don't want the following:
- * <ol>
- * <li>We don't want interpolated values being written back into the model.
- * <li>We don't want inherited values being written back into the model.
- * </ol>
+ * <p>
+ * 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).
+ * </p>
  */
 public class MavenProject
     implements Cloneable
@@ -100,8 +95,6 @@ public class MavenProject
 
     public static final String EMPTY_PROJECT_VERSION = "0";
 
-    private static final MavenProject ERROR_BUILDING_PARENT = new MavenProject();
-
     private Model model;
 
     private MavenProject parent;
@@ -171,14 +164,6 @@ public class MavenProject
 
     private boolean executionRoot;
 
-    private Map<String, String> moduleAdjustments;
-
-    private ProjectBuilder mavenProjectBuilder;
-
-    private ProjectBuildingRequest projectBuilderConfiguration;
-
-    private RepositorySystem repositorySystem;
-    
     private File parentFile;
 
     private Map<String, Object> context;
@@ -189,8 +174,6 @@ public class MavenProject
 
     private final Set<String> lifecyclePhases = Collections.synchronizedSet( new LinkedHashSet<String>() );
 
-    private Logger logger;
-
     public MavenProject()
     {
         Model model = new Model();
@@ -207,25 +190,10 @@ public class MavenProject
         setModel( model );
     }
 
-    /**
-     * @deprecated use {@link #clone()} so subclasses can provide a copy of the same class
-     */
-    @Deprecated
     public MavenProject( MavenProject project )
     {
-        repositorySystem = project.repositorySystem;
-        logger = project.logger;
-        mavenProjectBuilder = project.mavenProjectBuilder;
-        projectBuilderConfiguration = project.projectBuilderConfiguration;
         deepCopy( project );
     }
-    
-    @Deprecated
-    public MavenProject( Model model, RepositorySystem repositorySystem )
-    {        
-        this.repositorySystem = repositorySystem;
-        setModel( model );
-    }
 
     public File getParentFile()
     {
@@ -237,92 +205,6 @@ public class MavenProject
         this.parentFile = parentFile;
     }
 
-    /**
-     * Constructor
-     * 
-     * @param repositorySystem - may not be null
-     * @param mavenProjectBuilder
-     * @param projectBuilderConfiguration
-     * @throws InvalidRepositoryException
-     */
-    MavenProject( RepositorySystem repositorySystem, ProjectBuilder mavenProjectBuilder,
-                  ProjectBuildingRequest projectBuilderConfiguration, Logger logger )
-    {
-        if ( repositorySystem == null )
-        {
-            throw new IllegalArgumentException( "mavenTools: null" );
-        }
-
-        this.mavenProjectBuilder = mavenProjectBuilder;
-        this.projectBuilderConfiguration = projectBuilderConfiguration;
-        this.repositorySystem = repositorySystem;
-        this.logger = logger;
-    }
-
-    @Deprecated
-    public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter )
-        throws InvalidDependencyVersionException
-    {
-        return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope, filter, this );
-    }
-
-    // TODO: Find a way to use <relativePath/> here...it's tricky, because the moduleProject
-    // usually doesn't have a file associated with it yet.
-    public String getModulePathAdjustment( MavenProject moduleProject )
-        throws IOException
-    {
-        // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
-        // is coming from the repository??
-        String module = moduleProject.getArtifactId();
-
-        File moduleFile = moduleProject.getFile();
-
-        if ( moduleFile != null )
-        {
-            File moduleDir = moduleFile.getCanonicalFile().getParentFile();
-
-            module = moduleDir.getName();
-        }
-
-        if ( moduleAdjustments == null )
-        {
-            moduleAdjustments = new HashMap<String, String>();
-
-            List<String> modules = getModules();
-            if ( modules != null )
-            {
-                for ( String modulePath : modules )
-                {
-                    String moduleName = modulePath;
-
-                    if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
-                    {
-                        moduleName = moduleName.substring( 0, moduleName.length() - 1 );
-                    }
-
-                    int lastSlash = moduleName.lastIndexOf( '/' );
-
-                    if ( lastSlash < 0 )
-                    {
-                        lastSlash = moduleName.lastIndexOf( '\\' );
-                    }
-
-                    String adjustment = null;
-
-                    if ( lastSlash > -1 )
-                    {
-                        moduleName = moduleName.substring( lastSlash + 1 );
-                        adjustment = modulePath.substring( 0, lastSlash );
-                    }
-
-                    moduleAdjustments.put( moduleName, adjustment );
-                }
-            }
-        }
-
-        return moduleAdjustments.get( module );
-    }
-
     // ----------------------------------------------------------------------
     // Accessors
     // ----------------------------------------------------------------------
@@ -337,7 +219,7 @@ public class MavenProject
         this.artifact = artifact;
     }
 
-    //@todo I would like to get rid of this. jvz.
+    // @todo I would like to get rid of this. jvz.
     public Model getModel()
     {
         return model;
@@ -345,95 +227,19 @@ public class MavenProject
 
     /**
      * Returns the project corresponding to a declared parent.
+     * 
      * @return the parent, or null if no parent is declared or there was an error building it
      */
     public MavenProject getParent()
     {
-        if ( parent == null )
-        {
-            /*
-             * TODO: This is suboptimal. Without a cache in the project builder, rebuilding the parent chain currently
-             * causes O(n^2) parser invocations for an inheritance hierarchy of depth n.
-             */
-            if ( parentFile != null )
-            {
-                checkProjectBuildingRequest();
-                ProjectBuildingRequest request = new DefaultProjectBuildingRequest( projectBuilderConfiguration );
-                request.setRemoteRepositories( getRemoteArtifactRepositories() );
-
-                try
-                {
-                    parent = mavenProjectBuilder.build( parentFile, request ).getProject();
-                }
-                catch ( ProjectBuildingException e )
-                {
-                    if ( logger != null )
-                    {
-                        logger.error( "Failed to build parent project for " + getId(), e );
-                    }
-                    parent = ERROR_BUILDING_PARENT;
-                }
-            }
-            else if ( model.getParent() != null )
-            {
-                checkProjectBuildingRequest();
-                ProjectBuildingRequest request = new DefaultProjectBuildingRequest( projectBuilderConfiguration );
-                request.setRemoteRepositories( getRemoteArtifactRepositories() );
-                request.setResolveVersionRanges( true );
-
-                try
-                {
-                    parent = mavenProjectBuilder.build( repositorySystem.createProjectArtifact(
-                        model.getParent().getGroupId(), model.getParent().getArtifactId(),
-                        model.getParent().getVersion() ), request ).getProject();
-
-                    if ( !model.getParent().getVersion().equals( parent.getVersion() ) )
-                    {
-                        if ( model.getVersion() == null )
-                        {
-                            if ( logger != null )
-                            {
-                                logger.error( "Failed to build parent project for " + getId()
-                                                  + ": Parent version must be a constant" );
-
-                            }
-                            parent = ERROR_BUILDING_PARENT;
-                        }
-                        else
-                        {
-                            if ( model.getVersion().indexOf( "${" ) > -1 )
-                            {
-                                if ( logger != null )
-                                {
-                                    logger.error( "Failed to build parent project for " + getId() + ": The version '"
-                                                      + model.getParent().getVersion() + "' must be a constant" );
-
-                                }
-                                parent = ERROR_BUILDING_PARENT;
-                            }
-                        }
-
-                        // MNG-2199: What else to check here ?
-                    }
-                }
-                catch ( ProjectBuildingException e )
-                {
-                    if ( logger != null )
-                    {
-                        logger.error( "Failed to build parent project for " + getId(), e );
-                    }
-                    parent = ERROR_BUILDING_PARENT;
-                }
-            }
-        }
-        return parent == ERROR_BUILDING_PARENT ? null : parent;
+        return parent;
     }
 
     public void setParent( MavenProject parent )
     {
         this.parent = parent;
     }
-    
+
     public boolean hasParent()
     {
         return getParent() != null;
@@ -511,18 +317,6 @@ public class MavenProject
         addPath( getCompileSourceRoots(), path );
     }
 
-    public void addScriptSourceRoot( String path )
-    {
-        if ( path != null )
-        {
-            path = path.trim();
-            if ( path.length() != 0 && !getScriptSourceRoots().contains( path ) )
-            {
-                getScriptSourceRoots().add( path );
-            }
-        }
-    }
-
     public void addTestCompileSourceRoot( String path )
     {
         addPath( getTestCompileSourceRoots(), path );
@@ -533,11 +327,6 @@ public class MavenProject
         return compileSourceRoots;
     }
 
-    public List<String> getScriptSourceRoots()
-    {
-        return scriptSourceRoots;
-    }
-
     public List<String> getTestCompileSourceRoots()
     {
         return testCompileSourceRoots;
@@ -555,69 +344,22 @@ public class MavenProject
         }
 
         for ( Artifact a : getArtifacts() )
-        {                        
-            if ( a.getArtifactHandler().isAddedToClasspath()
-            // TODO: let the scope handler deal with this
-                && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) )
-            {
-                addArtifactPath( a, list );
-            }
-        }
-
-        return list;
-    }
-
-    @Deprecated
-    public List<Artifact> getCompileArtifacts()
-    {
-        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
-
-        for ( Artifact a : getArtifacts() )
         {
-            // TODO: classpath check doesn't belong here - that's the other method
-            if ( a.getArtifactHandler().isAddedToClasspath()
-            // TODO: let the scope handler deal with this
-                && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) )
+            if ( a.getArtifactHandler().isAddedToClasspath() )
             {
-                list.add( a );
+                // TODO: let the scope handler deal with this
+                if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
+                    || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+                {
+                    addArtifactPath( a, list );
+                }
             }
         }
-        return list;
-    }
-
-    @Deprecated
-    public List<Dependency> getCompileDependencies()
-    {
-        Set<Artifact> artifacts = getArtifacts();
-
-        if ( ( artifacts == null ) || artifacts.isEmpty() )
-        {
-            return Collections.emptyList();
-        }
-
-        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
-
-        for ( Artifact a : getArtifacts()  )
-        {
-            // TODO: let the scope handler deal with this
-            if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
-            {
-                Dependency dependency = new Dependency();
-
-                dependency.setArtifactId( a.getArtifactId() );
-                dependency.setGroupId( a.getGroupId() );
-                dependency.setVersion( a.getVersion() );
-                dependency.setScope( a.getScope() );
-                dependency.setType( a.getType() );
-                dependency.setClassifier( a.getClassifier() );
 
-                list.add( dependency );
-            }
-        }
         return list;
     }
 
-    //TODO: this checking for file == null happens because the resolver has been confused about the root
+    // TODO: this checking for file == null happens because the resolver has been confused about the root
     // artifact or not. things like the stupid dummy artifact coming from surefire.
     public List<String> getTestClasspathElements()
         throws DependencyResolutionRequiredException
@@ -635,11 +377,11 @@ public class MavenProject
         {
             list.add( d );
         }
-        
+
         for ( Artifact a : getArtifacts() )
-        {            
+        {
             if ( a.getArtifactHandler().isAddedToClasspath() )
-            {                
+            {
                 addArtifactPath( a, list );
             }
         }
@@ -647,204 +389,37 @@ public class MavenProject
         return list;
     }
 
-    @Deprecated
-    public List<Artifact> getTestArtifacts()
+    public List<String> getRuntimeClasspathElements()
+        throws DependencyResolutionRequiredException
     {
-        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
+        List<String> list = new ArrayList<String>( getArtifacts().size() + 1 );
+
+        String d = getBuild().getOutputDirectory();
+        if ( d != null )
+        {
+            list.add( d );
+        }
 
         for ( Artifact a : getArtifacts() )
         {
-            // TODO: classpath check doesn't belong here - that's the other method
-            if ( a.getArtifactHandler().isAddedToClasspath() )
+            if ( a.getArtifactHandler().isAddedToClasspath()
+            // TODO: let the scope handler deal with this
+                && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
             {
-                list.add( a );
+                addArtifactPath( a, list );
             }
         }
         return list;
     }
 
-    @Deprecated
-    public List<Dependency> getTestDependencies()
-    {
-        Set<Artifact> artifacts = getArtifacts();
-
-        if ( ( artifacts == null ) || artifacts.isEmpty() )
-        {
-            return Collections.emptyList();
-        }
+    // ----------------------------------------------------------------------
+    // Delegate to the model
+    // ----------------------------------------------------------------------
 
-        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
-
-        for ( Artifact a : getArtifacts()  )
-        {
-            Dependency dependency = new Dependency();
-
-            dependency.setArtifactId( a.getArtifactId() );
-            dependency.setGroupId( a.getGroupId() );
-            dependency.setVersion( a.getVersion() );
-            dependency.setScope( a.getScope() );
-            dependency.setType( a.getType() );
-            dependency.setClassifier( a.getClassifier() );
-
-            list.add( dependency );
-        }
-        return list;
-    }
-
-    public List<String> getRuntimeClasspathElements()
-        throws DependencyResolutionRequiredException
-    {
-        List<String> list = new ArrayList<String>( getArtifacts().size() + 1 );
-
-        String d = getBuild().getOutputDirectory();
-        if ( d != null )
-        {
-            list.add( d );
-        }
-
-        for ( Artifact a : getArtifacts() )
-        {
-            if ( a.getArtifactHandler().isAddedToClasspath()
-            // TODO: let the scope handler deal with this
-                && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
-            {
-                addArtifactPath( a, list );
-            }
-        }
-        return list;
-    }
-
-    @Deprecated
-    public List<Artifact> getRuntimeArtifacts()
-    {
-        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
-
-        for ( Artifact a : getArtifacts()  )
-        {
-            // TODO: classpath check doesn't belong here - that's the other method
-            if ( a.getArtifactHandler().isAddedToClasspath()
-            // TODO: let the scope handler deal with this
-                && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
-            {
-                list.add( a );
-            }
-        }
-        return list;
-    }
-
-    @Deprecated
-    public List<Dependency> getRuntimeDependencies()
-    {
-        Set<Artifact> artifacts = getArtifacts();
-
-        if ( ( artifacts == null ) || artifacts.isEmpty() )
-        {
-            return Collections.emptyList();
-        }
-
-        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
-
-        for ( Artifact a : getArtifacts()  )
-        {
-            // TODO: let the scope handler deal with this
-            if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
-            {
-                Dependency dependency = new Dependency();
-
-                dependency.setArtifactId( a.getArtifactId() );
-                dependency.setGroupId( a.getGroupId() );
-                dependency.setVersion( a.getVersion() );
-                dependency.setScope( a.getScope() );
-                dependency.setType( a.getType() );
-                dependency.setClassifier( a.getClassifier() );
-
-                list.add( dependency );
-            }
-        }
-        return list;
-    }
-
-    public List<String> getSystemClasspathElements()
-        throws DependencyResolutionRequiredException
-    {
-        List<String> list = new ArrayList<String>( getArtifacts().size() );
-
-        String d = getBuild().getOutputDirectory();
-        if ( d != null )
-        {
-            list.add( d );
-        }
-
-        for ( Artifact a : getArtifacts() )
-        {
-            if ( a.getArtifactHandler().isAddedToClasspath()
-            // TODO: let the scope handler deal with this
-                && Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
-            {
-                addArtifactPath( a, list );
-            }
-        }
-        return list;
-    }
-
-    @Deprecated
-    public List<Artifact> getSystemArtifacts()
-    {
-        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
-
-        for ( Artifact a : getArtifacts()  )
-        {
-            // TODO: classpath check doesn't belong here - that's the other method
-            if ( a.getArtifactHandler().isAddedToClasspath()
-            // TODO: let the scope handler deal with this
-                && Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
-            {
-                list.add( a );
-            }
-        }
-        return list;
-    }
-
-    @Deprecated
-    public List<Dependency> getSystemDependencies()
-    {
-        Set<Artifact> artifacts = getArtifacts();
-
-        if ( ( artifacts == null ) || artifacts.isEmpty() )
-        {
-            return Collections.emptyList();
-        }
-
-        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
-
-        for ( Artifact a : getArtifacts()  )
-        {
-            // TODO: let the scope handler deal with this
-            if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
-            {
-                Dependency dependency = new Dependency();
-
-                dependency.setArtifactId( a.getArtifactId() );
-                dependency.setGroupId( a.getGroupId() );
-                dependency.setVersion( a.getVersion() );
-                dependency.setScope( a.getScope() );
-                dependency.setType( a.getType() );
-                dependency.setClassifier( a.getClassifier() );
-
-                list.add( dependency );
-            }
-        }
-        return list;
-    }
-
-    // ----------------------------------------------------------------------
-    // Delegate to the model
-    // ----------------------------------------------------------------------
-
-    public void setModelVersion( String pomVersion )
-    {
-        getModel().setModelVersion( pomVersion );
-    }
+    public void setModelVersion( String pomVersion )
+    {
+        getModel().setModelVersion( pomVersion );
+    }
 
     public String getModelVersion()
     {
@@ -1088,18 +663,6 @@ public class MavenProject
         getBuild().addTestResource( testResource );
     }
 
-    @Deprecated
-    public void setReporting( Reporting reporting )
-    {
-        getModel().setReporting( reporting );
-    }
-
-    @Deprecated
-    public Reporting getReporting()
-    {
-        return getModel().getReporting();
-    }
-
     public void setLicenses( List<License> licenses )
     {
         getModel().setLicenses( licenses );
@@ -1124,9 +687,9 @@ public class MavenProject
     }
 
     /**
-     * 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.
+     * 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.
      * 
      * @return {@link Set} &lt; {@link Artifact} >
      * @see #getDependencyArtifacts() to get only direct dependencies
@@ -1172,28 +735,6 @@ public class MavenProject
 
     public Set<Artifact> getPluginArtifacts()
     {
-        if ( pluginArtifacts != null )
-        {
-            return pluginArtifacts;
-        }
-
-        pluginArtifacts = new HashSet<Artifact>();
-
-        if ( repositorySystem != null )
-        {
-            for ( Plugin p : getBuildPlugins() )
-            {
-                Artifact artifact = repositorySystem.createPluginArtifact( p );
-
-                if ( artifact != null )
-                {
-                    pluginArtifacts.add( artifact );
-                }
-            }
-        }
-
-        pluginArtifactMap = null;
-
         return pluginArtifacts;
     }
 
@@ -1207,178 +748,57 @@ public class MavenProject
         return pluginArtifactMap;
     }
 
-    @Deprecated
-    public void setReportArtifacts( Set<Artifact> reportArtifacts )
+    public void setParentArtifact( Artifact parentArtifact )
     {
-        this.reportArtifacts = reportArtifacts;
+        this.parentArtifact = parentArtifact;
+    }
 
-        reportArtifactMap = null;
+    public Artifact getParentArtifact()
+    {
+        return parentArtifact;
     }
 
-    @Deprecated
-    public Set<Artifact> getReportArtifacts()
+    public List<Repository> getRepositories()
     {
-        if ( reportArtifacts != null )
-        {
-            return reportArtifacts;
-        }
+        return getModel().getRepositories();
+    }
 
-        reportArtifacts = new HashSet<Artifact>();
+    // ----------------------------------------------------------------------
+    // Plugins
+    // ----------------------------------------------------------------------
 
-        if ( repositorySystem != null )
+    public List<Plugin> getBuildPlugins()
+    {
+        if ( getModel().getBuild() == null )
         {
-            for ( ReportPlugin p : getReportPlugins() )
-            {
-                Plugin pp = new Plugin();
-                pp.setGroupId( p.getGroupId() );
-                pp.setArtifactId( p.getArtifactId() );
-                pp.setVersion( p.getVersion() );
-
-                Artifact artifact = repositorySystem.createPluginArtifact( pp );
-
-                if ( artifact != null )
-                {
-                    reportArtifacts.add( artifact );
-                }
-            }
+            return Collections.emptyList();
         }
+        return getModel().getBuild().getPlugins();
+    }
 
-        reportArtifactMap = null;
-
-        return reportArtifacts;
+    public List<String> getModules()
+    {
+        return getModel().getModules();
     }
 
-    @Deprecated
-    public Map<String, Artifact> getReportArtifactMap()
+    public PluginManagement getPluginManagement()
     {
-        if ( reportArtifactMap == null )
+        PluginManagement pluginMgmt = null;
+
+        Build build = getModel().getBuild();
+        if ( build != null )
         {
-            reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
+            pluginMgmt = build.getPluginManagement();
         }
 
-        return reportArtifactMap;
+        return pluginMgmt;
     }
 
-    public void setExtensionArtifacts( Set<Artifact> extensionArtifacts )
+    private Build getModelBuild()
     {
-        this.extensionArtifacts = extensionArtifacts;
-
-        extensionArtifactMap = null;
-    }
+        Build build = getModel().getBuild();
 
-    public Set<Artifact> getExtensionArtifacts()
-    {
-        if ( extensionArtifacts != null )
-        {
-            return extensionArtifacts;
-        }
-        extensionArtifacts = new HashSet<Artifact>();
-        List<Extension> extensions = getBuildExtensions();
-        if ( extensions != null )
-        {
-            for ( Extension ext : extensions )
-            {
-                String version;
-                if ( StringUtils.isEmpty( ext.getVersion() ) )
-                {
-                    version = "RELEASE";
-                }
-                else
-                {
-                    version = ext.getVersion();
-                }
-
-                Artifact artifact =
-                    repositorySystem.createArtifact( ext.getGroupId(), ext.getArtifactId(), version, null, "jar" );
-
-                if ( artifact != null )
-                {
-                    extensionArtifacts.add( artifact );
-                }
-            }
-        }
-        extensionArtifactMap = null;
-        return extensionArtifacts;
-    }
-
-    public Map<String, Artifact> getExtensionArtifactMap()
-    {
-        if ( extensionArtifactMap == null )
-        {
-            extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() );
-        }
-
-        return extensionArtifactMap;
-    }
-
-    public void setParentArtifact( Artifact parentArtifact )
-    {
-        this.parentArtifact = parentArtifact;
-    }
-
-    public Artifact getParentArtifact()
-    {
-        if ( parentArtifact == null && getParent() != null )
-        {
-            parentArtifact = repositorySystem.createProjectArtifact(
-                getParent().getGroupId(), getParent().getArtifactId(), getParent().getVersion() );
-
-        }
-        return parentArtifact;
-    }
-
-    public List<Repository> getRepositories()
-    {
-        return getModel().getRepositories();
-    }
-
-    // ----------------------------------------------------------------------
-    // Plugins
-    // ----------------------------------------------------------------------
-
-    @Deprecated
-    public List<ReportPlugin> getReportPlugins()
-    {
-        if ( getModel().getReporting() == null )
-        {
-            return Collections.emptyList();
-        }
-        return getModel().getReporting().getPlugins();
-
-    }
-
-    public List<Plugin> getBuildPlugins()
-    {
-        if ( getModel().getBuild() == null )
-        {
-            return Collections.emptyList();
-        }
-        return getModel().getBuild().getPlugins();
-    }
-
-    public List<String> getModules()
-    {
-        return getModel().getModules();
-    }
-
-    public PluginManagement getPluginManagement()
-    {
-        PluginManagement pluginMgmt = null;
-
-        Build build = getModel().getBuild();
-        if ( build != null )
-        {
-            pluginMgmt = build.getPluginManagement();
-        }
-
-        return pluginMgmt;
-    }
-
-    private Build getModelBuild()
-    {
-        Build build = getModel().getBuild();
-
-        if ( build == null )
+        if ( build == null )
         {
             build = new Build();
 
@@ -1411,8 +831,8 @@ public class MavenProject
     }
 
     /**
-     * @return a list of ArtifactRepository objects constructed from the Repository objects returned
-     *         by getPluginRepositories.
+     * @return a list of ArtifactRepository objects constructed from the Repository objects returned by
+     *         getPluginRepositories.
      */
     public List<ArtifactRepository> getPluginArtifactRepositories()
     {
@@ -1426,7 +846,8 @@ public class MavenProject
 
     public ArtifactRepository getDistributionManagementArtifactRepository()
     {
-        return getArtifact().isSnapshot() && ( getSnapshotArtifactRepository() != null ) ? getSnapshotArtifactRepository() : getReleaseArtifactRepository();
+        return getArtifact().isSnapshot() && ( getSnapshotArtifactRepository() != null ) ? getSnapshotArtifactRepository()
+                        : getReleaseArtifactRepository();
     }
 
     public List<Repository> getPluginRepositories()
@@ -1468,10 +889,10 @@ public class MavenProject
 
     /**
      * 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 {@code
-     * settings.xml}. The profile identifiers are grouped by the identifier of their source, e.g. {@code
-     * <groupId>:<artifactId>:<version>} for a POM profile or {@code external} for profiles from the {@code
-     * settings.xml}.
+     * profiles from the project's POM and all its parent POMs as well as from external sources like the
+     * {@code settings.xml}. The profile identifiers are grouped by the identifier of their source, e.g.
+     * {@code <groupId>:<artifactId>:<version>} for a POM profile or {@code external} for profiles from the
+     * {@code settings.xml}.
      * 
      * @return The identifiers of all injected profiles, indexed by the source from which the profiles originated, never
      *         {@code null}.
@@ -1481,48 +902,19 @@ public class MavenProject
         return this.injectedProfileIds;
     }
 
-    private String logStringForArtifactFile( Artifact a )
-    {
-        if ( a.getFile() != null )
-        {
-            return a.getFile().getAbsolutePath();
-        }
-        else
-        {
-            return "(no path)";
-        }
-    }
-
     /**
-     * Add or replace an artifact.
-     * 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
+     * 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.
+     * 
      * @param artifact the artifact to add or replace.
      * @throws DuplicateArtifactAttachmentException
      */
     public void addAttachedArtifact( Artifact artifact )
         throws DuplicateArtifactAttachmentException
     {
-        List<Artifact> attachedArtifacts = getAttachedArtifacts();
-        for ( int ax = 0; ax < attachedArtifacts.size(); ax++ )
-        {
-            Artifact a = attachedArtifacts.get( ax );
-            if ( a.equals( artifact ) )
-            {
-                if ( logger != null )
-                {
-                    logger.debug( String.format( "Replacing attached artifact %s. Old path %s, new path %s. ",
-                                                 a,
-                                                 logStringForArtifactFile( a ),
-                                                 logStringForArtifactFile( artifact ) ) );
-                }
-                attachedArtifacts.set( ax, artifact );
-                return;
-            }
-        }
-
         getAttachedArtifacts().add( artifact );
     }
 
@@ -1571,52 +963,6 @@ public class MavenProject
         return dom;
     }
 
-    @Deprecated
-    public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId )
-    {
-        Xpp3Dom dom = null;
-
-        // ----------------------------------------------------------------------
-        // I would like to be able to lookup the Mojo object using a key but
-        // we have a limitation in modello that will be remedied shortly. So
-        // for now I have to iterate through and see what we have.
-        // ----------------------------------------------------------------------
-
-        if ( getReportPlugins() != null )
-        {
-            for ( ReportPlugin plugin : getReportPlugins() )
-            {
-                if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
-                {
-                    dom = (Xpp3Dom) plugin.getConfiguration();
-
-                    if ( reportSetId != null )
-                    {
-                        ReportSet reportSet = plugin.getReportSetsAsMap().get( reportSetId );
-                        if ( reportSet != null )
-                        {
-                            Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
-                            if ( executionConfiguration != null )
-                            {
-                                Xpp3Dom newDom = new Xpp3Dom( executionConfiguration );
-                                dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
-                            }
-                        }
-                    }
-                    break;
-                }
-            }
-        }
-
-        if ( dom != null )
-        {
-            // make a copy so the original in the POM doesn't get messed with
-            dom = new Xpp3Dom( dom );
-        }
-
-        return dom;
-    }
-
     public MavenProject getExecutionProject()
     {
         return ( executionProject == null ? this : executionProject );
@@ -1680,38 +1026,6 @@ public class MavenProject
 
     public Map<String, Artifact> getManagedVersionMap()
     {
-        if ( managedVersionMap != null )
-        {
-            return managedVersionMap;
-        }
-
-        Map<String, Artifact> map = null;
-        if ( repositorySystem != null )
-        {
-
-            List<Dependency> deps;
-            DependencyManagement dependencyManagement = getDependencyManagement();
-            if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && ( deps.size() > 0 ) )
-            {
-                map = new HashMap<String, Artifact>();
-                for ( Dependency d : dependencyManagement.getDependencies() )
-                {
-                    Artifact artifact = repositorySystem.createDependencyArtifact( d );
-
-                    if ( artifact == null )
-                    {
-                        map = Collections.emptyMap();
-                    }
-
-                    map.put( d.getManagementKey(), artifact );
-                }
-            }
-            else
-            {
-                map = Collections.emptyMap();
-            }
-        }
-        managedVersionMap = map;
         return managedVersionMap;
     }
 
@@ -1729,8 +1043,7 @@ public class MavenProject
 
         MavenProject that = (MavenProject) other;
 
-        return eq( getArtifactId(), that.getArtifactId() )
-            && eq( getGroupId(), that.getGroupId() )
+        return eq( getArtifactId(), that.getArtifactId() ) && eq( getGroupId(), that.getGroupId() )
             && eq( getVersion(), that.getVersion() );
     }
 
@@ -1764,15 +1077,8 @@ public class MavenProject
 
     public void addProjectReference( MavenProject project )
     {
-        projectReferences.put( getProjectReferenceId( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
-    }
-
-    /**
-     * @deprecated Use MavenProjectHelper.attachArtifact(..) instead.
-     */
-    @Deprecated
-    public void attachArtifact( String type, String classifier, File file )
-    {
+        projectReferences.put( getProjectReferenceId( project.getGroupId(), project.getArtifactId(),
+                                                      project.getVersion() ), project );
     }
 
     public Properties getProperties()
@@ -1831,35 +1137,13 @@ public class MavenProject
         }
         catch ( NullPointerException e )
         {
-            //don't log it.
+            // don't log it.
         }
 
         return sb.toString();
     }
 
     /**
-     * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
-     */
-    @Deprecated
-    public void writeModel( Writer writer )
-        throws IOException
-    {
-        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
-        pomWriter.write( writer, getModel() );
-    }
-
-    /**
-     * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
-     */
-    @Deprecated
-    public void writeOriginalModel( Writer writer )
-        throws IOException
-    {
-        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
-        pomWriter.write( writer, getOriginalModel() );
-    }
-
-    /**
      * @throws CloneNotSupportedException
      * @since 2.0.9
      */
@@ -1901,65 +1185,16 @@ public class MavenProject
         this.testCompileSourceRoots = testCompileSourceRoots;
     }
 
-    protected void setScriptSourceRoots( List<String> scriptSourceRoots )
-    {
-        this.scriptSourceRoots = scriptSourceRoots;
-    }
-
     protected ArtifactRepository getReleaseArtifactRepository()
     {
-        if ( releaseArtifactRepository == null && getDistributionManagement() != null
-            && getDistributionManagement().getRepository() != null )
-        {
-            checkProjectBuildingRequest();
-            try
-            {
-                ArtifactRepository repo =
-                    repositorySystem.buildArtifactRepository( getDistributionManagement().getRepository() );
-                repositorySystem.injectProxy( projectBuilderConfiguration.getRepositorySession(), Arrays.asList( repo ) );
-                repositorySystem.injectAuthentication( projectBuilderConfiguration.getRepositorySession(),
-                                                       Arrays.asList( repo ) );
-                setReleaseArtifactRepository( repo );
-            }
-            catch ( InvalidRepositoryException e )
-            {
-                throw new IllegalStateException( "Failed to create release distribution repository for " + getId(), e );
-            }
-        }
-
         return releaseArtifactRepository;
     }
 
     protected ArtifactRepository getSnapshotArtifactRepository()
     {
-        if ( snapshotArtifactRepository == null && getDistributionManagement() != null
-            && getDistributionManagement().getSnapshotRepository() != null )
-        {
-            checkProjectBuildingRequest();
-            try
-            {
-                ArtifactRepository repo =
-                    repositorySystem.buildArtifactRepository( getDistributionManagement().getSnapshotRepository() );
-                repositorySystem.injectProxy( projectBuilderConfiguration.getRepositorySession(), Arrays.asList( repo ) );
-                repositorySystem.injectAuthentication( projectBuilderConfiguration.getRepositorySession(),
-                                                       Arrays.asList( repo ) );
-                setSnapshotArtifactRepository( repo );
-            }
-            catch ( InvalidRepositoryException e )
-            {
-                throw new IllegalStateException( "Failed to create snapshot distribution repository for " + getId(), e );
-            }
-        }
-
         return snapshotArtifactRepository;
     }
 
-    @Deprecated
-    public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
-    {
-        return pluginArtifact;
-    }
-
     private void deepCopy( MavenProject project )
     {
         // disown the parent
@@ -2080,12 +1315,9 @@ public class MavenProject
     }
 
     /**
-     * Sets the value of the context value of this project identified
-     * by the given key. If the supplied value is <code>null</code>,
-     * the context value is removed from this project.
-     * 
-     * Context values are intended to allow core extensions to associate
-     * derived state with project instances. 
+     * Sets the value of the context value of this project identified by the given key. If the supplied value is
+     * <code>null</code>, the context value is removed from this project. Context values are intended to allow core
+     * extensions to associate derived state with project instances.
      */
     public void setContextValue( String key, Object value )
     {
@@ -2104,8 +1336,7 @@ public class MavenProject
     }
 
     /**
-     * Returns context value of this project associated with the given key 
-     * or null if this project has no such value. 
+     * Returns context value of this project associated with the given key or null if this project has no such value.
      */
     public Object getContextValue( String key )
     {
@@ -2221,36 +1452,518 @@ public class MavenProject
         lifecyclePhases.add( lifecyclePhase );
     }
 
-    /**
-     * Gets the project building request from which this project instance was created. <strong>Warning:</strong> This is
-     * an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
-     * 
-     * @return The project building request or {@code null}.
-     * @since 2.1
-     */
-    public ProjectBuildingRequest getProjectBuildingRequest()
-    {
-        return projectBuilderConfiguration;
-    }
+    // --------------------------------------------------------------------------------------------------------------------
+    //
+    //
+    // D E P R E C A T E D
+    //
+    //
+    // --------------------------------------------------------------------------------------------------------------------
+    //
+    // Everything below will be removed for Maven 4.0.0
+    //
+    // --------------------------------------------------------------------------------------------------------------------
 
-    /**
-     * Sets the project building request from which this project instance was created. <strong>Warning:</strong> This is
-     * an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
-     * 
-     * @param projectBuildingRequest The project building request, may be {@code null}.
-     * @since 2.1
-     */
-    public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingRequest )
-    {
-        projectBuilderConfiguration = projectBuildingRequest;
-    }
+    private ProjectBuildingRequest projectBuilderConfiguration;
 
-    private void checkProjectBuildingRequest()
-    {
-        if ( projectBuilderConfiguration == null )
-        {
-            throw new IllegalStateException( "project building request missing" );
-        }
-    }
+    private Map<String, String> moduleAdjustments;
 
+    @Deprecated // This appears only to be used in test code
+    public String getModulePathAdjustment( MavenProject moduleProject )
+        throws IOException
+    {
+        // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
+        // is coming from the repository??
+        String module = moduleProject.getArtifactId();
+
+        File moduleFile = moduleProject.getFile();
+
+        if ( moduleFile != null )
+        {
+            File moduleDir = moduleFile.getCanonicalFile().getParentFile();
+
+            module = moduleDir.getName();
+        }
+
+        if ( moduleAdjustments == null )
+        {
+            moduleAdjustments = new HashMap<String, String>();
+
+            List<String> modules = getModules();
+            if ( modules != null )
+            {
+                for ( String modulePath : modules )
+                {
+                    String moduleName = modulePath;
+
+                    if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
+                    {
+                        moduleName = moduleName.substring( 0, moduleName.length() - 1 );
+                    }
+
+                    int lastSlash = moduleName.lastIndexOf( '/' );
+
+                    if ( lastSlash < 0 )
+                    {
+                        lastSlash = moduleName.lastIndexOf( '\\' );
+                    }
+
+                    String adjustment = null;
+
+                    if ( lastSlash > -1 )
+                    {
+                        moduleName = moduleName.substring( lastSlash + 1 );
+                        adjustment = modulePath.substring( 0, lastSlash );
+                    }
+
+                    moduleAdjustments.put( moduleName, adjustment );
+                }
+            }
+        }
+
+        return moduleAdjustments.get( module );
+    }    
+    
+    @Deprecated
+    public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter )
+        throws InvalidDependencyVersionException
+    {
+        return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope, filter, this );
+    }
+
+    @Deprecated
+    protected void setScriptSourceRoots( List<String> scriptSourceRoots )
+    {
+        this.scriptSourceRoots = scriptSourceRoots;
+    }
+
+    @Deprecated
+    public void addScriptSourceRoot( String path )
+    {
+        if ( path != null )
+        {
+            path = path.trim();
+            if ( path.length() != 0 )
+            {
+                if ( !getScriptSourceRoots().contains( path ) )
+                {
+                    getScriptSourceRoots().add( path );
+                }
+            }
+        }
+    }
+
+    @Deprecated
+    public List<String> getScriptSourceRoots()
+    {
+        return scriptSourceRoots;
+    }
+
+    @Deprecated
+    public List<Artifact> getCompileArtifacts()
+    {
+        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
+
+        for ( Artifact a : getArtifacts() )
+        {
+            // TODO: classpath check doesn't belong here - that's the other method
+            if ( a.getArtifactHandler().isAddedToClasspath() )
+            {
+                // TODO: let the scope handler deal with this
+                if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
+                    || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+                {
+                    list.add( a );
+                }
+            }
+        }
+        return list;
+    }
+
+    @Deprecated
+    public List<Dependency> getCompileDependencies()
+    {
+        Set<Artifact> artifacts = getArtifacts();
+
+        if ( ( artifacts == null ) || artifacts.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
+
+        for ( Artifact a : getArtifacts() )
+        {
+            // TODO: let the scope handler deal with this
+            if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
+                || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+            {
+                Dependency dependency = new Dependency();
+
+                dependency.setArtifactId( a.getArtifactId() );
+                dependency.setGroupId( a.getGroupId() );
+                dependency.setVersion( a.getVersion() );
+                dependency.setScope( a.getScope() );
+                dependency.setType( a.getType() );
+                dependency.setClassifier( a.getClassifier() );
+
+                list.add( dependency );
+            }
+        }
+        return list;
+    }
+
+    @Deprecated
+    public List<Artifact> getTestArtifacts()
+    {
+        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
+
+        for ( Artifact a : getArtifacts() )
+        {
+            // TODO: classpath check doesn't belong here - that's the other method
+            if ( a.getArtifactHandler().isAddedToClasspath() )
+            {
+                list.add( a );
+            }
+        }
+        return list;
+    }
+
+    @Deprecated
+    public List<Dependency> getTestDependencies()
+    {
+        Set<Artifact> artifacts = getArtifacts();
+
+        if ( ( artifacts == null ) || artifacts.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
+
+        for ( Artifact a : getArtifacts() )
+        {
+            Dependency dependency = new Dependency();
+
+            dependency.setArtifactId( a.getArtifactId() );
+            dependency.setGroupId( a.getGroupId() );
+            dependency.setVersion( a.getVersion() );
+            dependency.setScope( a.getScope() );
+            dependency.setType( a.getType() );
+            dependency.setClassifier( a.getClassifier() );
+
+            list.add( dependency );
+        }
+        return list;
+    }
+
+    @Deprecated // used by the Maven ITs
+    public List<Dependency> getRuntimeDependencies()
+    {
+        Set<Artifact> artifacts = getArtifacts();
+
+        if ( ( artifacts == null ) || artifacts.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
+
+        for ( Artifact a : getArtifacts()  )
+        {
+            // TODO: let the scope handler deal with this
+            if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
+            {
+                Dependency dependency = new Dependency();
+
+                dependency.setArtifactId( a.getArtifactId() );
+                dependency.setGroupId( a.getGroupId() );
+                dependency.setVersion( a.getVersion() );
+                dependency.setScope( a.getScope() );
+                dependency.setType( a.getType() );
+                dependency.setClassifier( a.getClassifier() );
+
+                list.add( dependency );
+            }
+        }
+        return list;
+    }    
+    
+    @Deprecated
+    public List<Artifact> getRuntimeArtifacts()
+    {
+        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
+
+        for ( Artifact a : getArtifacts()  )
+        {
+            // TODO: classpath check doesn't belong here - that's the other method
+            if ( a.getArtifactHandler().isAddedToClasspath()
+            // TODO: let the scope handler deal with this
+                && ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) )
+            {
+                list.add( a );
+            }
+        }
+        return list;
+    }    
+    
+    @Deprecated
+    public List<String> getSystemClasspathElements()
+        throws DependencyResolutionRequiredException
+    {
+        List<String> list = new ArrayList<String>( getArtifacts().size() );
+
+        String d = getBuild().getOutputDirectory();
+        if ( d != null )
+        {
+            list.add( d );
+        }
+
+        for ( Artifact a : getArtifacts() )
+        {
+            if ( a.getArtifactHandler().isAddedToClasspath() )
+            {
+                // TODO: let the scope handler deal with this
+                if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+                {
+                    addArtifactPath( a, list );
+                }
+            }
+        }
+        return list;
+    }
+
+    @Deprecated
+    public List<Artifact> getSystemArtifacts()
+    {
+        List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
+
+        for ( Artifact a : getArtifacts() )
+        {
+            // TODO: classpath check doesn't belong here - that's the other method
+            if ( a.getArtifactHandler().isAddedToClasspath() )
+            {
+                // TODO: let the scope handler deal with this
+                if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+                {
+                    list.add( a );
+                }
+            }
+        }
+        return list;
+    }
+
+    @Deprecated
+    public List<Dependency> getSystemDependencies()
+    {
+        Set<Artifact> artifacts = getArtifacts();
+
+        if ( ( artifacts == null ) || artifacts.isEmpty() )
+        {
+            return Collections.emptyList();
+        }
+
+        List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
+
+        for ( Artifact a : getArtifacts() )
+        {
+            // TODO: let the scope handler deal with this
+            if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
+            {
+                Dependency dependency = new Dependency();
+
+                dependency.setArtifactId( a.getArtifactId() );
+                dependency.setGroupId( a.getGroupId() );
+                dependency.setVersion( a.getVersion() );
+                dependency.setScope( a.getScope() );
+                dependency.setType( a.getType() );
+                dependency.setClassifier( a.getClassifier() );
+
+                list.add( dependency );
+            }
+        }
+        return list;
+    }
+
+    @Deprecated
+    public void setReporting( Reporting reporting )
+    {
+        getModel().setReporting( reporting );
+    }
+
+    @Deprecated
+    public Reporting getReporting()
+    {
+        return getModel().getReporting();
+    }
+
+    @Deprecated
+    public void setReportArtifacts( Set<Artifact> reportArtifacts )
+    {
+        this.reportArtifacts = reportArtifacts;
+
+        reportArtifactMap = null;
+    }
+
+    @Deprecated
+    public Set<Artifact> getReportArtifacts()
+    {
+        return reportArtifacts;
+    }
+
+    @Deprecated
+    public Map<String, Artifact> getReportArtifactMap()
+    {
+        if ( reportArtifactMap == null )
+        {
+            reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
+        }
+
+        return reportArtifactMap;
+    }
+
+    @Deprecated
+    public void setExtensionArtifacts( Set<Artifact> extensionArtifacts )
+    {
+        this.extensionArtifacts = extensionArtifacts;
+
+        extensionArtifactMap = null;
+    }
+
+    @Deprecated
+    public Set<Artifact> getExtensionArtifacts()
+    {
+        return extensionArtifacts;
+    }
+
+    @Deprecated
+    public Map<String, Artifact> getExtensionArtifactMap()
+    {
+        if ( extensionArtifactMap == null )
+        {
+            extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() );
+        }
+
+        return extensionArtifactMap;
+    }
+
+    @Deprecated
+    public List<ReportPlugin> getReportPlugins()
+    {
+        if ( getModel().getReporting() == null )
+        {
+            return Collections.emptyList();
+        }
+        return getModel().getReporting().getPlugins();
+
+    }
+
+    @Deprecated
+    public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId )
+    {
+        Xpp3Dom dom = null;
+
+        // ----------------------------------------------------------------------
+        // I would like to be able to lookup the Mojo object using a key but
+        // we have a limitation in modello that will be remedied shortly. So
+        // for now I have to iterate through and see what we have.
+        // ----------------------------------------------------------------------
+
+        if ( getReportPlugins() != null )
+        {
+            for ( ReportPlugin plugin : getReportPlugins() )
+            {
+                if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
+                {
+                    dom = (Xpp3Dom) plugin.getConfiguration();
+
+                    if ( reportSetId != null )
+                    {
+                        ReportSet reportSet = plugin.getReportSetsAsMap().get( reportSetId );
+                        if ( reportSet != null )
+                        {
+                            Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
+                            if ( executionConfiguration != null )
+                            {
+                                Xpp3Dom newDom = new Xpp3Dom( executionConfiguration );
+                                dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
+                            }
+                        }
+                    }
+                    break;
+                }
+            }
+        }
+
+        if ( dom != null )
+        {
+            // make a copy so the original in the POM doesn't get messed with
+            dom = new Xpp3Dom( dom );
+        }
+
+        return dom;
+    }
+
+    /**
+     * @deprecated Use MavenProjectHelper.attachArtifact(..) instead.
+     */
+    @Deprecated
+    public void attachArtifact( String type, String classifier, File file )
+    {
+    }
+
+    /**
+     * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
+     */
+    @Deprecated
+    public void writeModel( Writer writer )
+        throws IOException
+    {
+        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
+        pomWriter.write( writer, getModel() );
+    }
+
+    /**
+     * @deprecated Use {@link org.apache.maven.model.io.ModelWriter}.
+     */
+    @Deprecated
+    public void writeOriginalModel( Writer writer )
+        throws IOException
+    {
+        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
+        pomWriter.write( writer, getOriginalModel() );
+    }
+
+    @Deprecated
+    public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
+    {
+        return pluginArtifact;
+    }
+
+    /**
+     * Gets the project building request from which this project instance was created. <strong>Warning:</strong> This is
+     * an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
+     * 
+     * @return The project building request or {@code null}.
+     * @since 2.1
+     */
+    @Deprecated
+    public ProjectBuildingRequest getProjectBuildingRequest()
+    {
+        return projectBuilderConfiguration;
+    }
+
+    /**
+     * Sets the project building request from which this project instance was created. <strong>Warning:</strong> This is
+     * an utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
+     * 
+     * @param projectBuildingRequest The project building request, may be {@code null}.
+     * @since 2.1
+     */
+    // used by maven-dependency-tree
+    @Deprecated
+    public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingRequest )
+    {
+        this.projectBuilderConfiguration = projectBuildingRequest;
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java
index 430093f..c6248ad 100644
--- a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java
@@ -179,32 +179,6 @@ public class MavenProjectTest
                        activeProfilesClone );
     }
 
-    public void testInvalidParent() throws Exception
-    {
-        Parent parent = new Parent();
-        parent.setGroupId( "test-group" );
-        parent.setArtifactId( "parent-artifact" );
-        parent.setVersion( "1.0" );
-        Model model = new Model();
-        model.setParent( parent );
-        model.setArtifactId( "child-artifact" );
-        final AtomicInteger logged = new AtomicInteger();
-        class L extends LoggerStub
-        {
-            @Override
-            public void error( String s, Throwable throwable )
-            {
-                logged.incrementAndGet();
-            }
-        }
-        MavenProject project = new MavenProject( repositorySystem, projectBuilder, newBuildingRequest(), new L() );
-        project.setModel( model );
-        assertNull( project.getParent() );
-        assertEquals( 1, logged.get() );
-        assertNull( project.getParent() );
-        assertEquals( 1, logged.get() );
-    }
-
     public void testUndefinedOutputDirectory()
         throws Exception
     {

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java
----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java
index 2a9b176..6208c88 100644
--- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java
+++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.MavenArtifactRepository;
@@ -36,6 +37,8 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Plugin;
@@ -48,6 +51,7 @@ import org.apache.maven.settings.Server;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
 import org.eclipse.aether.RepositorySystemSession;
 
 /**
@@ -61,6 +65,9 @@ public class TestRepositorySystem
     @Requirement
     private ModelReader modelReader;
 
+    @Requirement
+    private ArtifactFactory artifactFactory;    
+    
     public ArtifactRepository buildArtifactRepository( Repository repository )
         throws InvalidRepositoryException
     {
@@ -134,8 +141,22 @@ public class TestRepositorySystem
 
     public Artifact createPluginArtifact( Plugin plugin )
     {
-        return new DefaultArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null,
-                                    "maven-plugin", null, new TestArtifactHandler( "maven-plugin", "jar" ) );
+        VersionRange versionRange;
+        try
+        {
+            String version = plugin.getVersion();
+            if ( StringUtils.isEmpty( version ) )
+            {
+                version = "RELEASE";
+            }
+            versionRange = VersionRange.createFromVersionSpec( version );
+        }
+        catch ( InvalidVersionSpecificationException e )
+        {
+            return null;
+        }
+
+        return artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange );
     }
 
     public Artifact createProjectArtifact( String groupId, String artifactId, String version )


[2/2] git commit: MNG-5661: First step toward an immutable Maven Project. This removes all compentry from MavenProject. There's a note at the top of the class which describes the rest of the work.

Posted by jv...@apache.org.
MNG-5661: First step toward an immutable Maven Project. This removes all compentry from MavenProject. There's a note at the top
          of the class which describes the rest of the work.

check point


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/6cf93209
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/6cf93209
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/6cf93209

Branch: refs/heads/master
Commit: 6cf9320942c34bc68205425ab696b1712ace9ba4
Parents: ce6fc62
Author: Jason van Zyl <ja...@tesla.io>
Authored: Thu May 29 13:38:07 2014 -0400
Committer: Jason van Zyl <ja...@tesla.io>
Committed: Sat Jul 5 16:15:36 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/maven/RepositoryUtils.java  |    7 +-
 .../repository/MavenArtifactRepository.java     |    7 +-
 .../maven/bridge/MavenRepositorySystem.java     |  698 ++++++++
 .../org/apache/maven/bridge/MirrorSelector.java |  197 +++
 .../DefaultMavenExecutionRequestPopulator.java  |   23 +-
 .../project/DefaultMavenProjectHelper.java      |   21 +-
 .../maven/project/DefaultProjectBuilder.java    |  232 ++-
 .../org/apache/maven/project/MavenProject.java  | 1533 +++++++-----------
 .../apache/maven/project/MavenProjectTest.java  |   26 -
 .../maven/repository/TestRepositorySystem.java  |   25 +-
 10 files changed, 1797 insertions(+), 972 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
index 6341d13..059c9e6 100644
--- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
@@ -25,11 +25,17 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.MavenArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout2;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.codehaus.plexus.util.StringUtils;
 import org.eclipse.aether.artifact.Artifact;
 import org.eclipse.aether.artifact.ArtifactProperties;
 import org.eclipse.aether.artifact.ArtifactType;
@@ -359,5 +365,4 @@ public class RepositoryUtils
         }
         return artifacts;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
index 7ded223..fa503a0 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java
@@ -134,10 +134,15 @@ public class MavenArtifactRepository
     {
         StringBuilder sb = new StringBuilder();
 
-        sb.append( "       id: " ).append( getId() ).append( "\n" );
+        sb.append( "      id: " ).append( getId() ).append( "\n" );
         sb.append( "      url: " ).append( getUrl() ).append( "\n" );
         sb.append( "   layout: " ).append( layout != null ? layout : "none" ).append( "\n" );
 
+        if( proxy != null)
+        {
+            sb.append("    proxy: " ).append( proxy.getHost() ).append(":").append( proxy.getPort() ).append( "\n" );
+        }
+        
         if ( snapshots != null )
         {
             sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
new file mode 100644
index 0000000..80aee22
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
@@ -0,0 +1,698 @@
+package org.apache.maven.bridge;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.Authentication;
+import org.apache.maven.artifact.repository.MavenArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout2;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.repository.Proxy;
+import org.apache.maven.settings.Mirror;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.building.SettingsProblem;
+import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
+import org.apache.maven.settings.crypto.SettingsDecryptionResult;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.impl.ArtifactResolver;
+import org.eclipse.aether.repository.AuthenticationContext;
+import org.eclipse.aether.repository.AuthenticationSelector;
+import org.eclipse.aether.repository.ProxySelector;
+import org.eclipse.aether.repository.RemoteRepository;
+
+/**
+ * @author Jason van Zyl
+ */
+@Component( role = MavenRepositorySystem.class, hint = "default" )
+public class MavenRepositorySystem
+{
+
+    @Requirement
+    private Logger logger;
+
+    @Requirement
+    private ArtifactHandlerManager artifactHandlerManager;
+    
+    @Requirement
+    private ArtifactResolver artifactResolver;
+
+    @Requirement( role = ArtifactRepositoryLayout.class )
+    private Map<String, ArtifactRepositoryLayout> layouts;
+
+    @Requirement
+    private PlexusContainer plexus;
+
+    @Requirement
+    private SettingsDecrypter settingsDecrypter;
+    
+    // DefaultProjectBuilder
+    public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
+    {
+        return XcreateArtifact( groupId, artifactId, version, scope, type );
+    }
+
+    // DefaultProjectBuilder
+    public Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId )
+    {
+        return XcreateProjectArtifact( groupId, artifactId, metaVersionId );
+    }
+
+    // DefaultProjectBuilder
+    public Artifact createDependencyArtifact( Dependency d )
+    {
+        VersionRange versionRange;
+        try
+        {
+            versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
+        }
+        catch ( InvalidVersionSpecificationException e )
+        {
+            return null;
+        }
+
+        Artifact artifact =
+            XcreateDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(),
+                                                      d.getClassifier(), d.getScope(), d.isOptional() );
+
+        if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && d.getSystemPath() != null )
+        {
+            artifact.setFile( new File( d.getSystemPath() ) );
+        }
+
+        if ( !d.getExclusions().isEmpty() )
+        {
+            List<String> exclusions = new ArrayList<String>();
+
+            for ( Exclusion exclusion : d.getExclusions() )
+            {
+                exclusions.add( exclusion.getGroupId() + ':' + exclusion.getArtifactId() );
+            }
+
+            artifact.setDependencyFilter( new ExcludesArtifactFilter( exclusions ) );
+        }
+
+        return artifact;
+    }
+
+    // DefaultProjectBuilder
+    public Artifact createExtensionArtifact( String groupId, String artifactId, String version )
+    {
+        VersionRange versionRange;
+        try
+        {
+            versionRange = VersionRange.createFromVersionSpec( version );
+        }
+        catch ( InvalidVersionSpecificationException e )
+        {
+            return null;
+        }
+
+        return XcreateExtensionArtifact( groupId, artifactId, versionRange );
+    }
+
+    // DefaultProjectBuilder
+    public Artifact createParentArtifact( String groupId, String artifactId, String version )
+    {
+        return XcreateParentArtifact( groupId, artifactId, version );
+    }
+
+    // DefaultProjectBuilder
+    public Artifact createPluginArtifact( Plugin plugin )
+    {
+        VersionRange versionRange;
+        try
+        {
+            String version = plugin.getVersion();
+            if ( StringUtils.isEmpty( version ) )
+            {
+                version = "RELEASE";
+            }
+            versionRange = VersionRange.createFromVersionSpec( version );
+        }
+        catch ( InvalidVersionSpecificationException e )
+        {
+            return null;
+        }
+
+        return XcreatePluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange );
+    }
+
+    public List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories )
+    {
+        if ( repositories == null )
+        {
+            return null;
+        }
+
+        Map<String, List<ArtifactRepository>> reposByKey = new LinkedHashMap<String, List<ArtifactRepository>>();
+
+        for ( ArtifactRepository repository : repositories )
+        {
+            String key = repository.getId();
+
+            List<ArtifactRepository> aliasedRepos = reposByKey.get( key );
+
+            if ( aliasedRepos == null )
+            {
+                aliasedRepos = new ArrayList<ArtifactRepository>();
+                reposByKey.put( key, aliasedRepos );
+            }
+
+            aliasedRepos.add( repository );
+        }
+
+        List<ArtifactRepository> effectiveRepositories = new ArrayList<ArtifactRepository>();
+
+        for ( List<ArtifactRepository> aliasedRepos : reposByKey.values() )
+        {
+            List<ArtifactRepository> mirroredRepos = new ArrayList<ArtifactRepository>();
+
+            List<ArtifactRepositoryPolicy> releasePolicies =
+                new ArrayList<ArtifactRepositoryPolicy>( aliasedRepos.size() );
+
+            for ( ArtifactRepository aliasedRepo : aliasedRepos )
+            {
+                releasePolicies.add( aliasedRepo.getReleases() );
+                mirroredRepos.addAll( aliasedRepo.getMirroredRepositories() );
+            }
+
+            ArtifactRepositoryPolicy releasePolicy = getEffectivePolicy( releasePolicies );
+
+            List<ArtifactRepositoryPolicy> snapshotPolicies =
+                new ArrayList<ArtifactRepositoryPolicy>( aliasedRepos.size() );
+
+            for ( ArtifactRepository aliasedRepo : aliasedRepos )
+            {
+                snapshotPolicies.add( aliasedRepo.getSnapshots() );
+            }
+
+            ArtifactRepositoryPolicy snapshotPolicy = getEffectivePolicy( snapshotPolicies );
+
+            ArtifactRepository aliasedRepo = aliasedRepos.get( 0 );
+
+            ArtifactRepository effectiveRepository =
+                createArtifactRepository( aliasedRepo.getId(), aliasedRepo.getUrl(), aliasedRepo.getLayout(),
+                                          snapshotPolicy, releasePolicy );
+
+            effectiveRepository.setAuthentication( aliasedRepo.getAuthentication() );
+
+            effectiveRepository.setProxy( aliasedRepo.getProxy() );
+
+            effectiveRepository.setMirroredRepositories( mirroredRepos );
+
+            effectiveRepositories.add( effectiveRepository );
+        }
+
+        return effectiveRepositories;
+    }
+
+    private ArtifactRepositoryPolicy getEffectivePolicy( Collection<ArtifactRepositoryPolicy> policies )
+    {
+        ArtifactRepositoryPolicy effectivePolicy = null;
+
+        for ( ArtifactRepositoryPolicy policy : policies )
+        {
+            if ( effectivePolicy == null )
+            {
+                effectivePolicy = new ArtifactRepositoryPolicy( policy );
+            }
+            else
+            {
+                effectivePolicy.merge( policy );
+            }
+        }
+
+        return effectivePolicy;
+    }
+
+    public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
+    {
+        return MirrorSelector.getMirror( repository, mirrors );
+    }
+
+    public void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors )
+    {
+        if ( repositories != null && mirrors != null )
+        {
+            for ( ArtifactRepository repository : repositories )
+            {
+                Mirror mirror = getMirror( repository, mirrors );
+                injectMirror( repository, mirror );
+            }
+        }
+    }
+
+    private Mirror getMirror( RepositorySystemSession session, ArtifactRepository repository )
+    {
+        if ( session != null )
+        {
+            org.eclipse.aether.repository.MirrorSelector selector = session.getMirrorSelector();
+            if ( selector != null )
+            {
+                RemoteRepository repo = selector.getMirror( RepositoryUtils.toRepo( repository ) );
+                if ( repo != null )
+                {
+                    Mirror mirror = new Mirror();
+                    mirror.setId( repo.getId() );
+                    mirror.setUrl( repo.getUrl() );
+                    mirror.setLayout( repo.getContentType() );
+                    return mirror;
+                }
+            }
+        }
+        return null;
+    }
+
+    public void injectMirror( RepositorySystemSession session, List<ArtifactRepository> repositories )
+    {
+        if ( repositories != null && session != null )
+        {
+            for ( ArtifactRepository repository : repositories )
+            {
+                Mirror mirror = getMirror( session, repository );
+                injectMirror( repository, mirror );
+            }
+        }
+    }
+
+    private void injectMirror( ArtifactRepository repository, Mirror mirror )
+    {
+        if ( mirror != null )
+        {
+            ArtifactRepository original =
+                createArtifactRepository( repository.getId(), repository.getUrl(), repository.getLayout(),
+                                          repository.getSnapshots(), repository.getReleases() );
+
+            repository.setMirroredRepositories( Collections.singletonList( original ) );
+
+            repository.setId( mirror.getId() );
+            repository.setUrl( mirror.getUrl() );
+
+            if ( StringUtils.isNotEmpty( mirror.getLayout() ) )
+            {
+                repository.setLayout( getLayout( mirror.getLayout() ) );
+            }
+        }
+    }
+
+    public void injectAuthentication( List<ArtifactRepository> repositories, List<Server> servers )
+    {
+        if ( repositories != null )
+        {
+            Map<String, Server> serversById = new HashMap<String, Server>();
+
+            if ( servers != null )
+            {
+                for ( Server server : servers )
+                {
+                    if ( !serversById.containsKey( server.getId() ) )
+                    {
+                        serversById.put( server.getId(), server );
+                    }
+                }
+            }
+
+            for ( ArtifactRepository repository : repositories )
+            {
+                Server server = serversById.get( repository.getId() );
+
+                if ( server != null )
+                {
+                    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest( server );
+                    SettingsDecryptionResult result = settingsDecrypter.decrypt( request );
+                    server = result.getServer();
+
+                    if ( logger.isDebugEnabled() )
+                    {
+                        for ( SettingsProblem problem : result.getProblems() )
+                        {
+                            logger.debug( problem.getMessage(), problem.getException() );
+                        }
+                    }
+
+                    Authentication authentication = new Authentication( server.getUsername(), server.getPassword() );
+                    authentication.setPrivateKey( server.getPrivateKey() );
+                    authentication.setPassphrase( server.getPassphrase() );
+
+                    repository.setAuthentication( authentication );
+                }
+                else
+                {
+                    repository.setAuthentication( null );
+                }
+            }
+        }
+    }
+
+    private Authentication getAuthentication( RepositorySystemSession session, ArtifactRepository repository )
+    {
+        if ( session != null )
+        {
+            AuthenticationSelector selector = session.getAuthenticationSelector();
+            if ( selector != null )
+            {
+                RemoteRepository repo = RepositoryUtils.toRepo( repository );
+                org.eclipse.aether.repository.Authentication auth = selector.getAuthentication( repo );
+                if ( auth != null )
+                {
+                    repo = new RemoteRepository.Builder( repo ).setAuthentication( auth ).build();
+                    AuthenticationContext authCtx = AuthenticationContext.forRepository( session, repo );
+                    Authentication result =
+                        new Authentication( authCtx.get( AuthenticationContext.USERNAME ),
+                                            authCtx.get( AuthenticationContext.PASSWORD ) );
+                    result.setPrivateKey( authCtx.get( AuthenticationContext.PRIVATE_KEY_PATH ) );
+                    result.setPassphrase( authCtx.get( AuthenticationContext.PRIVATE_KEY_PASSPHRASE ) );
+                    authCtx.close();
+                    return result;
+                }
+            }
+        }
+        return null;
+    }
+
+    public void injectAuthentication( RepositorySystemSession session, List<ArtifactRepository> repositories )
+    {
+        if ( repositories != null && session != null )
+        {
+            for ( ArtifactRepository repository : repositories )
+            {
+                repository.setAuthentication( getAuthentication( session, repository ) );
+            }
+        }
+    }
+
+    private Proxy getProxy( RepositorySystemSession session, ArtifactRepository repository )
+    {
+        if ( session != null )
+        {
+            ProxySelector selector = session.getProxySelector();
+            if ( selector != null )
+            {
+                RemoteRepository repo = RepositoryUtils.toRepo( repository );
+                org.eclipse.aether.repository.Proxy proxy = selector.getProxy( repo );
+                if ( proxy != null )
+                {
+                    Proxy p = new Proxy();
+                    p.setHost( proxy.getHost() );
+                    p.setProtocol( proxy.getType() );
+                    p.setPort( proxy.getPort() );
+                    if ( proxy.getAuthentication() != null )
+                    {
+                        repo = new RemoteRepository.Builder( repo ).setProxy( proxy ).build();
+                        AuthenticationContext authCtx = AuthenticationContext.forProxy( session, repo );
+                        p.setUserName( authCtx.get( AuthenticationContext.USERNAME ) );
+                        p.setPassword( authCtx.get( AuthenticationContext.PASSWORD ) );
+                        p.setNtlmDomain( authCtx.get( AuthenticationContext.NTLM_DOMAIN ) );
+                        p.setNtlmHost( authCtx.get( AuthenticationContext.NTLM_WORKSTATION ) );
+                        authCtx.close();
+                    }
+                    return p;
+                }
+            }
+        }
+        return null;
+    }
+
+    public void injectProxy( RepositorySystemSession session, List<ArtifactRepository> repositories )
+    {
+        if ( repositories != null && session != null )
+        {
+            for ( ArtifactRepository repository : repositories )
+            {
+                repository.setProxy( getProxy( session, repository ) );
+            }
+        }
+    }
+
+    private ArtifactRepositoryLayout getLayout( String id )
+    {
+        ArtifactRepositoryLayout layout = layouts.get( id );
+
+        return layout;
+    }
+
+
+    //
+    // Taken from LegacyRepositorySystem
+    //
+
+    public static org.apache.maven.model.Repository fromSettingsRepository( org.apache.maven.settings.Repository settingsRepository )
+    {
+        org.apache.maven.model.Repository modelRepository = new org.apache.maven.model.Repository();
+        modelRepository.setId( settingsRepository.getId() );
+        modelRepository.setLayout( settingsRepository.getLayout() );
+        modelRepository.setName( settingsRepository.getName() );
+        modelRepository.setUrl( settingsRepository.getUrl() );
+        modelRepository.setReleases( fromSettingsRepositoryPolicy( settingsRepository.getReleases() ) );
+        modelRepository.setSnapshots( fromSettingsRepositoryPolicy( settingsRepository.getSnapshots() ) );
+        return modelRepository;
+    }
+
+    public static org.apache.maven.model.RepositoryPolicy fromSettingsRepositoryPolicy( org.apache.maven.settings.RepositoryPolicy settingsRepositoryPolicy )
+    {
+        org.apache.maven.model.RepositoryPolicy modelRepositoryPolicy = new org.apache.maven.model.RepositoryPolicy();
+        if ( settingsRepositoryPolicy != null )
+        {
+            modelRepositoryPolicy.setEnabled( settingsRepositoryPolicy.isEnabled() );
+            modelRepositoryPolicy.setUpdatePolicy( settingsRepositoryPolicy.getUpdatePolicy() );
+            modelRepositoryPolicy.setChecksumPolicy( settingsRepositoryPolicy.getChecksumPolicy() );
+        }
+        return modelRepositoryPolicy;
+    }
+
+    public static ArtifactRepository buildArtifactRepository( org.apache.maven.settings.Repository repo )
+        throws InvalidRepositoryException
+    {
+        return buildArtifactRepository( fromSettingsRepository( repo ) );
+    }
+
+    public static ArtifactRepository buildArtifactRepository( org.apache.maven.model.Repository repo )
+        throws InvalidRepositoryException
+    {
+        if ( repo != null )
+        {
+            String id = repo.getId();
+
+            if ( StringUtils.isEmpty( id ) )
+            {
+                throw new InvalidRepositoryException( "Repository identifier missing", "" );
+            }
+
+            String url = repo.getUrl();
+
+            if ( StringUtils.isEmpty( url ) )
+            {
+                throw new InvalidRepositoryException( "URL missing for repository " + id, id );
+            }
+
+            ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
+
+            ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
+
+            ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
+
+            return createArtifactRepository( id, url, layout, snapshots, releases );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    public static ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( org.apache.maven.model.RepositoryPolicy policy )
+    {
+        boolean enabled = true;
+
+        String updatePolicy = null;
+
+        String checksumPolicy = null;
+
+        if ( policy != null )
+        {
+            enabled = policy.isEnabled();
+
+            if ( policy.getUpdatePolicy() != null )
+            {
+                updatePolicy = policy.getUpdatePolicy();
+            }
+            if ( policy.getChecksumPolicy() != null )
+            {
+                checksumPolicy = policy.getChecksumPolicy();
+            }
+        }
+
+        return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
+    }
+
+    public static ArtifactRepository createArtifactRepository( String id, String url,
+                                                        ArtifactRepositoryLayout repositoryLayout,
+                                                        ArtifactRepositoryPolicy snapshots,
+                                                        ArtifactRepositoryPolicy releases )
+    {
+        if ( snapshots == null )
+        {
+            snapshots = new ArtifactRepositoryPolicy();
+        }
+
+        if ( releases == null )
+        {
+            releases = new ArtifactRepositoryPolicy();
+        }
+
+        ArtifactRepository repository;
+        if ( repositoryLayout instanceof ArtifactRepositoryLayout2 )
+        {
+            repository =
+                ( (ArtifactRepositoryLayout2) repositoryLayout ).newMavenArtifactRepository( id, url, snapshots,
+                                                                                             releases );
+        }
+        else
+        {
+            repository = new MavenArtifactRepository( id, url, repositoryLayout, snapshots, releases );
+        }
+
+        return repository;
+    }
+    
+    // ArtifactFactory
+    private Artifact XcreateArtifact( String groupId, String artifactId, String version, String scope, String type )
+    {
+        return XcreateArtifact( groupId, artifactId, version, scope, type, null, null );
+    }
+
+    private Artifact XcreateDependencyArtifact( String groupId, String artifactId, VersionRange versionRange,
+                                              String type, String classifier, String scope, boolean optional )
+    {
+        return XcreateArtifact( groupId, artifactId, versionRange, type, classifier, scope, null, optional );
+    }
+
+    private Artifact XcreateProjectArtifact( String groupId, String artifactId, String version )
+    {
+        return XcreateProjectArtifact( groupId, artifactId, version, null );
+    }
+
+    private Artifact XcreateParentArtifact( String groupId, String artifactId, String version )
+    {
+        return XcreateProjectArtifact( groupId, artifactId, version );
+    }
+
+    private Artifact XcreatePluginArtifact( String groupId, String artifactId, VersionRange versionRange )
+    {
+        return XcreateArtifact( groupId, artifactId, versionRange, "maven-plugin", null, Artifact.SCOPE_RUNTIME, null );
+    }
+
+    private Artifact XcreateProjectArtifact( String groupId, String artifactId, String version, String scope )
+    {
+        return XcreateArtifact( groupId, artifactId, version, scope, "pom" );
+    }
+
+    private Artifact XcreateExtensionArtifact( String groupId, String artifactId, VersionRange versionRange )
+    {
+        return XcreateArtifact( groupId, artifactId, versionRange, "jar", null, Artifact.SCOPE_RUNTIME, null );
+    }
+
+    private Artifact XcreateArtifact( String groupId, String artifactId, String version, String scope, String type,
+                                     String classifier, String inheritedScope )
+    {
+        VersionRange versionRange = null;
+        if ( version != null )
+        {
+            versionRange = VersionRange.createFromVersion( version );
+        }
+        return XcreateArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope );
+    }
+
+    private Artifact XcreateArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
+                                     String classifier, String scope, String inheritedScope )
+    {
+        return XcreateArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope, false );
+    }
+
+    private Artifact XcreateArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
+                                     String classifier, String scope, String inheritedScope, boolean optional )
+    {
+        String desiredScope = Artifact.SCOPE_RUNTIME;
+
+        if ( inheritedScope == null )
+        {
+            desiredScope = scope;
+        }
+        else if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_PROVIDED.equals( scope ) )
+        {
+            return null;
+        }
+        else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
+        {
+            // added to retain compile artifactScope. Remove if you want compile inherited as runtime
+            desiredScope = Artifact.SCOPE_COMPILE;
+        }
+
+        if ( Artifact.SCOPE_TEST.equals( inheritedScope ) )
+        {
+            desiredScope = Artifact.SCOPE_TEST;
+        }
+
+        if ( Artifact.SCOPE_PROVIDED.equals( inheritedScope ) )
+        {
+            desiredScope = Artifact.SCOPE_PROVIDED;
+        }
+
+        if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
+        {
+            // system scopes come through unchanged...
+            desiredScope = Artifact.SCOPE_SYSTEM;
+        }
+
+        ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( type );
+
+        return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler,
+                                    optional );
+    }    
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java b/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java
new file mode 100644
index 0000000..c0dd935
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java
@@ -0,0 +1,197 @@
+package org.apache.maven.bridge;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.settings.Mirror;
+import org.codehaus.plexus.util.StringUtils;
+
+public class MirrorSelector
+{
+    private static final String WILDCARD = "*";
+
+    private static final String EXTERNAL_WILDCARD = "external:*";
+
+    public static Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
+    {
+        String repoId = repository.getId();
+
+        if ( repoId != null && mirrors != null )
+        {
+            for ( Mirror mirror : mirrors )
+            {
+                if ( repoId.equals( mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) )
+                {
+                    return mirror;
+                }
+            }
+
+            for ( Mirror mirror : mirrors )
+            {
+                if ( matchPattern( repository, mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) )
+                {
+                    return mirror;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * This method checks if the pattern matches the originalRepository. Valid patterns: * = everything external:* =
+     * everything not on the localhost and not file based. repo,repo1 = repo or repo1 *,!repo1 = everything except repo1
+     *
+     * @param originalRepository to compare for a match.
+     * @param pattern used for match. Currently only '*' is supported.
+     * @return true if the repository is a match to this pattern.
+     */
+    static boolean matchPattern( ArtifactRepository originalRepository, String pattern )
+    {
+        boolean result = false;
+        String originalId = originalRepository.getId();
+
+        // simple checks first to short circuit processing below.
+        if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) )
+        {
+            result = true;
+        }
+        else
+        {
+            // process the list
+            String[] repos = pattern.split( "," );
+            for ( String repo : repos )
+            {
+                // see if this is a negative match
+                if ( repo.length() > 1 && repo.startsWith( "!" ) )
+                {
+                    if ( repo.substring( 1 ).equals( originalId ) )
+                    {
+                        // explicitly exclude. Set result and stop processing.
+                        result = false;
+                        break;
+                    }
+                }
+                // check for exact match
+                else if ( repo.equals( originalId ) )
+                {
+                    result = true;
+                    break;
+                }
+                // check for external:*
+                else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository ) )
+                {
+                    result = true;
+                    // don't stop processing in case a future segment explicitly excludes this repo
+                }
+                else if ( WILDCARD.equals( repo ) )
+                {
+                    result = true;
+                    // don't stop processing in case a future segment explicitly excludes this repo
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Checks the URL to see if this repository refers to an external repository
+     *
+     * @param originalRepository
+     * @return true if external.
+     */
+    static boolean isExternalRepo( ArtifactRepository originalRepository )
+    {
+        try
+        {
+            URL url = new URL( originalRepository.getUrl() );
+            return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) || url.getProtocol().equals( "file" ) );
+        }
+        catch ( MalformedURLException e )
+        {
+            // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it
+            return false;
+        }
+    }
+
+    static boolean matchesLayout( ArtifactRepository repository, Mirror mirror )
+    {
+        return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() );
+    }
+
+    /**
+     * Checks whether the layouts configured for a mirror match with the layout of the repository.
+     *
+     * @param repoLayout The layout of the repository, may be {@code null}.
+     * @param mirrorLayout The layouts supported by the mirror, may be {@code null}.
+     * @return {@code true} if the layouts associated with the mirror match the layout of the original repository,
+     *         {@code false} otherwise.
+     */
+    static boolean matchesLayout( String repoLayout, String mirrorLayout )
+    {
+        boolean result = false;
+
+        // simple checks first to short circuit processing below.
+        if ( StringUtils.isEmpty( mirrorLayout ) || WILDCARD.equals( mirrorLayout ) )
+        {
+            result = true;
+        }
+        else if ( mirrorLayout.equals( repoLayout ) )
+        {
+            result = true;
+        }
+        else
+        {
+            // process the list
+            String[] layouts = mirrorLayout.split( "," );
+            for ( String layout : layouts )
+            {
+                // see if this is a negative match
+                if ( layout.length() > 1 && layout.startsWith( "!" ) )
+                {
+                    if ( layout.substring( 1 ).equals( repoLayout ) )
+                    {
+                        // explicitly exclude. Set result and stop processing.
+                        result = false;
+                        break;
+                    }
+                }
+                // check for exact match
+                else if ( layout.equals( repoLayout ) )
+                {
+                    result = true;
+                    break;
+                }
+                else if ( WILDCARD.equals( layout ) )
+                {
+                    result = true;
+                    // don't stop processing in case a future segment explicitly excludes this repo
+                }
+            }
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
index 1feebab..a7e93a8 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
@@ -24,11 +24,14 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Repository;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.SettingsUtils;
@@ -111,11 +114,27 @@ public class DefaultMavenExecutionRequestPopulator
         for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
         {
             request.addProfile( SettingsUtils.convertFromSettingsProfile( rawProfile ) );
+            
+            if(settings.getActiveProfiles().contains( rawProfile.getId() ))
+            {
+                List<Repository> remoteRepositories = rawProfile.getRepositories();
+                for( Repository remoteRepository : remoteRepositories )
+                {
+                    try
+                    {
+                        request.addRemoteRepository( MavenRepositorySystem.buildArtifactRepository( remoteRepository ) );
+                    }
+                    catch ( InvalidRepositoryException e )
+                    {
+                        // do nothing for now
+                    }
+                }
+            }
         }
 
         return request;
-    }
-
+    }    
+    
     private void populateDefaultPluginGroups( MavenExecutionRequest request )
     {
         request.addPluginGroup( "org.apache.maven.plugins" );

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
index 2b9444f..6f26ec4 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
@@ -19,6 +19,9 @@ package org.apache.maven.project;
  * under the License.
  */
 
+import java.io.File;
+import java.util.List;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -28,9 +31,6 @@ import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
-import java.io.File;
-import java.util.List;
-
 @SuppressWarnings( "deprecation" )
 @Component( role = MavenProjectHelper.class )
 public class DefaultMavenProjectHelper
@@ -40,8 +40,7 @@ public class DefaultMavenProjectHelper
     @Requirement
     private ArtifactHandlerManager artifactHandlerManager;
 
-    public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier,
-                                File artifactFile )
+    public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile )
     {
         String type = artifactType;
 
@@ -81,8 +80,9 @@ public class DefaultMavenProjectHelper
     {
         Artifact projectArtifact = project.getArtifact();
 
-        Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier,
-                                                  projectArtifact.getArtifactHandler() );
+        Artifact artifact =
+            new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier,
+                                  projectArtifact.getArtifactHandler() );
 
         artifact.setFile( artifactFile );
         artifact.setResolved( true );
@@ -92,6 +92,7 @@ public class DefaultMavenProjectHelper
 
     /**
      * Add an attached artifact or replace the file for an existing artifact.
+     * 
      * @see MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact)
      * @param project project reference.
      * @param artifact artifact to add or replace.
@@ -101,7 +102,8 @@ public class DefaultMavenProjectHelper
         project.addAttachedArtifact( artifact );
     }
 
-    public void addResource( MavenProject project, String resourceDirectory, List<String> includes, List<String> excludes )
+    public void addResource( MavenProject project, String resourceDirectory, List<String> includes,
+                             List<String> excludes )
     {
         Resource resource = new Resource();
         resource.setDirectory( resourceDirectory );
@@ -111,7 +113,8 @@ public class DefaultMavenProjectHelper
         project.addResource( resource );
     }
 
-    public void addTestResource( MavenProject project, String resourceDirectory, List<String> includes, List<String> excludes )
+    public void addTestResource( MavenProject project, String resourceDirectory, List<String> includes,
+                                 List<String> excludes )
     {
         Resource resource = new Resource();
         resource.setDirectory( resourceDirectory );

http://git-wip-us.apache.org/repos/asf/maven/blob/6cf93209/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index c5d7c51..32786ae 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -32,10 +33,20 @@ import java.util.Set;
 
 import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager;
+import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.model.Build;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.DeploymentRepository;
+import org.apache.maven.model.Extension;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Profile;
+import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.model.building.DefaultModelBuildingRequest;
 import org.apache.maven.model.building.DefaultModelProblem;
 import org.apache.maven.model.building.FileModelSource;
@@ -48,7 +59,6 @@ import org.apache.maven.model.building.ModelProcessor;
 import org.apache.maven.model.building.ModelSource;
 import org.apache.maven.model.building.StringModelSource;
 import org.apache.maven.model.resolution.ModelResolver;
-import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -87,7 +97,7 @@ public class DefaultProjectBuilder
     private ProjectBuildingHelper projectBuildingHelper;
 
     @Requirement
-    private RepositorySystem repositorySystem;
+    private MavenRepositorySystem repositorySystem;
 
     @Requirement
     private org.eclipse.aether.RepositorySystem repoSystem;
@@ -121,9 +131,9 @@ public class DefaultProjectBuilder
 
         try
         {
-            ProjectBuildingRequest configuration = config.request;
+            ProjectBuildingRequest projectBuildingRequest = config.request;            
 
-            MavenProject project = configuration.getProject();
+            MavenProject project = projectBuildingRequest.getProject();
 
             List<ModelProblem> modelProblems = null;
             Throwable error = null;
@@ -132,10 +142,10 @@ public class DefaultProjectBuilder
             {
                 ModelBuildingRequest request = getModelBuildingRequest( config );
 
-                project = new MavenProject( repositorySystem, this, configuration, logger );
+                project = new MavenProject();
 
                 DefaultModelBuildingListener listener =
-                    new DefaultModelBuildingListener( project, projectBuildingHelper, configuration );
+                    new DefaultModelBuildingListener( project, projectBuildingHelper, projectBuildingRequest );
                 request.setModelBuildingListener( listener );
 
                 request.setPomFile( pomFile );
@@ -161,16 +171,16 @@ public class DefaultProjectBuilder
                 modelProblems = result.getProblems();
 
                 initProject( project, Collections.<String, MavenProject> emptyMap(), result,
-                             new HashMap<File, Boolean>() );
+                             new HashMap<File, Boolean>(), projectBuildingRequest );
             }
-            else if ( configuration.isResolveDependencies() )
+            else if ( projectBuildingRequest.isResolveDependencies() )
             {
                 projectBuildingHelper.selectProjectRealm( project );
             }
 
             DependencyResolutionResult resolutionResult = null;
 
-            if ( configuration.isResolveDependencies() )
+            if ( projectBuildingRequest.isResolveDependencies() )
             {
                 resolutionResult = resolveDependencies( project, config.session );
             }
@@ -437,7 +447,7 @@ public class DefaultProjectBuilder
 
         ModelBuildingRequest request = getModelBuildingRequest( config );
 
-        MavenProject project = new MavenProject( repositorySystem, this, config.request, logger );
+        MavenProject project = new MavenProject();
 
         request.setPomFile( pomFile );
         request.setTwoPhaseBuilding( true );
@@ -484,7 +494,8 @@ public class DefaultProjectBuilder
                     {
                         ModelProblem problem =
                             new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
-                                + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1, -1, null );
+                                + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1,
+                                                     -1, null );
                         result.getProblems().add( problem );
 
                         noErrors = false;
@@ -520,8 +531,8 @@ public class DefaultProjectBuilder
 
                         ModelProblem problem =
                             new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
-                                + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1, -1,
-                                                     null );
+                                + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR,
+                                                     ModelProblem.Version.BASE, model, -1, -1, null );
                         result.getProblems().add( problem );
 
                         noErrors = false;
@@ -602,7 +613,7 @@ public class DefaultProjectBuilder
                 ModelBuildingResult result = modelBuilder.build( interimResult.request, interimResult.result );
 
                 MavenProject project = interimResult.listener.getProject();
-                initProject( project, projectIndex, result, profilesXmls );
+                initProject( project, projectIndex, result, profilesXmls, request );
 
                 List<MavenProject> modules = new ArrayList<MavenProject>();
                 noErrors =
@@ -628,19 +639,59 @@ public class DefaultProjectBuilder
     }
 
     private void initProject( MavenProject project, Map<String, MavenProject> projects, ModelBuildingResult result,
-                              Map<File, Boolean> profilesXmls )
+                              Map<File, Boolean> profilesXmls, ProjectBuildingRequest projectBuildingRequest )
     {
         Model model = result.getEffectiveModel();
 
         project.setModel( model );
         project.setOriginalModel( result.getRawModel() );
-
         project.setFile( model.getPomFile() );
-
-        File parentPomFile = result.getRawModel( result.getModelIds().get( 1 ) ).getPomFile();
-        project.setParentFile( parentPomFile );
-
-        project.setParent( projects.get( result.getModelIds().get( 1 ) ) );
+        Parent p = model.getParent();
+        if ( p != null )
+        {
+            project.setParentArtifact( repositorySystem.createProjectArtifact( p.getGroupId(), p.getArtifactId(),
+                                                                               p.getVersion() ) );
+            // org.apache.maven.its.mng4834:parent:0.1
+            String parentModelId = result.getModelIds().get( 1 );
+            File parentPomFile = result.getRawModel( parentModelId ).getPomFile();
+            MavenProject parent = projects.get( parentModelId );
+            if ( parent == null )
+            {
+                //
+                // At this point the DefaultModelBuildingListener has fired and it populates the
+                // remote repositories with those found in the pom.xml, along with the existing externally
+                // defined repositories.
+                //
+                projectBuildingRequest.setRemoteRepositories( project.getRemoteArtifactRepositories() );
+                if ( parentPomFile != null )
+                {
+                    project.setParentFile( parentPomFile );
+                    try
+                    {
+                        parent = build( parentPomFile, projectBuildingRequest ).getProject();
+                    }
+                    catch ( ProjectBuildingException e )
+                    {
+                        // MNG-4488 where let invalid parents slide on by
+                        logger.warn( "Failed to build parent project for " + project.getId() );
+                    }
+                }
+                else
+                {
+                    Artifact parentArtifact = project.getParentArtifact();
+                    try
+                    {
+                        parent = build( parentArtifact, projectBuildingRequest ).getProject();
+                    }
+                    catch ( ProjectBuildingException e )
+                    {
+                        // MNG-4488 where let invalid parents slide on by
+                        logger.warn( "Failed to build parent project for " + project.getId() );
+                    }
+                }
+            }
+            project.setParent( parent );
+        }
 
         Artifact projectArtifact =
             repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null,
@@ -675,6 +726,145 @@ public class DefaultProjectBuilder
                                          ModelProblem.Severity.WARNING, ModelProblem.Version.V30, model, -1, -1, null );
             result.getProblems().add( problem );
         }
+
+        //
+        // All the parts that were taken out of MavenProject for Maven 4.0.0
+        //
+        
+        project.setProjectBuildingRequest( projectBuildingRequest );
+        
+        // pluginArtifacts
+        Set<Artifact> pluginArtifacts = new HashSet<Artifact>();
+        for ( Plugin plugin : project.getBuildPlugins() )
+        {
+            Artifact artifact = repositorySystem.createPluginArtifact( plugin );
+
+            if ( artifact != null )
+            {
+                pluginArtifacts.add( artifact );
+            }
+        }
+        project.setPluginArtifacts( pluginArtifacts );
+
+        // reportArtifacts
+        Set<Artifact> reportArtifacts = new HashSet<Artifact>();
+        for ( ReportPlugin report : project.getReportPlugins() )
+        {
+            Plugin pp = new Plugin();
+            pp.setGroupId( report.getGroupId() );
+            pp.setArtifactId( report.getArtifactId() );
+            pp.setVersion( report.getVersion() );
+
+            Artifact artifact = repositorySystem.createPluginArtifact( pp );
+
+            if ( artifact != null )
+            {
+                reportArtifacts.add( artifact );
+            }
+        }
+        project.setReportArtifacts( reportArtifacts );
+
+        // extensionArtifacts
+        Set<Artifact> extensionArtifacts = new HashSet<Artifact>();
+        List<Extension> extensions = project.getBuildExtensions();
+        if ( extensions != null )
+        {
+            for ( Extension ext : extensions )
+            {
+                String version;
+                if ( StringUtils.isEmpty( ext.getVersion() ) )
+                {
+                    version = "RELEASE";
+                }
+                else
+                {
+                    version = ext.getVersion();
+                }
+
+                Artifact artifact =
+                    repositorySystem.createArtifact( ext.getGroupId(), ext.getArtifactId(), version, null, "jar" );
+
+                if ( artifact != null )
+                {
+                    extensionArtifacts.add( artifact );
+                }
+            }
+        }
+        project.setExtensionArtifacts( extensionArtifacts );
+
+        // managedVersionMap
+        Map<String, Artifact> map = null;
+        if ( repositorySystem != null )
+        {
+            List<Dependency> deps;
+            DependencyManagement dependencyManagement = project.getDependencyManagement();
+            if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null )
+                && ( deps.size() > 0 ) )
+            {
+                map = new HashMap<String, Artifact>();
+                for ( Dependency d : dependencyManagement.getDependencies() )
+                {
+                    Artifact artifact = repositorySystem.createDependencyArtifact( d );
+
+                    if ( artifact == null )
+                    {
+                        map = Collections.emptyMap();
+                    }
+
+                    map.put( d.getManagementKey(), artifact );
+                }
+            }
+            else
+            {
+                map = Collections.emptyMap();
+            }
+        }
+        project.setManagedVersionMap( map );
+
+        // release artifact repository
+        if ( project.getDistributionManagement() != null && project.getDistributionManagement().getRepository() != null )
+        {
+            try
+            {
+                DeploymentRepository r = project.getDistributionManagement().getRepository();
+                if ( !StringUtils.isEmpty( r.getId() ) && !StringUtils.isEmpty( r.getUrl() ) )
+                {
+                    ArtifactRepository repo =
+                        repositorySystem.buildArtifactRepository( project.getDistributionManagement().getRepository() );
+                    repositorySystem.injectProxy( projectBuildingRequest.getRepositorySession(), Arrays.asList( repo ) );
+                    repositorySystem.injectAuthentication( projectBuildingRequest.getRepositorySession(), Arrays.asList( repo ) );
+                    project.setReleaseArtifactRepository( repo );
+                }
+            }
+            catch ( InvalidRepositoryException e )
+            {
+                throw new IllegalStateException( "Failed to create release distribution repository for "
+                    + project.getId(), e );
+            }
+        }
+
+        // snapshot artifact repository
+        if ( project.getDistributionManagement() != null
+            && project.getDistributionManagement().getSnapshotRepository() != null )
+        {
+            try
+            {
+                DeploymentRepository r = project.getDistributionManagement().getSnapshotRepository();
+                if ( !StringUtils.isEmpty( r.getId() ) && !StringUtils.isEmpty( r.getUrl() ) )
+                {
+                    ArtifactRepository repo =
+                        repositorySystem.buildArtifactRepository( project.getDistributionManagement().getSnapshotRepository() );
+                    repositorySystem.injectProxy( projectBuildingRequest.getRepositorySession(), Arrays.asList( repo ) );
+                    repositorySystem.injectAuthentication( projectBuildingRequest.getRepositorySession(), Arrays.asList( repo ) );
+                    project.setSnapshotArtifactRepository( repo );
+                }
+            }
+            catch ( InvalidRepositoryException e )
+            {
+                throw new IllegalStateException( "Failed to create snapshot distribution repository for "
+                    + project.getId(), e );
+            }
+        }
     }
 
     private String findProfilesXml( ModelBuildingResult result, Map<File, Boolean> profilesXmls )