Repository: maven
Updated Branches:
  refs/heads/MNG-6300_ProjectArtifactsCache-bug [created] 0ef66d201


[MNG-6300] Multi module release creates empty directories in war file instead 
of jars
Reorganize caches


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/13a408a7
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/13a408a7
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/13a408a7

Branch: refs/heads/MNG-6300_ProjectArtifactsCache-bug
Commit: 13a408a754a3410c471d013e956e0ebab3fa448d
Parents: eee06f7
Author: rfscholte <rfscho...@apache.org>
Authored: Sat Dec 16 20:36:32 2017 +0100
Committer: rfscholte <rfscho...@apache.org>
Committed: Sat Dec 16 20:36:32 2017 +0100

----------------------------------------------------------------------
 .../java/org/apache/maven/RepositoryUtils.java  |  69 +++++
 .../internal/LifecycleDependencyResolver.java   |   2 +-
 .../org/apache/maven/plugin/CacheUtils.java     |  68 -----
 .../plugin/DefaultPluginArtifactsCache.java     |   7 +-
 .../plugin/DefaultPluginDescriptorCache.java    |   7 +-
 .../maven/plugin/DefaultPluginRealmCache.java   |   7 +-
 .../plugin/DefaultProjectArtifactsCache.java    | 256 -------------------
 .../maven/plugin/ProjectArtifactsCache.java     |  90 -------
 .../artifact/DefaultProjectArtifactsCache.java  | 246 ++++++++++++++++++
 .../project/artifact/ProjectArtifactsCache.java |  90 +++++++
 10 files changed, 418 insertions(+), 424 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java 
b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
index 52442b7..00f1327 100644
--- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
@@ -22,14 +22,17 @@ package org.apache.maven;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.artifact.Artifact;
 import org.eclipse.aether.artifact.ArtifactProperties;
 import org.eclipse.aether.artifact.ArtifactType;
@@ -44,6 +47,8 @@ import org.eclipse.aether.repository.Authentication;
 import org.eclipse.aether.repository.Proxy;
 import org.eclipse.aether.repository.RemoteRepository;
 import org.eclipse.aether.repository.RepositoryPolicy;
