[maven] branch master updated: [MNG-6311] Implement class-level ModelCache in DefaultProjectBuilder to solve slow pom resolutions

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[maven] branch master updated: [MNG-6311] Implement class-level ModelCache in DefaultProjectBuilder to solve slow pom resolutions

slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 8bc3c20  [MNG-6311] Implement class-level ModelCache in DefaultProjectBuilder to solve slow pom resolutions
8bc3c20 is described below

commit 8bc3c207d0aa7cef72171af23d9c4667b2d46c5d
Author: Sylwester Lachiewicz <[hidden email]>
AuthorDate: Fri Nov 24 00:56:00 2017 +0100

    [MNG-6311] Implement class-level ModelCache in DefaultProjectBuilder to solve slow pom resolutions
   
    Fix by: David Churcher
---
 .../apache/maven/project/DefaultProjectBuilder.java | 21 +++++++++++++--------
 .../org/apache/maven/project/ReactorModelCache.java |  8 ++++----
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index 279399a..1091a08 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -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 class DefaultProjectBuilder
         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 class DefaultProjectBuilder
 
         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 @@ public class DefaultProjectBuilder
 
         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 @@ public class DefaultProjectBuilder
 
     }
 
+    private ReactorModelCache getModelCache()
+    {
+        return this.modelCache;
+    }
+
 }
diff --git a/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java b/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
index 6331157..343967d 100644
--- a/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
+++ b/maven-core/src/main/java/org/apache/maven/project/ReactorModelCache.java
@@ -19,11 +19,11 @@ package org.apache.maven.project;
  * 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 )
     {