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 e958980c1d7..67695d9273a 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 @@ 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 models = new ConcurrentHashMap<>( 256 ); - private final Map> mappedSources = new ConcurrentHashMap<>( 64 ); - @Override public Object get( String groupId, String artifactId, String version, String tag ) { @@ -52,30 +48,6 @@ public void put( String groupId, String artifactId, String version, String tag, { models.put( new GavCacheKey( groupId, artifactId, version, tag ), data ); } - - @Override - public Source get( String groupId, String artifactId ) - { - Set 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 b8960e59120..f9ca3a40ad0 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.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 @@ private Model readFileModel( ModelBuildingRequest request, 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 @@ private void intoCache( ModelCache modelCache, String groupId, String artifa } } - private void intoCache( ModelCache modelCache, String groupId, String artifactId, Source source ) - { - if ( modelCache != null ) - { - modelCache.put( groupId, artifactId, source ); - } - } - private void intoCache( ModelCache modelCache, Source source, ModelCacheTag tag, T data ) { if ( modelCache != null ) @@ -1572,16 +1572,6 @@ private static T fromCache( ModelCache modelCache, String groupId, String ar } 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 fromCache( ModelCache modelCache, Source source, ModelCacheTag tag ) { @@ -1808,12 +1798,15 @@ protected void mergePluginContainer_Plugins( PluginContainer target, PluginConta private class DefaultTransformerContextBuilder implements TransformerContextBuilder { private final DefaultTransformerContext context = new DefaultTransformerContext(); - + + private final Map> 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 Model getRawModel( Path path ) 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 @@ private Model findRawModel( Path p ) public TransformerContext build() { return context; - } + } + + public Source getSource( String groupId, String artifactId ) + { + Set 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 963b0ea6cb0..952ef46806d 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 @@ default Object get( Source path, String tag ) // 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.