+import org.eclipse.aether.repository.WorkspaceReader;
+import org.eclipse.aether.repository.WorkspaceRepository;
 import org.eclipse.aether.util.repository.AuthenticationBuilder;
 
 /**
@@ -364,4 +369,68 @@ public class RepositoryUtils
         }
         return artifacts;
     }
+
+    public static WorkspaceRepository getWorkspace( RepositorySystemSession 
session )
+    {
+        WorkspaceReader reader = session.getWorkspaceReader();
+        return ( reader != null ) ? reader.getRepository() : null;
+    }
+
+    public static boolean repositoriesEquals( List<RemoteRepository> r1, 
List<RemoteRepository> r2 )
+    {
+        if ( r1.size() != r2.size() )
+        {
+            return false;
+        }
+    
+        for ( Iterator<RemoteRepository> it1 = r1.iterator(), it2 = 
r2.iterator(); it1.hasNext(); )
+        {
+            if ( !repositoryEquals( it1.next(), it2.next() ) )
+            {
+                return false;
+            }
+        }
+    
+        return true;
+    }
+
+    public static int repositoriesHashCode( List<RemoteRepository> 
repositories )
+    {
+        int result = 17;
+        for ( RemoteRepository repository : repositories )
+        {
+            result = 31 * result + repositoryHashCode( repository );
+        }
+        return result;
+    }
+
+    private static int repositoryHashCode( RemoteRepository repository )
+    {
+        int result = 17;
+        Object obj = repository.getUrl();
+        result = 31 * result + ( obj != null ? obj.hashCode() : 0 );
+        return result;
+    }
+
+    private static boolean policyEquals( RepositoryPolicy p1, RepositoryPolicy 
p2 )
+    {
+        if ( p1 == p2 )
+        {
+            return true;
+        }
+        // update policy doesn't affect contents
+        return p1.isEnabled() == p2.isEnabled() && Objects.equals( 
p1.getChecksumPolicy(), p2.getChecksumPolicy() );
+    }
+
+    private static boolean repositoryEquals( RemoteRepository r1, 
RemoteRepository r2 )
+    {
+        if ( r1 == r2 )
+        {
+            return true;
+        }
+    
+        return Objects.equals( r1.getId(), r2.getId() ) && Objects.equals( 
r1.getUrl(), r2.getUrl() )
+            && policyEquals( r1.getPolicy( false ), r2.getPolicy( false ) )
+            && policyEquals( r1.getPolicy( true ), r2.getPolicy( true ) );
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java
index 504274f..dd72e19 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java
@@ -37,13 +37,13 @@ import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.eventspy.internal.EventSpyDispatcher;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.lifecycle.LifecycleExecutionException;
-import org.apache.maven.plugin.ProjectArtifactsCache;
 import org.apache.maven.project.DefaultDependencyResolutionRequest;
 import org.apache.maven.project.DependencyResolutionException;
 import org.apache.maven.project.DependencyResolutionResult;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectDependenciesResolver;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.project.artifact.ProjectArtifactsCache;
 import org.codehaus.plexus.logging.Logger;
 import org.eclipse.aether.graph.Dependency;
 import org.eclipse.aether.graph.DependencyFilter;

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java 
b/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
index a73e1ef..7196ce9 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/CacheUtils.java
@@ -25,11 +25,6 @@ import java.util.List;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Exclusion;
 import org.apache.maven.model.Plugin;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.repository.RepositoryPolicy;
-import org.eclipse.aether.repository.WorkspaceReader;
-import org.eclipse.aether.repository.WorkspaceRepository;
 
 /**
  * @author Benjamin Bentmann
@@ -47,63 +42,6 @@ class CacheUtils
         return obj != null ? obj.hashCode() : 0;
     }
 
-    public static int repositoriesHashCode( List<RemoteRepository> 
repositories )
-    {
-        int result = 17;
-        for ( RemoteRepository repository : repositories )
-        {
-            result = 31 * result + repositoryHashCode( repository );
-        }
-        return result;
-    }
-
-    private static int repositoryHashCode( RemoteRepository repository )
-    {
-        int result = 17;
-        result = 31 * result + hash( repository.getUrl() );
-        return result;
-    }
-
-    private static boolean repositoryEquals( RemoteRepository r1, 
RemoteRepository r2 )
-    {
-        if ( r1 == r2 )
-        {
-            return true;
-        }
-
-        return eq( r1.getId(), r2.getId() ) && eq( r1.getUrl(), r2.getUrl() )
-            && policyEquals( r1.getPolicy( false ), r2.getPolicy( false ) )
-            && policyEquals( r1.getPolicy( true ), r2.getPolicy( true ) );
-    }
-
-    private static boolean policyEquals( RepositoryPolicy p1, RepositoryPolicy 
p2 )
-    {
-        if ( p1 == p2 )
-        {
-            return true;
-        }
-        // update policy doesn't affect contents
-        return p1.isEnabled() == p2.isEnabled() && eq( p1.getChecksumPolicy(), 
p2.getChecksumPolicy() );
-    }
-
-    public static boolean repositoriesEquals( List<RemoteRepository> r1, 
List<RemoteRepository> r2 )
-    {
-        if ( r1.size() != r2.size() )
-        {
-            return false;
-        }
-
-        for ( Iterator<RemoteRepository> it1 = r1.iterator(), it2 = 
r2.iterator(); it1.hasNext(); )
-        {
-            if ( !repositoryEquals( it1.next(), it2.next() ) )
-            {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
     public static int pluginHashCode( Plugin plugin )
     {
         int hash = 17;
@@ -202,10 +140,4 @@ class CacheUtils
         return true;
     }
 
-    public static WorkspaceRepository getWorkspace( RepositorySystemSession 
session )
-    {
-        WorkspaceReader reader = session.getWorkspaceReader();
-        return ( reader != null ) ? reader.getRepository() : null;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginArtifactsCache.java
----------------------------------------------------------------------
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 6a08681..91f8b20 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
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.lang3.Validate;
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.project.MavenProject;
@@ -65,7 +66,7 @@ public class DefaultPluginArtifactsCache
                          RepositorySystemSession session )
         {
             this.plugin = plugin.clone();
-            workspace = CacheUtils.getWorkspace( session );
+            workspace = RepositoryUtils.getWorkspace( session );
             this.localRepo = session.getLocalRepository();
             this.repositories = new ArrayList<>( repositories.size() );
             for ( RemoteRepository repository : repositories )
@@ -85,7 +86,7 @@ public class DefaultPluginArtifactsCache
             hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
             hash = hash * 31 + hash( workspace );
             hash = hash * 31 + hash( localRepo );
-            hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
+            hash = hash * 31 + RepositoryUtils.repositoriesHashCode( 
repositories );
             hash = hash * 31 + hash( extensionFilter );
             this.hashCode = hash;
         }
@@ -123,7 +124,7 @@ public class DefaultPluginArtifactsCache
             CacheKey that = (CacheKey) o;
 
             return CacheUtils.pluginEquals( plugin, that.plugin ) && eq( 
workspace, that.workspace )
-                && eq( localRepo, that.localRepo ) && 
CacheUtils.repositoriesEquals( repositories, that.repositories )
+                && eq( localRepo, that.localRepo ) && 
RepositoryUtils.repositoriesEquals( repositories, that.repositories )
                 && eq( filter, that.filter );
         }
 

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
 
b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
index 5968332..32228ba 100644
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
+++ 
b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -146,7 +147,7 @@ public class DefaultPluginDescriptorCache
             artifactId = plugin.getArtifactId();
             version = plugin.getVersion();
 
-            workspace = CacheUtils.getWorkspace( session );
+            workspace = RepositoryUtils.getWorkspace( session );
             localRepo = session.getLocalRepository();
             this.repositories = new ArrayList<>( repositories.size() );
             for ( RemoteRepository repository : repositories )
@@ -167,7 +168,7 @@ public class DefaultPluginDescriptorCache
             hash = hash * 31 + version.hashCode();
             hash = hash * 31 + hash( workspace );
             hash = hash * 31 + localRepo.hashCode();
-            hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
+            hash = hash * 31 + RepositoryUtils.repositoriesHashCode( 
repositories );
             this.hashCode = hash;
         }
 
@@ -195,7 +196,7 @@ public class DefaultPluginDescriptorCache
             return eq( this.artifactId, that.artifactId ) && eq( this.groupId, 
that.groupId )
                 && eq( this.version, that.version ) && eq( this.localRepo, 
that.localRepo )
                 && eq( this.workspace, that.workspace )
-                && CacheUtils.repositoriesEquals( this.repositories, 
that.repositories );
+                && RepositoryUtils.repositoriesEquals( this.repositories, 
that.repositories );
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmCache.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmCache.java 
b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmCache.java
index 0a6da8d..b6c7b9b 100644
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmCache.java
+++ 
b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmCache.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.lang3.Validate;
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.project.MavenProject;
@@ -72,7 +73,7 @@ public class DefaultPluginRealmCache
                          RepositorySystemSession session )
         {
             this.plugin = plugin.clone();
-            this.workspace = CacheUtils.getWorkspace( session );
+            this.workspace = RepositoryUtils.getWorkspace( session );
             this.localRepo = session.getLocalRepository();
             this.repositories = new ArrayList<>( repositories.size() );
             for ( RemoteRepository repository : repositories )
@@ -95,7 +96,7 @@ public class DefaultPluginRealmCache
             hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
             hash = hash * 31 + hash( workspace );
             hash = hash * 31 + hash( localRepo );
-            hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
+            hash = hash * 31 + RepositoryUtils.repositoriesHashCode( 
repositories );
             hash = hash * 31 + hash( parentRealm );
             hash = hash * 31 + this.foreignImports.hashCode();
             hash = hash * 31 + hash( dependencyFilter );
@@ -136,7 +137,7 @@ public class DefaultPluginRealmCache
 
             return parentRealm == that.parentRealm && CacheUtils.pluginEquals( 
plugin, that.plugin )
                 && eq( workspace, that.workspace ) && eq( localRepo, 
that.localRepo )
-                && CacheUtils.repositoriesEquals( this.repositories, 
that.repositories ) && eq( filter, that.filter )
+                && RepositoryUtils.repositoriesEquals( this.repositories, 
that.repositories ) && eq( filter, that.filter )
                 && eq( foreignImports, that.foreignImports );
         }
 

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/plugin/DefaultProjectArtifactsCache.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/DefaultProjectArtifactsCache.java
 
b/maven-core/src/main/java/org/apache/maven/plugin/DefaultProjectArtifactsCache.java
deleted file mode 100644
index 1eaa627..0000000
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/DefaultProjectArtifactsCache.java
+++ /dev/null
@@ -1,256 +0,0 @@
-package org.apache.maven.plugin;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.lang3.Validate;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.lifecycle.LifecycleExecutionException;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.component.annotations.Component;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.repository.WorkspaceRepository;
-
-/**
- * @author Igor Fedorenko
- * @author Benjamin Bentmann
- * @author Anton Tanasenko
- */
-@Component( role = ProjectArtifactsCache.class )
-public class DefaultProjectArtifactsCache
-    implements ProjectArtifactsCache
-{
-
-    protected static class CacheKey
-        implements Key
-    {
-
-        private final String groupId;
-        
-        private final String artifactId;
-        
-        private final String version;
-        
-        private final Set<String> dependencyArtifacts;
-
-        private final WorkspaceRepository workspace;
-
-        private final LocalRepository localRepo;
-
-        private final List<RemoteRepository> repositories;
-        
-        private final Set<String> collect;
-        
-        private final Set<String> resolve;
-        
-        private boolean aggregating;
-
-        private final int hashCode;
-
-        public CacheKey( MavenProject project, List<RemoteRepository> 
repositories,
-            Collection<String> scopesToCollect, Collection<String> 
scopesToResolve, boolean aggregating,
-            RepositorySystemSession session )
-        {
-            
-            groupId = project.getGroupId();
-            artifactId = project.getArtifactId();
-            version = project.getVersion();
-            
-            Set<String> deps = new HashSet<>();
-            if ( project.getDependencyArtifacts() != null )
-            {
-              for ( Artifact dep: project.getDependencyArtifacts() )
-              {
-                deps.add( dep.toString() );
-              }
-            }
-            dependencyArtifacts = Collections.unmodifiableSet( deps );
-            
-            workspace = CacheUtils.getWorkspace( session );
-            this.localRepo = session.getLocalRepository();
-            this.repositories = new ArrayList<>( repositories.size() );
-            for ( RemoteRepository repository : repositories )
-            {
-                if ( repository.isRepositoryManager() )
-                {
-                    this.repositories.addAll( 
repository.getMirroredRepositories() );
-                }
-                else
-                {
-                    this.repositories.add( repository );
-                }
-            }
-            collect = scopesToCollect == null
-                ? Collections.<String>emptySet() 
-                : Collections.unmodifiableSet( new HashSet<>( scopesToCollect 
) );
-            resolve = scopesToResolve == null 
-                ? Collections.<String>emptySet() 
-                : Collections.unmodifiableSet( new HashSet<>( scopesToResolve 
) );
-            this.aggregating = aggregating;
-
-            int hash = 17;
-            hash = hash * 31 + hash( groupId );
-            hash = hash * 31 + hash( artifactId );
-            hash = hash * 31 + hash( version );
-            hash = hash * 31 + hash( dependencyArtifacts );
-            hash = hash * 31 + hash( workspace );
-            hash = hash * 31 + hash( localRepo );
-            hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
-            hash = hash * 31 + hash( collect );
-            hash = hash * 31 + hash( resolve );
-            hash = hash * 31 + hash( aggregating );
-            this.hashCode = hash;
-        }
-
-        @Override
-        public String toString()
-        {
-            return groupId + ":" + artifactId + ":" + version;
-        }
-
-        @Override
-        public int hashCode()
-        {
-            return hashCode;
-        }
-
-        private static int hash( Object obj )
-        {
-            return obj != null ? obj.hashCode() : 0;
-        }
-
-        @Override
-        public boolean equals( Object o )
-        {
-            if ( o == this )
-            {
-                return true;
-            }
-
-            if ( !( o instanceof CacheKey ) )
-            {
-                return false;
-            }
-
-            CacheKey that = (CacheKey) o;
-
-            return eq( groupId, that.groupId ) && eq( artifactId, 
that.artifactId ) && eq( version, that.version ) 
-                && eq( dependencyArtifacts, that.dependencyArtifacts )
-                && eq( workspace, that.workspace ) && eq( localRepo, 
that.localRepo ) 
-                && CacheUtils.repositoriesEquals( repositories, 
that.repositories ) && eq( collect, that.collect ) 
-                && eq( resolve, that.resolve ) && aggregating == 
that.aggregating;
-        }
-
-        private static <T> boolean eq( T s1, T s2 )
-        {
-            return s1 != null ? s1.equals( s2 ) : s2 == null;
-        }
-
-    }
-
-    protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<>();
-
-    public Key createKey( MavenProject project, Collection<String> 
scopesToCollect,
-        Collection<String> scopesToResolve, boolean aggregating, 
RepositorySystemSession session )
-    {
-        return new CacheKey( project, project.getRemoteProjectRepositories(), 
scopesToCollect, scopesToResolve, 
-            aggregating, session );
-    }
-
-    public CacheRecord get( Key key )
-        throws LifecycleExecutionException
-    {
-        CacheRecord cacheRecord = cache.get( key );
-
-        if ( cacheRecord != null && cacheRecord.exception != null )
-        {
-            throw cacheRecord.exception;
-        }
-
-        return cacheRecord;
-    }
-
-    public CacheRecord put( Key key, Set<Artifact> projectArtifacts )
-    {
-        Validate.notNull( projectArtifacts, "projectArtifacts cannot be null" 
);
-
-        assertUniqueKey( key );
-
-        CacheRecord record =
-            new CacheRecord( Collections.unmodifiableSet( new HashSet<>( 
projectArtifacts ) ) );
-
-        cache.put( key, record );
-
-        return record;
-    }
-
-    protected void assertUniqueKey( Key key )
-    {
-        if ( cache.containsKey( key ) )
-        {
-            throw new IllegalStateException( "Duplicate artifact resolution 
result for project " + key );
-        }
-    }
-
-    public CacheRecord put( Key key, LifecycleExecutionException exception )
-    {
-        Validate.notNull( exception, "exception cannot be null" );
-
-        assertUniqueKey( key );
-
-        CacheRecord record = new CacheRecord( exception );
-
-        cache.put( key, record );
-
-        return record;
-    }
-
-    public void flush()
-    {
-        cache.clear();
-    }
-
-    protected static int pluginHashCode( Plugin plugin )
-    {
-        return CacheUtils.pluginHashCode( plugin );
-    }
-
-    protected static boolean pluginEquals( Plugin a, Plugin b )
-    {
-        return CacheUtils.pluginEquals( a, b );
-    }
-
-    public void register( MavenProject project, Key cacheKey, CacheRecord 
record )
-    {
-        // default cache does not track record usage
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/plugin/ProjectArtifactsCache.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/ProjectArtifactsCache.java 
b/maven-core/src/main/java/org/apache/maven/plugin/ProjectArtifactsCache.java
deleted file mode 100644
index 42a95e5..0000000
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/ProjectArtifactsCache.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.apache.maven.plugin;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.lifecycle.LifecycleExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.eclipse.aether.RepositorySystemSession;
-/**
- * Caches project artifacts. <strong>Warning:</strong> This is an internal 
utility interface that is only public for
- * technical reasons, it is not part of the public API. In particular, this 
interface can be changed or deleted without
- * prior notice.
- *
- * @author Igor Fedorenko
- * @author Benjamin Bentmann
- * @author Anton Tanasenko
- */
-public interface ProjectArtifactsCache
-{
-
-    /**
-     * A cache key.
-     */
-    interface Key
-    {
-        // marker interface for cache keys
-    }
-
-    static class CacheRecord
-    {
-
-        public final Set<Artifact> artifacts;
-
-        public final LifecycleExecutionException exception;
-
-        public CacheRecord( Set<Artifact> artifacts )
-        {
-            this.artifacts = artifacts;
-            this.exception = null;
-        }
-
-        public CacheRecord( LifecycleExecutionException exception )
-        {
-            this.artifacts = null;
-            this.exception = exception;
-        }
-    }
-
-    Key createKey( MavenProject project, Collection<String> scopesToCollect, 
Collection<String> scopesToResolve, 
-        boolean aggregating, RepositorySystemSession session );
-
-    CacheRecord get( Key key ) throws LifecycleExecutionException;
-
-    CacheRecord put( Key key, Set<Artifact> pluginArtifacts );
-
-    CacheRecord put( Key key, LifecycleExecutionException e );
-
-    void flush();
-
-    /**
-     * Registers the specified cache record for usage with the given project. 
Integrators can use the information
-     * collected from this method in combination with a custom cache 
implementation to dispose unused records from the
-     * cache.
-     *
-     * @param project The project that employs the plugin realm, must not be 
{@code null}.
-     * @param record The cache record being used for the project, must not be 
{@code null}.
-     */
-    void register( MavenProject project, Key cacheKey, CacheRecord record );
-
-}

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCache.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCache.java
 
b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCache.java
new file mode 100644
index 0000000..1c427f2
--- /dev/null
+++ 
b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultProjectArtifactsCache.java
@@ -0,0 +1,246 @@
+package org.apache.maven.project.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.lang3.Validate;
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.component.annotations.Component;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.repository.WorkspaceRepository;
+
+/**
+ * @author Igor Fedorenko
+ * @author Benjamin Bentmann
+ * @author Anton Tanasenko
+ */
+@Component( role = ProjectArtifactsCache.class )
+public class DefaultProjectArtifactsCache
+    implements ProjectArtifactsCache
+{
+
+    protected static class CacheKey
+        implements Key
+    {
+
+        private final String groupId;
+        
+        private final String artifactId;
+        
+        private final String version;
+        
+        private final Set<String> dependencyArtifacts;
+
+        private final WorkspaceRepository workspace;
+
+        private final LocalRepository localRepo;
+
+        private final List<RemoteRepository> repositories;
+        
+        private final Set<String> collect;
+        
+        private final Set<String> resolve;
+        
+        private boolean aggregating;
+
+        private final int hashCode;
+
+        public CacheKey( MavenProject project, List<RemoteRepository> 
repositories,
+            Collection<String> scopesToCollect, Collection<String> 
scopesToResolve, boolean aggregating,
+            RepositorySystemSession session )
+        {
+            
+            groupId = project.getGroupId();
+            artifactId = project.getArtifactId();
+            version = project.getVersion();
+            
+            Set<String> deps = new HashSet<>();
+            if ( project.getDependencyArtifacts() != null )
+            {
+              for ( Artifact dep: project.getDependencyArtifacts() )
+              {
+                deps.add( dep.toString() );
+              }
+            }
+            dependencyArtifacts = Collections.unmodifiableSet( deps );
+            
+            workspace = RepositoryUtils.getWorkspace( session );
+            this.localRepo = session.getLocalRepository();
+            this.repositories = new ArrayList<>( repositories.size() );
+            for ( RemoteRepository repository : repositories )
+            {
+                if ( repository.isRepositoryManager() )
+                {
+                    this.repositories.addAll( 
repository.getMirroredRepositories() );
+                }
+                else
+                {
+                    this.repositories.add( repository );
+                }
+            }
+            collect = scopesToCollect == null
+                ? Collections.<String>emptySet() 
+                : Collections.unmodifiableSet( new HashSet<>( scopesToCollect 
) );
+            resolve = scopesToResolve == null 
+                ? Collections.<String>emptySet() 
+                : Collections.unmodifiableSet( new HashSet<>( scopesToResolve 
) );
+            this.aggregating = aggregating;
+
+            int hash = 17;
+            hash = hash * 31 + hash( groupId );
+            hash = hash * 31 + hash( artifactId );
+            hash = hash * 31 + hash( version );
+            hash = hash * 31 + hash( dependencyArtifacts );
+            hash = hash * 31 + hash( workspace );
+            hash = hash * 31 + hash( localRepo );
+            hash = hash * 31 + RepositoryUtils.repositoriesHashCode( 
repositories );
+            hash = hash * 31 + hash( collect );
+            hash = hash * 31 + hash( resolve );
+            hash = hash * 31 + hash( aggregating );
+            this.hashCode = hash;
+        }
+
+        @Override
+        public String toString()
+        {
+            return groupId + ":" + artifactId + ":" + version;
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return hashCode;
+        }
+
+        private static int hash( Object obj )
+        {
+            return obj != null ? obj.hashCode() : 0;
+        }
+
+        @Override
+        public boolean equals( Object o )
+        {
+            if ( o == this )
+            {
+                return true;
+            }
+
+            if ( !( o instanceof CacheKey ) )
+            {
+                return false;
+            }
+
+            CacheKey that = (CacheKey) o;
+
+            return eq( groupId, that.groupId ) && eq( artifactId, 
that.artifactId ) && eq( version, that.version ) 
+                && eq( dependencyArtifacts, that.dependencyArtifacts )
+                && eq( workspace, that.workspace ) && eq( localRepo, 
that.localRepo ) 
+                && RepositoryUtils.repositoriesEquals( repositories, 
that.repositories ) && eq( collect, that.collect ) 
+                && eq( resolve, that.resolve ) && aggregating == 
that.aggregating;
+        }
+
+        private static <T> boolean eq( T s1, T s2 )
+        {
+            return s1 != null ? s1.equals( s2 ) : s2 == null;
+        }
+
+    }
+
+    protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<>();
+
+    public Key createKey( MavenProject project, Collection<String> 
scopesToCollect,
+        Collection<String> scopesToResolve, boolean aggregating, 
RepositorySystemSession session )
+    {
+        return new CacheKey( project, project.getRemoteProjectRepositories(), 
scopesToCollect, scopesToResolve, 
+            aggregating, session );
+    }
+
+    public CacheRecord get( Key key )
+        throws LifecycleExecutionException
+    {
+        CacheRecord cacheRecord = cache.get( key );
+
+        if ( cacheRecord != null && cacheRecord.exception != null )
+        {
+            throw cacheRecord.exception;
+        }
+
+        return cacheRecord;
+    }
+
+    public CacheRecord put( Key key, Set<Artifact> projectArtifacts )
+    {
+        Validate.notNull( projectArtifacts, "projectArtifacts cannot be null" 
);
+
+        assertUniqueKey( key );
+
+        CacheRecord record =
+            new CacheRecord( Collections.unmodifiableSet( new HashSet<>( 
projectArtifacts ) ) );
+
+        cache.put( key, record );
+
+        return record;
+    }
+
+    protected void assertUniqueKey( Key key )
+    {
+        if ( cache.containsKey( key ) )
+        {
+            throw new IllegalStateException( "Duplicate artifact resolution 
result for project " + key );
+        }
+    }
+
+    public CacheRecord put( Key key, LifecycleExecutionException exception )
+    {
+        Validate.notNull( exception, "exception cannot be null" );
+
+        assertUniqueKey( key );
+
+        CacheRecord record = new CacheRecord( exception );
+
+        cache.put( key, record );
+
+        return record;
+    }
+
+    public void flush()
+    {
+        cache.clear();
+    }
+
+    public void register( MavenProject project, Key cacheKey, CacheRecord 
record )
+    {
+        // default cache does not track record usage
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/13a408a7/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactsCache.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactsCache.java
 
b/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactsCache.java
new file mode 100644
index 0000000..ac093e9
--- /dev/null
+++ 
b/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactsCache.java
@@ -0,0 +1,90 @@
+package org.apache.maven.project.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystemSession;
+/**
+ * Caches project artifacts. <strong>Warning:</strong> This is an internal 
utility interface that is only public for
+ * technical reasons, it is not part of the public API. In particular, this 
interface can be changed or deleted without
+ * prior notice.
+ *
+ * @author Igor Fedorenko
+ * @author Benjamin Bentmann
+ * @author Anton Tanasenko
+ */
+public interface ProjectArtifactsCache
+{
+
+    /**
+     * A cache key.
+     */
+    interface Key
+    {
+        // marker interface for cache keys
+    }
+
+    static class CacheRecord
+    {
+
+        public final Set<Artifact> artifacts;
+
+        public final LifecycleExecutionException exception;
+
+        public CacheRecord( Set<Artifact> artifacts )
+        {
+            this.artifacts = artifacts;
+            this.exception = null;
+        }
+
+        public CacheRecord( LifecycleExecutionException exception )
+        {
+            this.artifacts = null;
+            this.exception = exception;
+        }
+    }
+
+    Key createKey( MavenProject project, Collection<String> scopesToCollect, 
Collection<String> scopesToResolve, 
+        boolean aggregating, RepositorySystemSession session );
+
+    CacheRecord get( Key key ) throws LifecycleExecutionException;
+
+    CacheRecord put( Key key, Set<Artifact> pluginArtifacts );
+
+    CacheRecord put( Key key, LifecycleExecutionException e );
+
+    void flush();
+
+    /**
+     * Registers the specified cache record for usage with the given project. 
Integrators can use the information
+     * collected from this method in combination with a custom cache 
implementation to dispose unused records from the
+     * cache.
+     *
+     * @param project The project that employs the plugin realm, must not be 
{@code null}.
+     * @param record The cache record being used for the project, must not be 
{@code null}.
+     */
+    void register( MavenProject project, Key cacheKey, CacheRecord record );
+
+}

Reply via email to