diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginArtifactsCache.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginArtifactsCache.java index b66dc22c9b..cc2d7bf545 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginArtifactsCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginArtifactsCache.java @@ -142,8 +142,16 @@ public class DefaultPluginArtifactsCache } public CacheRecord get( Key key ) + throws PluginResolutionException { - return cache.get( key ); + CacheRecord cacheRecord = cache.get( key ); + + if ( cacheRecord != null && cacheRecord.exception != null ) + { + throw cacheRecord.exception; + } + + return cacheRecord; } public CacheRecord put( Key key, List pluginArtifacts ) @@ -153,13 +161,34 @@ public class DefaultPluginArtifactsCache throw new NullPointerException(); } + assertUniqueKey( key ); + + CacheRecord record = + new CacheRecord( Collections.unmodifiableList( new ArrayList( pluginArtifacts ) ) ); + + cache.put( key, record ); + + return record; + } + + protected void assertUniqueKey( Key key ) + { if ( cache.containsKey( key ) ) { throw new IllegalStateException( "Duplicate artifact resolution result for plugin " + key ); } + } - CacheRecord record = - new CacheRecord( Collections.unmodifiableList( new ArrayList( pluginArtifacts ) ) ); + public CacheRecord put( Key key, PluginResolutionException exception ) + { + if ( exception == null ) + { + throw new NullPointerException(); + } + + assertUniqueKey( key ); + + CacheRecord record = new CacheRecord( exception ); cache.put( key, record ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginArtifactsCache.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginArtifactsCache.java index 7114b8f7ae..37d9aeee80 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginArtifactsCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginArtifactsCache.java @@ -52,20 +52,30 @@ public interface PluginArtifactsCache public final List artifacts; + public final PluginResolutionException exception; + public CacheRecord( List artifacts ) { this.artifacts = artifacts; + this.exception = null; } + public CacheRecord( PluginResolutionException exception ) + { + this.artifacts = null; + this.exception = exception; + } } Key createKey( Plugin plugin, DependencyFilter extensionFilter, List repositories, RepositorySystemSession session ); - CacheRecord get( Key key ); + CacheRecord get( Key key ) throws PluginResolutionException; CacheRecord put( Key key, List pluginArtifacts ); + CacheRecord put( Key key, PluginResolutionException e ); + void flush(); /** diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java index 1465ab0969..e9b08929c8 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java @@ -232,9 +232,20 @@ public class DefaultProjectBuildingHelper } else { - artifacts = resolveExtensionArtifacts( plugin, project.getRemotePluginRepositories(), request ); + try + { + artifacts = resolveExtensionArtifacts( plugin, project.getRemotePluginRepositories(), request ); - recordArtifacts = pluginArtifactsCache.put( cacheKey, artifacts ); + recordArtifacts = pluginArtifactsCache.put( cacheKey, artifacts ); + } + catch ( PluginResolutionException e ) + { + pluginArtifactsCache.put( cacheKey, e ); + + pluginArtifactsCache.register( project, recordArtifacts ); + + throw e; + } } pluginArtifactsCache.register( project, recordArtifacts );