[MNG-3380] Process relocations before attempting to resolve child nodes during artifact collection.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@675352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-07-09 21:44:10 +00:00
parent a3719ed76c
commit 3a52d33141
2 changed files with 89 additions and 7 deletions

View File

@ -89,16 +89,59 @@ public class MavenMetadataSource
private boolean strictlyEnforceThePresenceOfAValidMavenPOM = false;
/**
* Retrieve the metadata for the project from the repository.
* Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
* associated artifacts.
* Resolve all relocations in the POM for this artifact, and return the new artifact coordinate.
*/
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
public Artifact retrieveRelocatedArtifact( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
if ( artifact instanceof ActiveProjectArtifact )
{
return artifact;
}
ProjectRelocation res = retrieveRelocatedProject( artifact, localRepository, remoteRepositories );
MavenProject project = res.project;
if ( project == null || getRelocationKey( artifact ).equals( getRelocationKey( project.getArtifact() ) ) )
{
return artifact;
}
Artifact result = null;
if ( artifact.getClassifier() != null )
{
result = artifactFactory.createArtifactWithClassifier( project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getType(), artifact.getClassifier() );
}
else
{
result = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getScope(), artifact.getType() );
}
result.setScope( artifact.getScope() );
result.setArtifactHandler( artifact.getArtifactHandler() );
result.setDependencyFilter( artifact.getDependencyFilter() );
result.setDependencyTrail( artifact.getDependencyTrail() );
result.setOptional( artifact.isOptional() );
result.setRelease( artifact.isRelease() );
return result;
}
private String getRelocationKey( Artifact artifact )
{
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
}
private ProjectRelocation retrieveRelocatedProject( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
if ( remoteRepositories == null )
{
remoteRepositories = Collections.EMPTY_LIST;
remoteRepositories = Collections.emptyList();
}
try
@ -111,7 +154,6 @@ public class MavenMetadataSource
}
MavenProject project = null;
Artifact pomArtifact;
boolean done = false;
@ -181,14 +223,17 @@ public class MavenMetadataSource
if ( relocation.getGroupId() != null )
{
artifact.setGroupId( relocation.getGroupId() );
project.setGroupId( relocation.getGroupId() );
}
if ( relocation.getArtifactId() != null )
{
artifact.setArtifactId( relocation.getArtifactId() );
project.setArtifactId( relocation.getArtifactId() );
}
if ( relocation.getVersion() != null )
{
artifact.setVersionRange( VersionRange.createFromVersion( relocation.getVersion() ) );
project.setVersion( relocation.getVersion() );
}
if ( ( artifact.getDependencyFilter() != null ) &&
@ -239,6 +284,25 @@ public class MavenMetadataSource
}
while ( !done );
ProjectRelocation res = new ProjectRelocation();
res.project = project;
res.pomArtifact = pomArtifact;
return res;
}
/**
* Retrieve the metadata for the project from the repository.
* Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
* associated artifacts.
*/
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
ProjectRelocation res = retrieveRelocatedProject( artifact, localRepository, remoteRepositories );
MavenProject project = res.project;
Artifact pomArtifact = res.pomArtifact;
// last ditch effort to try to get this set...
if ( artifact.getDownloadUrl() == null )
{
@ -511,4 +575,11 @@ public class MavenMetadataSource
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
private static final class ProjectRelocation
{
private MavenProject project;
private Artifact pomArtifact;
}
}

View File

@ -189,6 +189,14 @@ public class TestArtifactResolver
return projectArtifacts;
}
public Artifact retrieveRelocatedArtifact( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
return artifact;
}
}
public Source source()
@ -199,12 +207,14 @@ public class TestArtifactResolver
/**
* @noinspection RefusedBequest
*/
@Override
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
artifact.setFile( new File( "dummy" ) );
}
@Override
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
@ -214,6 +224,7 @@ public class TestArtifactResolver
new Source( artifactFactory, repositoryFactory, container ), filter );
}
@Override
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
@ -226,7 +237,7 @@ public class TestArtifactResolver
public void contextualize( Context context )
throws ContextException
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}