This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MNG-7063 in repository https://gitbox.apache.org/repos/asf/maven.git
commit 43db833d0a0afea28c91021bb57eb07f9c131a9f Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Fri Nov 27 08:23:06 2020 +0100 Move the ModelCacheTag usage to the ModelCache interface --- .../maven/model/building/DefaultModelBuilder.java | 16 ++----- .../apache/maven/model/building/ModelCache.java | 56 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 12 deletions(-) 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 f66ae86..bc94607 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 @@ -1529,7 +1529,7 @@ public class DefaultModelBuilder { if ( modelCache != null ) { - modelCache.put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) ); + modelCache.put( groupId, artifactId, version, tag, data ); } } @@ -1537,7 +1537,7 @@ public class DefaultModelBuilder { if ( modelCache != null ) { - modelCache.put( source, tag.getName(), tag.intoCache( data ) ); + modelCache.put( source, tag, data ); } } @@ -1546,11 +1546,7 @@ public class DefaultModelBuilder { if ( modelCache != null ) { - Object data = modelCache.get( groupId, artifactId, version, tag.getName() ); - if ( data != null ) - { - return tag.fromCache( tag.getType().cast( data ) ); - } + return modelCache.get( groupId, artifactId, version, tag ); } return null; } @@ -1559,11 +1555,7 @@ public class DefaultModelBuilder { if ( modelCache != null ) { - Object data = modelCache.get( source, tag.getName() ); - if ( data != null ) - { - return tag.fromCache( tag.getType().cast( data ) ); - } + return modelCache.get( source, tag ); } return null; } 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 3962fe0..b44e8a4 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 @@ -82,4 +82,60 @@ public interface ModelCache */ Object get( String groupId, String artifactId, String version, String tag ); + /** + * Puts the specified data into the cache. + * + * @param path The path of the cache record, must not be {@code null}. + * @param tag The tag of the cache record, must not be {@code null}. + * @param data The data to store in the cache, must not be {@code null}. + * @since 3.7.0 + */ + default <T> void put( Source path, ModelCacheTag<T> tag, T data ) + { + put( path, tag.getName(), tag.intoCache( data ) ); + } + + /** + * Gets the specified data from the cache. + * + * @param path The path of the cache record, must not be {@code null}. + * @param tag The tag of the cache record, must not be {@code null}. + * @return The requested data or {@code null} if none was present in the cache. + * @since 3.7.0 + */ + default <T> T get( Source path, ModelCacheTag<T> tag ) + { + Object obj = get( path, tag.getName() ); + return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null; + } + + /** + * Puts the specified data into the cache. + * + * @param groupId The group id of the cache record, must not be {@code null}. + * @param artifactId The artifact id of the cache record, must not be {@code null}. + * @param version The version of the cache record, must not be {@code null}. + * @param tag The tag of the cache record, must not be {@code null}. + * @param data The data to store in the cache, must not be {@code null}. + */ + default <T> void put( String groupId, String artifactId, String version, ModelCacheTag<T> tag, T data ) + { + put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) ); + } + + /** + * Gets the specified data from the cache. + * + * @param groupId The group id of the cache record, must not be {@code null}. + * @param artifactId The artifact id of the cache record, must not be {@code null}. + * @param version The version of the cache record, must not be {@code null}. + * @param tag The tag of the cache record, must not be {@code null}. + * @return The requested data or {@code null} if none was present in the cache. + */ + default <T> T get( String groupId, String artifactId, String version, ModelCacheTag<T> tag ) + { + Object obj = get( groupId, artifactId, version, tag.getName() ); + return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null; + } + }