mirror of https://github.com/apache/maven.git
[MNG-6638] Prevent reparsing POMs in MavenMetadataSource
If a dependency on another project is found, don't parse its POM again, but instead use the model we already have in memory. This saves a large amount of time and memory for builds that have lots of subprojects and dependencies between them. The approach was directly copied from DefaultArtifactDescriptorReader, which does the same optimization. This closes #244
This commit is contained in:
parent
6c01ec18cb
commit
d3ace78602
|
@ -32,6 +32,7 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.RepositoryUtils;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
|
@ -55,6 +56,7 @@ import org.apache.maven.artifact.versioning.VersionRange;
|
|||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.DistributionManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Relocation;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
|
@ -68,6 +70,7 @@ import org.apache.maven.project.ProjectBuildingException;
|
|||
import org.apache.maven.project.ProjectBuildingRequest;
|
||||
import org.apache.maven.properties.internal.EnvironmentUtils;
|
||||
import org.apache.maven.properties.internal.SystemProperties;
|
||||
import org.apache.maven.repository.internal.MavenWorkspaceReader;
|
||||
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
||||
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -77,6 +80,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
|
|||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.repository.RepositoryPolicy;
|
||||
import org.eclipse.aether.repository.WorkspaceReader;
|
||||
import org.eclipse.aether.transfer.ArtifactNotFoundException;
|
||||
|
||||
/**
|
||||
|
@ -174,9 +178,21 @@ public class MavenMetadataSource
|
|||
|
||||
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 )
|
||||
final WorkspaceReader workspace = legacySupport.getRepositorySession().getWorkspaceReader();
|
||||
Model model = null;
|
||||
if ( workspace instanceof MavenWorkspaceReader )
|
||||
{
|
||||
model = ( (MavenWorkspaceReader) workspace ).findModel( RepositoryUtils.toArtifact( artifact ) );
|
||||
}
|
||||
|
||||
if ( model != null )
|
||||
{
|
||||
pomArtifact = artifact;
|
||||
dependencies = model.getDependencies();
|
||||
DependencyManagement dependencyManagement = model.getDependencyManagement();
|
||||
managedDependencies = dependencyManagement == null ? null : dependencyManagement.getDependencies();
|
||||
}
|
||||
else if ( artifact instanceof ArtifactWithDependencies )
|
||||
{
|
||||
pomArtifact = artifact;
|
||||
|
||||
|
|
|
@ -257,7 +257,6 @@ public class DefaultArtifactDescriptorReader
|
|||
|
||||
Model model;
|
||||
|
||||
// hack: don't rebuild model if it was already loaded during reactor resolution
|
||||
final WorkspaceReader workspace = session.getWorkspaceReader();
|
||||
if ( workspace instanceof MavenWorkspaceReader )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue