[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:
Stefan Oehme 2019-04-14 13:47:05 +02:00 committed by Michael Osipov
parent 6c01ec18cb
commit d3ace78602
2 changed files with 19 additions and 4 deletions

View File

@ -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;

View File

@ -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 )
{