o Fixed critical performance regression introduced in r801648. The relocation is now grabbed alongside the direct dependencies when we get the resolution group, these bits are stored in the same file and so we can as well process them in one go.

Issue id: o


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@802251 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-07 22:17:19 +00:00
parent 5c3cb94678
commit 09d93a0b6a
12 changed files with 76 additions and 134 deletions

View File

@ -122,6 +122,11 @@ public final class ArtifactUtils
return artifactMap;
}
public static Artifact copyArtifactSafe( Artifact artifact )
{
return ( artifact != null ) ? copyArtifact( artifact ) : null;
}
public static Artifact copyArtifact( Artifact artifact )
{
VersionRange range = artifact.getVersionRange();

View File

@ -33,10 +33,10 @@ public class ResolutionGroup
super( pomArtifact, artifacts, resolutionRepositories );
}
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions,
List<ArtifactRepository> resolutionRepositories )
public ResolutionGroup( Artifact pomArtifact, Artifact relocatedArtifact, Set<Artifact> artifacts,
Map<String, Artifact> managedVersions, List<ArtifactRepository> resolutionRepositories )
{
super( pomArtifact, artifacts, managedVersions, resolutionRepositories );
super( pomArtifact, relocatedArtifact, artifacts, managedVersions, resolutionRepositories );
}
}

View File

@ -72,11 +72,4 @@ public interface ArtifactMetadataSource
List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException;
/**
* Resolve all relocations in the POM for this artifact, and return the new artifact coordinate.
*/
Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException;
}

View File

