Skip to content

Commit

Permalink
Actually cache the results and avoid caching POM resolved results
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 13, 2021
1 parent 0535b59 commit 9944364
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
Expand Down Expand Up @@ -91,14 +92,14 @@ public class DefaultPluginVersionResolver
public PluginVersionResult resolve( PluginVersionRequest request )
throws PluginVersionResolutionException
{
Map<String, PluginVersionResult> cache = getCache( request.getRepositorySession().getData() );
ConcurrentMap<String, PluginVersionResult> cache = getCache( request.getRepositorySession().getData() );
String key = getKey( request );

PluginVersionResult result = cache.get( key );
PluginVersionResult result = resolveFromProject( request );

if ( result == null )
{
result = resolveFromProject( request );
result = cache.get( key );

if ( result == null )
{
Expand All @@ -109,17 +110,19 @@ public PluginVersionResult resolve( PluginVersionRequest request )
logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
+ " to " + result.getVersion() + " from repository " + result.getRepository() );
}

cache.putIfAbsent( key, result );
}
else if ( logger.isDebugEnabled() )
{
logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
+ " to " + result.getVersion() + " from POM " + request.getPom() );
logger.debug( "Reusing cached resolved plugin version for " + request.getGroupId() + ":"
+ request.getArtifactId() + " to " + result.getVersion() + " from POM " + request.getPom() );
}
}
else if ( logger.isDebugEnabled() )
{
logger.debug( "Reusing cached resolved plugin version for " + request.getGroupId() + ":"
+ request.getArtifactId() + " to " + result.getVersion() + " from POM " + request.getPom() );
logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
+ " to " + result.getVersion() + " from POM " + request.getPom() );
}

return result;
Expand Down Expand Up @@ -402,17 +405,18 @@ private PluginVersionResult resolveFromProject( PluginVersionRequest request, Li
}

@SuppressWarnings( "unchecked" )
private Map<String, PluginVersionResult> getCache( SessionData data )
private ConcurrentMap<String, PluginVersionResult> getCache( SessionData data )
{
Map<String, PluginVersionResult> cache = ( Map<String, PluginVersionResult> ) data.get( CACHE_KEY );
ConcurrentMap<String, PluginVersionResult> cache =
( ConcurrentMap<String, PluginVersionResult> ) data.get( CACHE_KEY );
while ( cache == null )
{
cache = new ConcurrentHashMap<>( 256 );
if ( data.set( CACHE_KEY, null, cache ) )
{
break;
}
cache = ( Map<String, PluginVersionResult> ) data.get( CACHE_KEY );
cache = ( ConcurrentMap<String, PluginVersionResult> ) data.get( CACHE_KEY );
}
return cache;
}
Expand Down

0 comments on commit 9944364

Please sign in to comment.