diff --git a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java index 7708540f77..636a972735 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java @@ -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(); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/DependencyResolutionPhase.java b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/DependencyResolutionPhase.java index 6c0f439126..431374603e 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/DependencyResolutionPhase.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/DependencyResolutionPhase.java @@ -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 ); } } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index aaea291bc0..d5b1d4a8a8 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -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, diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index c902f25258..4d8fe6b842 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -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 );