@ -35,18 +35,21 @@ public class ResolutionGroup
private final Artifact pomArtifact;
private final Artifact relocatedArtifact;
private final Map<String, Artifact> managedVersions;
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts,
List<ArtifactRepository> resolutionRepositories )
{
this( pomArtifact, artifacts, null, resolutionRepositories );
this( pomArtifact, null, artifacts, null, resolutionRepositories );
}
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions,
List<ArtifactRepository> resolutionRepositories )
public ResolutionGroup( Artifact pomArtifact, Artifact relocatedArtifact, Set<Artifact> artifacts,
Map<String, Artifact> managedVersions, List<ArtifactRepository> resolutionRepositories )
{
this.pomArtifact = pomArtifact;
this.relocatedArtifact = relocatedArtifact;
this.artifacts = artifacts;
this.managedVersions = managedVersions;
this.resolutionRepositories = resolutionRepositories;
@ -57,6 +60,11 @@ public class ResolutionGroup
return pomArtifact;
}
public Artifact getRelocatedArtifact()
{
return relocatedArtifact;
}
public Set<Artifact> getArtifacts()
{
return artifacts;

View File

@ -400,6 +400,8 @@ public class DefaultLegacyArtifactCollector
try
{
ResolutionGroup rGroup;
Object childKey;
do
{
@ -481,9 +483,14 @@ public class DefaultLegacyArtifactCollector
fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child );
}
Artifact relocated =
source.retrieveRelocatedArtifact( artifact, localRepository,
childRemoteRepositories );
rGroup = source.retrieve( artifact, localRepository, childRemoteRepositories );
if ( rGroup == null )
{
break;
}
Artifact relocated = rGroup.getRelocatedArtifact();
if ( relocated != null && !artifact.equals( relocated ) )
{
relocated.setDependencyFilter( artifact.getDependencyFilter() );
@ -504,8 +511,6 @@ public class DefaultLegacyArtifactCollector
continue;
}
ResolutionGroup rGroup = source.retrieve( artifact, localRepository, childRemoteRepositories );
// TODO might be better to have source.retrieve() throw a specific exception for this
// situation
// and catch here rather than have it return null

View File

@ -57,14 +57,6 @@ public class SimpleArtifactMetadataSource
return Collections.<ArtifactVersion>singletonList( new DefaultArtifactVersion( "10.1.3" ) );
}
public Artifact retrieveRelocatedArtifact( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
return artifact;
}
public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{

View File

@ -69,12 +69,6 @@ public class TestMetadataSource
throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
}
public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
return artifact;
}
public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{

View File

@ -217,14 +217,6 @@ public class ArtifactResolverTest
throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
}
public Artifact retrieveRelocatedArtifact( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
return artifact;
}
public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{

View File

@ -969,14 +969,6 @@ public class DefaultArtifactCollectorTest
return artifactVersions;
}
public Artifact retrieveRelocatedArtifact( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
return artifact;
}
public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{

View File

@ -72,12 +72,6 @@ public class TestMetadataSource
throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
}
public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
return artifact;
}
public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{

View File

@ -126,6 +126,7 @@ public class DefaultMavenMetadataCache
public class CacheRecord
{
private Artifact pomArtifact;
private Artifact relocatedArtifact;
private List<Artifact> artifacts;
private Map<String, Artifact> managedVersions;
private List<ArtifactRepository> remoteRepositories;
@ -133,9 +134,11 @@ public class DefaultMavenMetadataCache
private long length;
private long timestamp;
CacheRecord(Artifact pomArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions, List<ArtifactRepository> remoteRepositories)
CacheRecord( Artifact pomArtifact, Artifact relocatedArtifact, Set<Artifact> artifacts,
Map<String, Artifact> managedVersions, List<ArtifactRepository> remoteRepositories )
{
this.pomArtifact = ArtifactUtils.copyArtifact( pomArtifact );
this.relocatedArtifact = ArtifactUtils.copyArtifactSafe( relocatedArtifact );
this.artifacts = ArtifactUtils.copyArtifacts( artifacts, new ArrayList<Artifact>() );
this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
@ -158,12 +161,17 @@ public class DefaultMavenMetadataCache
this.timestamp = -1;
}
}
public Artifact getArtifact()
{
return pomArtifact;
}
public Artifact getRelocatedArtifact()
{
return relocatedArtifact;
}
public List<Artifact> getArtifacts()
{
return artifacts;
@ -203,6 +211,7 @@ public class DefaultMavenMetadataCache
if ( cacheRecord != null && !cacheRecord.isStale() )
{
Artifact pomArtifact = ArtifactUtils.copyArtifact( cacheRecord.getArtifact() );
Artifact relocatedArtifact = ArtifactUtils.copyArtifactSafe( cacheRecord.getRelocatedArtifact() );
Set<Artifact> artifacts =
ArtifactUtils.copyArtifacts( cacheRecord.getArtifacts(), new LinkedHashSet<Artifact>() );
Map<String, Artifact> managedVersions = cacheRecord.getManagedVersions();
@ -210,7 +219,8 @@ public class DefaultMavenMetadataCache
{
managedVersions = ArtifactUtils.copyArtifacts( managedVersions, new LinkedHashMap<String, Artifact>() );
}
return new ResolutionGroup( pomArtifact, artifacts, managedVersions, cacheRecord.getRemoteRepositories() );
return new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions,
cacheRecord.getRemoteRepositories() );
}
cache.remove( cacheKey );
@ -223,8 +233,8 @@ public class DefaultMavenMetadataCache
{
CacheKey cacheKey = new CacheKey( artifact, resolveManagedVersions, localRepository, remoteRepositories );
CacheRecord cacheRecord =
new CacheRecord( result.getPomArtifact(), result.getArtifacts(), result.getManagedVersions(),
result.getResolutionRepositories() );
new CacheRecord( result.getPomArtifact(), result.getRelocatedArtifact(), result.getArtifacts(),
result.getManagedVersions(), result.getResolutionRepositories() );
cache.put( cacheKey, cacheRecord );
}

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@ -127,6 +128,8 @@ public class MavenMetadataSource
Artifact pomArtifact;
Artifact relocatedArtifact = null;
//TODO: Not even sure this is really required as the project will be cached in the builder, we'll see this
// is currently the biggest hotspot
if ( artifact instanceof ArtifactWithDependencies )
@ -157,6 +160,8 @@ public class MavenMetadataSource
}
else
{
relocatedArtifact = rel.relocatedArtifact;
dependencies = rel.project.getDependencies();
DependencyManagement depMngt = rel.project.getDependencyManagement();
@ -195,7 +200,8 @@ public class MavenMetadataSource
}
}
ResolutionGroup result = new ResolutionGroup( pomArtifact, artifacts, managedVersions, remoteRepositories );
ResolutionGroup result =
new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, remoteRepositories );
cache.put( artifact, resolveManagedVersions, localRepository, remoteRepositories, result );
@ -410,63 +416,6 @@ public class MavenMetadataSource
return projectBuilder;
}
public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
ProjectRelocation rel = retrieveRelocatedProject( artifact, localRepository, remoteRepositories );
if ( rel == null )
{
return artifact;
}
MavenProject project = rel.project;
if ( project == null || getRelocationKey( artifact ).equals( getRelocationKey( project.getArtifact() ) ) )
{
return artifact;
}
// NOTE: Using artifact information here, since some POMs are deployed
// to central with one version in the filename, but another in the <version> string!
// Case in point: org.apache.ws.commons:XmlSchema:1.1:pom.
//
// Since relocation triggers a reconfiguration of the artifact's information
// in retrieveRelocatedProject(..), this is safe to do.
Artifact result = null;
if ( artifact.getClassifier() != null )
{
result =
repositorySystem.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getType(),
artifact.getClassifier() );
}
else
{
result =
repositorySystem.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getScope(), artifact.getType() );
}
result.setResolved( artifact.isResolved() );
result.setFile( artifact.getFile() );
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
@ -474,20 +423,21 @@ public class MavenMetadataSource
MavenProject project = null;
Artifact pomArtifact;
Artifact relocatedArtifact = artifact;
boolean done = false;
do
{
// TODO: can we just modify the original?
pomArtifact =
repositorySystem.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getScope() );
repositorySystem.createProjectArtifact( relocatedArtifact.getGroupId(),
relocatedArtifact.getArtifactId(),
relocatedArtifact.getVersion(), relocatedArtifact.getScope() );
if ( "pom".equals( artifact.getType() ) )
if ( "pom".equals( relocatedArtifact.getType() ) )
{
pomArtifact.setFile( artifact.getFile() );
pomArtifact.setFile( relocatedArtifact.getFile() );
}
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
if ( Artifact.SCOPE_SYSTEM.equals( relocatedArtifact.getScope() ) )
{
done = true;
}
@ -495,7 +445,6 @@ public class MavenMetadataSource
{
try
{
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
configuration.setLocalRepository( localRepository );
configuration.setRemoteRepositories( remoteRepositories );
@ -520,31 +469,36 @@ public class MavenMetadataSource
{
relocation = distMgmt.getRelocation();
artifact.setDownloadUrl( distMgmt.getDownloadUrl() );
relocatedArtifact.setDownloadUrl( distMgmt.getDownloadUrl() );
pomArtifact.setDownloadUrl( distMgmt.getDownloadUrl() );
}
if ( relocation != null )
{
if ( relocatedArtifact == artifact )
{
relocatedArtifact = ArtifactUtils.copyArtifact( artifact );
}
if ( relocation.getGroupId() != null )
{
artifact.setGroupId( relocation.getGroupId() );
relocatedArtifact.setGroupId( relocation.getGroupId() );
project.setGroupId( relocation.getGroupId() );
}
if ( relocation.getArtifactId() != null )
{
artifact.setArtifactId( relocation.getArtifactId() );
relocatedArtifact.setArtifactId( relocation.getArtifactId() );
project.setArtifactId( relocation.getArtifactId() );
}
if ( relocation.getVersion() != null )
{
// note: see MNG-3454. This causes a problem, but fixing it may break more.
artifact.setVersionRange( VersionRange.createFromVersion( relocation.getVersion() ) );
relocatedArtifact.setVersionRange( VersionRange.createFromVersion( relocation.getVersion() ) );
project.setVersion( relocation.getVersion() );
}
if ( artifact.getDependencyFilter() != null
&& !artifact.getDependencyFilter().include( artifact ) )
&& !artifact.getDependencyFilter().include( relocatedArtifact ) )
{
return null;
}
@ -555,14 +509,14 @@ public class MavenMetadataSource
List<ArtifactVersion> available = artifact.getAvailableVersions();
if ( available != null && !available.isEmpty() )
{
artifact.setAvailableVersions( retrieveAvailableVersions( artifact, localRepository,
remoteRepositories ) );
available =
retrieveAvailableVersions( relocatedArtifact, localRepository, remoteRepositories );
relocatedArtifact.setAvailableVersions( available );
}
String message =
"\n This artifact has been relocated to " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ".\n";
"\n This artifact has been relocated to " + relocatedArtifact.getGroupId() + ":"
+ relocatedArtifact.getArtifactId() + ":" + relocatedArtifact.getVersion() + ".\n";
if ( relocation.getMessage() != null )
{
@ -596,6 +550,7 @@ public class MavenMetadataSource
ProjectRelocation rel = new ProjectRelocation();
rel.project = project;
rel.pomArtifact = pomArtifact;
rel.relocatedArtifact = ( relocatedArtifact == artifact ) ? null : relocatedArtifact;
return rel;
}
@ -605,6 +560,8 @@ public class MavenMetadataSource
private MavenProject project;
private Artifact pomArtifact;
private Artifact relocatedArtifact;
}
}