o Replaced Model/MavenXpp3Reader with MavenProjectBuilder in MavenMetaDataSource,

to take advantage of the post-processing (managed dependencies, pom interpolation,
  inheritance assembly) involved with building a project. This shoud make transitive
  dependency resolution more consistent with the rest of m2's handling of
  POM information.

  It has been tested on marmalade in the jelly-core taglib, but
  I'm not sure how to setup an integration test using the it-verifier
  to build multiple POMs in a single test, so I'm not sure how to
  setup an integration test for this.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-02-04 04:02:10 +00:00
parent 4f8225545e
commit bf3c9c2a02
4 changed files with 38 additions and 22 deletions

View File

@ -23,11 +23,13 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model; //import org.apache.maven.model.Model;
import org.apache.maven.model.Parent; //import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import java.io.FileReader; //import java.io.FileReader;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -40,7 +42,10 @@ import java.util.Set;
public class MavenMetadataSource public class MavenMetadataSource
implements ArtifactMetadataSource implements ArtifactMetadataSource
{ {
private MavenXpp3Reader reader = new MavenXpp3Reader();
private MavenProjectBuilder mavenProjectBuilder;
// private MavenXpp3Reader reader = new MavenXpp3Reader();
private ArtifactRepository localRepository; private ArtifactRepository localRepository;
@ -50,12 +55,15 @@ public class MavenMetadataSource
public MavenMetadataSource( Set remoteRepositories, public MavenMetadataSource( Set remoteRepositories,
ArtifactRepository localRepository, ArtifactRepository localRepository,
ArtifactResolver artifactResolver ) ArtifactResolver artifactResolver,
MavenProjectBuilder projectBuilder )
{ {
this.localRepository = localRepository; this.localRepository = localRepository;
this.artifactResolver = artifactResolver; this.artifactResolver = artifactResolver;
this.mavenProjectBuilder = projectBuilder;
this.remoteRepositories = remoteRepositories; this.remoteRepositories = remoteRepositories;
} }
@ -73,9 +81,13 @@ public class MavenMetadataSource
{ {
artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository ); artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
Model model = reader.read( new FileReader( metadataArtifact.getFile() ) ); // [jdcasey/03-Feb-2005]: Replacing with ProjectBuilder, to enable
// post-processing and inheritance calculation before retrieving the
// associated artifacts. This should improve consistency.
MavenProject project = mavenProjectBuilder.build( metadataArtifact.getFile(), localRepository );
// Model model = reader.read( new FileReader( metadataArtifact.getFile() ) );
artifacts = createArtifacts( model, localRepository ); artifacts = createArtifacts( project.getDependencies(), localRepository );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
@ -89,20 +101,10 @@ public class MavenMetadataSource
return artifacts; return artifacts;
} }
public Set createArtifacts( Model model, ArtifactRepository localRepository ) public Set createArtifacts( List dependencies, ArtifactRepository localRepository )
{ {
Set projectArtifacts = new HashSet(); Set projectArtifacts = new HashSet();
Parent parent = model.getParent();
if(parent != null)
{
projectArtifacts.add( new DefaultArtifact( parent.getGroupId(),
parent.getArtifactId(),
parent.getVersion(),
"pom" ) );
}
List dependencies = model.getDependencies();
for ( Iterator i = dependencies.iterator(); i.hasNext(); ) for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{ {
Dependency d = (Dependency) i.next(); Dependency d = (Dependency) i.next();

View File

@ -25,6 +25,7 @@ import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext; import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import java.util.Iterator; import java.util.Iterator;
@ -71,15 +72,20 @@ public class DependencyResolutionPhase
{ {
ArtifactResolver artifactResolver = null; ArtifactResolver artifactResolver = null;
MavenProjectBuilder projectBuilder = null;
try try
{ {
MavenProject project = context.getProject(); MavenProject project = context.getProject();
artifactResolver = (ArtifactResolver) context.lookup( ArtifactResolver.ROLE ); artifactResolver = (ArtifactResolver) context.lookup( ArtifactResolver.ROLE );
projectBuilder = (MavenProjectBuilder) context.lookup( MavenProjectBuilder.ROLE );
MavenMetadataSource sourceReader = new MavenMetadataSource( context.getRemoteRepositories(), MavenMetadataSource sourceReader = new MavenMetadataSource( context.getRemoteRepositories(),
context.getLocalRepository(), context.getLocalRepository(),
artifactResolver ); artifactResolver,
projectBuilder );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(), ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
context.getRemoteRepositories(), context.getRemoteRepositories(),
@ -91,6 +97,8 @@ public class DependencyResolutionPhase
finally finally
{ {
context.release( artifactResolver ); context.release( artifactResolver );
context.release( projectBuilder );
} }
} }
} }

View File

@ -29,6 +29,7 @@ import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.ArtifactEnabledContainer; import org.codehaus.plexus.ArtifactEnabledContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
@ -71,6 +72,8 @@ public class DefaultPluginManager
protected ArtifactFilter artifactFilter; protected ArtifactFilter artifactFilter;
protected MavenProjectBuilder mavenProjectBuilder;
public DefaultPluginManager() public DefaultPluginManager()
{ {
mojoDescriptors = new HashMap(); mojoDescriptors = new HashMap();
@ -209,9 +212,12 @@ public class DefaultPluginManager
{ {
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE ); artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
MavenMetadataSource metadataSource = new MavenMetadataSource( remotePluginRepositories, MavenMetadataSource metadataSource = new MavenMetadataSource( remotePluginRepositories,
session.getLocalRepository(), session.getLocalRepository(),
artifactResolver ); artifactResolver,
mavenProjectBuilder );
( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, ( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact,
artifactResolver, artifactResolver,

View File

@ -143,7 +143,7 @@ public class DefaultMavenProjectBuilder
Set repos = RepositoryUtils.mavenToWagon( project.getRepositories() ); Set repos = RepositoryUtils.mavenToWagon( project.getRepositories() );
MavenMetadataSource sourceReader = new MavenMetadataSource( repos, localRepository, MavenMetadataSource sourceReader = new MavenMetadataSource( repos, localRepository,
artifactResolver ); artifactResolver, this );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project ArtifactResolutionResult result = artifactResolver.resolveTransitively( project
.getArtifacts(), repos, localRepository, sourceReader ); .getArtifacts(), repos, localRepository, sourceReader );