[MNG-6311] Implement class-level ModelCache in DefaultProjectBuilder to solve slow pom resolutions

Fix by: David Churcher
This commit is contained in:
Sylwester Lachiewicz 2017-11-24 00:56:00 +01:00
parent 01f098efd1
commit 8bc3c207d0
2 changed files with 17 additions and 12 deletions

View File

@ -105,6 +105,8 @@ public class DefaultProjectBuilder
@Requirement
private ProjectDependenciesResolver dependencyResolver;
private final ReactorModelCache modelCache = new ReactorModelCache();
// ----------------------------------------------------------------------
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
@ -113,14 +115,14 @@ public class DefaultProjectBuilder
public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request )
throws ProjectBuildingException
{
return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null, null ) );
return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null ) );
}
@Override
public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request )
throws ProjectBuildingException
{
return build( null, modelSource, new InternalConfig( request, null, null ) );
return build( null, modelSource, new InternalConfig( request, null ) );
}
private ProjectBuildingResult build( File pomFile, ModelSource modelSource, InternalConfig config )
@ -291,7 +293,7 @@ public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P
org.eclipse.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact );
pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact );
InternalConfig config = new InternalConfig( request, null, null );
InternalConfig config = new InternalConfig( request, null );
boolean localProject;
@ -353,9 +355,7 @@ public List<ProjectBuildingResult> build( List<File> pomFiles, boolean recursive
ReactorModelPool modelPool = new ReactorModelPool();
ReactorModelCache modelCache = new ReactorModelCache();
InternalConfig config = new InternalConfig( request, modelPool, modelCache );
InternalConfig config = new InternalConfig( request, modelPool );
Map<String, MavenProject> projectIndex = new HashMap<>( 256 );
@ -943,11 +943,11 @@ class InternalConfig
private final ReactorModelCache modelCache;
InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool, ReactorModelCache modelCache )
InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool )
{
this.request = request;
this.modelPool = modelPool;
this.modelCache = modelCache;
this.modelCache = getModelCache();
session =
LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(),
repoSystem );
@ -956,4 +956,9 @@ class InternalConfig
}
private ReactorModelCache getModelCache()
{
return this.modelCache;
}
}

View File

@ -19,11 +19,11 @@
* under the License.
*/
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.model.building.ModelCache;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* A simple model cache used to accelerate model building during a reactor build.
*
@ -33,7 +33,7 @@ class ReactorModelCache
implements ModelCache
{
private final Map<CacheKey, Object> models = new HashMap<>( 256 );
private final Map<CacheKey, Object> models = new ConcurrentHashMap<>( 256 );
public Object get( String groupId, String artifactId, String version, String tag )
{