o create a test repository system that has the "special" retrieve method. i'll turn this into a proper test but this

exposed a bug in the plexus test metadata generation -- the production component along with the test component are                       
  put in the generated metadata and the last definition wins which knocks out my test component    


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@747618 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-02-25 00:04:51 +00:00
parent d4890344f8
commit df4430644b
6 changed files with 99 additions and 7 deletions

View File

@ -257,7 +257,7 @@ public class DefaultMavenProjectBuilder
.setMetadataSource( repositorySystem );
ArtifactResolutionResult result = repositorySystem.resolve( request );
project.setArtifacts( result.getArtifacts() );
return new MavenProjectBuildingResult( project, result );

View File

@ -1705,8 +1705,7 @@ public class MavenProject
ArtifactFilter dependencyFilter )
throws InvalidDependencyVersionException
{
return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope,
dependencyFilter, this );
return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope, dependencyFilter, this );
}
public void addProjectReference( MavenProject project )

View File

@ -29,6 +29,12 @@ public class ProjectClasspathTest
{
private String dir = "projects/scope/";
public void setUp() throws Exception
{
super.setUp();
projectBuilder = lookup(MavenProjectBuilder.class, "test");
}
public void testProjectClasspath()
throws Exception
{
@ -52,7 +58,6 @@ public class ProjectClasspathTest
artifact = getArtifact( project, "maven-test-test", "scope-test" );
assertNull( "Check no test dependencies are transitive", artifact );
artifact = getArtifact( project, "maven-test-test", "scope-compile" );
System.out.println( "a = " + artifact );
System.out.println( "b = " + artifact.getScope() );
@ -104,7 +109,8 @@ public class ProjectClasspathTest
}
private Artifact getArtifact( MavenProject project, String groupId, String artifactId )
{ System.out.println(groupId + ":" + artifactId);
{
System.out.println( "[ Looking for " + groupId + ":" + artifactId + " ]");
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();

View File

@ -62,7 +62,7 @@ public class TestArtifactResolver
@Requirement
private MavenRepositorySystem repositorySystem;
static class Source
implements ArtifactMetadataSource
{

View File

@ -0,0 +1,83 @@
package org.apache.maven.project;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.repository.LegacyMavenRepositorySystem;
import org.apache.maven.repository.MavenRepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@Component(role = MavenRepositorySystem.class, hint = "test")
public class TestMavenRepositorySystem
extends LegacyMavenRepositorySystem
{
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
Model model = null;
InputStreamReader r = null;
try
{
String scope = artifact.getArtifactId().substring( "scope-".length() );
if ( "maven-test".equals( artifact.getGroupId() ) )
{
String name = "/projects/scope/transitive-" + scope + "-dep.xml";
r = new InputStreamReader( getClass().getResourceAsStream( name ) );
MavenXpp3Reader reader = new MavenXpp3Reader();
model = reader.read( r );
}
else
{
model = new Model();
}
model.setGroupId( artifact.getGroupId() );
model.setArtifactId( artifact.getArtifactId() );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( e );
}
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( e );
}
finally
{
IOUtil.close( r );
}
Set artifacts;
try
{
artifacts = createArtifacts( model.getDependencies(), artifact.getScope(), null, null );
}
catch ( InvalidDependencyVersionException e )
{
throw new ArtifactMetadataRetrievalException( e );
}
List artifactRepositories;
try
{
artifactRepositories = buildArtifactRepositories( model.getRepositories() );
}
catch ( InvalidRepositoryException e )
{
throw new ArtifactMetadataRetrievalException( e );
}
return new ResolutionGroup( artifact, artifacts, artifactRepositories );
}
}

View File

@ -20,6 +20,7 @@ package org.apache.maven.project;
*/
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.repository.MavenRepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -28,5 +29,8 @@ public class TestProjectBuilder
extends DefaultMavenProjectBuilder
{
@Requirement(hint="test")
private ArtifactResolver artifactResolver;
private ArtifactResolver artifactResolver;
@Requirement(hint="test")
private MavenRepositorySystem repositorySystem;
}