This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6957
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/MNG-6957 by this push:
new 50e8beb Do not use the ReactorModelCache to store the mapping between
GA<->Source
50e8beb is described below
commit 50e8beb59eee74bcce8281ebc4ae40a90883539e
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Nov 28 21:29:08 2020 +0100
Do not use the ReactorModelCache to store the mapping between GA<->Source
---
.../apache/maven/project/ReactorModelCache.java | 28 ----------
.../maven/model/building/DefaultModelBuilder.java | 60 +++++++++++++---------
.../apache/maven/model/building/ModelCache.java | 24 ---------
3 files changed, 37 insertions(+), 75 deletions(-)
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 e958980..67695d9 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
@@ -22,10 +22,8 @@ package org.apache.maven.project;
import org.apache.maven.building.Source;
import org.apache.maven.model.building.ModelCache;
-import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -39,8 +37,6 @@ class ReactorModelCache
private final Map<Object, Object> models = new ConcurrentHashMap<>( 256 );
- private final Map<GACacheKey, Set<Source>> mappedSources = new
ConcurrentHashMap<>( 64 );
-
@Override
public Object get( String groupId, String artifactId, String version,
String tag )
{
@@ -52,30 +48,6 @@ class ReactorModelCache
{
models.put( new GavCacheKey( groupId, artifactId, version, tag ), data
);
}
-
- @Override
- public Source get( String groupId, String artifactId )
- {
- Set<Source> sources = mappedSources.get( new GACacheKey( groupId,
artifactId ) );
- if ( sources == null )
- {
- return null;
- }
- else
- {
- return sources.stream().reduce( ( a, b ) ->
- {
- throw new IllegalStateException( "No unique Source for " +
groupId + ':' + artifactId
- + ": " + a.getLocation() + " and " + b.getLocation() );
- } ).orElse( null );
- }
- }
-
- @Override
- public void put( String groupId, String artifactId, Source source )
- {
- mappedSources.computeIfAbsent( new GACacheKey( groupId, artifactId ),
k -> new HashSet<>() ).add( source );
- }
@Override
public Object get( Source source, String tag )
diff --git
a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index b8960e5..f9ca3a4 100644
---
a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++
b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -31,12 +31,15 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;
import javax.inject.Named;
@@ -696,7 +699,12 @@ public class DefaultModelBuilder
intoCache( request.getModelCache(), modelSource, ModelCacheTag.FILE,
model );
if ( modelSource instanceof FileModelSource )
{
- intoCache( request.getModelCache(), getGroupId( model ),
model.getArtifactId(), modelSource );
+ if ( request.getTransformerContextBuilder() instanceof
DefaultTransformerContextBuilder )
+ {
+ DefaultTransformerContextBuilder contextBuilder =
+ (DefaultTransformerContextBuilder)
request.getTransformerContextBuilder();
+ contextBuilder.putSource( getGroupId( model ),
model.getArtifactId(), modelSource );
+ }
}
return model;
@@ -1543,14 +1551,6 @@ public class DefaultModelBuilder
}
}
- private <T> void intoCache( ModelCache modelCache, String groupId, String
artifactId, Source source )
- {
- if ( modelCache != null )
- {
- modelCache.put( groupId, artifactId, source );
- }
- }
-
private <T> void intoCache( ModelCache modelCache, Source source,
ModelCacheTag<T> tag, T data )
{
if ( modelCache != null )
@@ -1572,16 +1572,6 @@ public class DefaultModelBuilder
}
return null;
}
-
- private static Source fromCache( ModelCache modelCache, String groupId,
String artifactId )
- {
- if ( modelCache != null )
- {
- return modelCache.get( groupId, artifactId );
- }
- return null;
- }
-
private static <T> T fromCache( ModelCache modelCache, Source source,
ModelCacheTag<T> tag )
{
@@ -1808,12 +1798,15 @@ public class DefaultModelBuilder
private class DefaultTransformerContextBuilder implements
TransformerContextBuilder
{
private final DefaultTransformerContext context = new
DefaultTransformerContext();
-
+
+ private final Map<DefaultTransformerContext.GAKey, Set<Source>>
mappedSources
+ = new ConcurrentHashMap<>( 64 );
+
/**
* If an interface could be extracted, DefaultModelProblemCollector
should be ModelProblemCollectorExt
*
* @param request
- * @param problems
+ * @param collector
* @return
*/
@Override
@@ -1845,7 +1838,7 @@ public class DefaultModelBuilder
private Model findRawModel( String groupId, String artifactId )
{
- Source source = fromCache( request.getModelCache(),
groupId, artifactId );
+ Source source = getSource( groupId, artifactId );
if ( source != null )
{
try
@@ -1897,6 +1890,27 @@ public class DefaultModelBuilder
public TransformerContext build()
{
return context;
- }
+ }
+
+ public Source getSource( String groupId, String artifactId )
+ {
+ Set<Source> sources = mappedSources.get( new
DefaultTransformerContext.GAKey( groupId, artifactId ) );
+ if ( sources == null )
+ {
+ return null;
+ }
+ return sources.stream().reduce( ( a, b ) ->
+ {
+ throw new IllegalStateException( "No unique Source for " +
groupId + ':' + artifactId
+ + ": " + a.getLocation() + " and " + b.getLocation() );
+ } ).orElse( null );
+ }
+
+ public void putSource( String groupId, String artifactId, Source
source )
+ {
+ mappedSources.computeIfAbsent( new
DefaultTransformerContext.GAKey( groupId, artifactId ),
+ k -> new HashSet<>() ).add( source );
+ }
+
}
}
diff --git
a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
index 963b0ea..952ef46 100644
---
a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
+++
b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
@@ -59,30 +59,6 @@ public interface ModelCache
// only useful for ReactorModelCache
return null;
}
-
- /**
- *
- * @param groupId The groupId, must not be {@code null}.
- * @param artifactId The artifactId, must not be {@code null}.
- * @param source the source matching
- * @throws IllegalArgumentException if the groupId + artifactId was
already added before
- */
- default void put( String groupId, String artifactId, Source source )
- {
- // only useful for ReactorModelCache
- }
-
- /**
- *
- * @param groupId The groupId, must not be {@code null}.
- * @param artifactId The artifactId, must not be {@code null}.
- * @return The requested source or {@code null} if none was present in the
cache.
- */
- default Source get( String groupId, String artifactId )
- {
- // only useful for ReactorModelCache
- return null;
- }
/**
* Puts the specified data into the cache.