mirror of https://github.com/apache/maven.git
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:
parent
4f8225545e
commit
bf3c9c2a02
|
@ -23,11 +23,13 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
//import org.apache.maven.model.Model;
|
||||
//import org.apache.maven.model.Parent;
|
||||
//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.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -40,7 +42,10 @@ import java.util.Set;
|
|||
public class MavenMetadataSource
|
||||
implements ArtifactMetadataSource
|
||||
{
|
||||
private MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
|
||||
private MavenProjectBuilder mavenProjectBuilder;
|
||||
|
||||
// private MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
|
@ -50,11 +55,14 @@ public class MavenMetadataSource
|
|||
|
||||
public MavenMetadataSource( Set remoteRepositories,
|
||||
ArtifactRepository localRepository,
|
||||
ArtifactResolver artifactResolver )
|
||||
ArtifactResolver artifactResolver,
|
||||
MavenProjectBuilder projectBuilder )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
|
||||
this.artifactResolver = artifactResolver;
|
||||
|
||||
this.mavenProjectBuilder = projectBuilder;
|
||||
|
||||
this.remoteRepositories = remoteRepositories;
|
||||
}
|
||||
|
@ -73,9 +81,13 @@ public class MavenMetadataSource
|
|||
{
|
||||
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 )
|
||||
{
|
||||
|
@ -89,20 +101,10 @@ public class MavenMetadataSource
|
|||
return artifacts;
|
||||
}
|
||||
|
||||
public Set createArtifacts( Model model, ArtifactRepository localRepository )
|
||||
public Set createArtifacts( List dependencies, ArtifactRepository localRepository )
|
||||
{
|
||||
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(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
|||
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
@ -70,16 +71,21 @@ public class DependencyResolutionPhase
|
|||
throws Exception
|
||||
{
|
||||
ArtifactResolver artifactResolver = null;
|
||||
|
||||
MavenProjectBuilder projectBuilder = null;
|
||||
|
||||
try
|
||||
{
|
||||
MavenProject project = context.getProject();
|
||||
|
||||
artifactResolver = (ArtifactResolver) context.lookup( ArtifactResolver.ROLE );
|
||||
|
||||
projectBuilder = (MavenProjectBuilder) context.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
MavenMetadataSource sourceReader = new MavenMetadataSource( context.getRemoteRepositories(),
|
||||
context.getLocalRepository(),
|
||||
artifactResolver );
|
||||
artifactResolver,
|
||||
projectBuilder );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
||||
context.getRemoteRepositories(),
|
||||
|
@ -91,6 +97,8 @@ public class DependencyResolutionPhase
|
|||
finally
|
||||
{
|
||||
context.release( artifactResolver );
|
||||
|
||||
context.release( projectBuilder );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.maven.lifecycle.session.MavenSession;
|
|||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.codehaus.plexus.ArtifactEnabledContainer;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -70,6 +71,8 @@ public class DefaultPluginManager
|
|||
protected Set remotePluginRepositories;
|
||||
|
||||
protected ArtifactFilter artifactFilter;
|
||||
|
||||
protected MavenProjectBuilder mavenProjectBuilder;
|
||||
|
||||
public DefaultPluginManager()
|
||||
{
|
||||
|
@ -208,10 +211,13 @@ public class DefaultPluginManager
|
|||
throws Exception
|
||||
{
|
||||
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
|
||||
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
MavenMetadataSource metadataSource = new MavenMetadataSource( remotePluginRepositories,
|
||||
session.getLocalRepository(),
|
||||
artifactResolver );
|
||||
artifactResolver,
|
||||
mavenProjectBuilder );
|
||||
|
||||
( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact,
|
||||
artifactResolver,
|
||||
|
|
|
@ -143,7 +143,7 @@ public class DefaultMavenProjectBuilder
|
|||
Set repos = RepositoryUtils.mavenToWagon( project.getRepositories() );
|
||||
|
||||
MavenMetadataSource sourceReader = new MavenMetadataSource( repos, localRepository,
|
||||
artifactResolver );
|
||||
artifactResolver, this );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project
|
||||
.getArtifacts(), repos, localRepository, sourceReader );
|
||||
|
|
Loading…
Reference in New Issue