[maven] branch MNG-5995 created (now 684a9fc)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven] branch MNG-5995 created (now 684a9fc)

slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch MNG-5995
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at 684a9fc  [MNG-5995] Remove dependency to maven-compat

This branch includes the following new commits:

     new 684a9fc  [MNG-5995] Remove dependency to maven-compat

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Reply | Threaded
Open this post in threaded view
|

[maven] 01/01: [MNG-5995] Remove dependency to maven-compat

slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MNG-5995
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 684a9fca310522c2ce1764852fcd3fbdc7cf8aa7
Author: Sylwester Lachiewicz <[hidden email]>
AuthorDate: Sat Oct 13 04:16:44 2018 +0200

    [MNG-5995] Remove dependency to maven-compat
---
 .../apache/maven/bridge/MavenRepositorySystem.java | 93 +++++++++++++++++++++-
 .../project/DefaultProjectBuildingHelper.java      |  6 +-
 2 files changed, 94 insertions(+), 5 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
index 84ad93c..07ffdae 100644
--- a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
+++ b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
@@ -23,8 +23,10 @@ import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -606,8 +608,95 @@ public class MavenRepositorySystem
 
         return repoIds;
     }
-    
-    
+
+    public List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories )
+    {
+        if ( repositories == null )
+        {
+            return null;
+        }
+
+        Map<String, List<ArtifactRepository>> reposByKey = new LinkedHashMap<>();
+
+        for ( ArtifactRepository repository : repositories )
+        {
+            String key = repository.getId();
+
+            List<ArtifactRepository> aliasedRepos = reposByKey.get( key );
+
+            if ( aliasedRepos == null )
+            {
+                aliasedRepos = new ArrayList<>();
+                reposByKey.put( key, aliasedRepos );
+            }
+
+            aliasedRepos.add( repository );
+        }
+
+        List<ArtifactRepository> effectiveRepositories = new ArrayList<>();
+
+        for ( List<ArtifactRepository> aliasedRepos : reposByKey.values() )
+        {
+            List<ArtifactRepository> mirroredRepos = new ArrayList<>();
+
+            List<ArtifactRepositoryPolicy> releasePolicies =
+                    new ArrayList<>( aliasedRepos.size() );
+
+            for ( ArtifactRepository aliasedRepo : aliasedRepos )
+            {
+                releasePolicies.add( aliasedRepo.getReleases() );
+                mirroredRepos.addAll( aliasedRepo.getMirroredRepositories() );
+            }
+
+            ArtifactRepositoryPolicy releasePolicy = getEffectivePolicy( releasePolicies );
+
+            List<ArtifactRepositoryPolicy> snapshotPolicies =
+                    new ArrayList<>( aliasedRepos.size() );
+
+            for ( ArtifactRepository aliasedRepo : aliasedRepos )
+            {
+                snapshotPolicies.add( aliasedRepo.getSnapshots() );
+            }
+
+            ArtifactRepositoryPolicy snapshotPolicy = getEffectivePolicy( snapshotPolicies );
+
+            ArtifactRepository aliasedRepo = aliasedRepos.get( 0 );
+
+            ArtifactRepository effectiveRepository =
+                    createArtifactRepository( aliasedRepo.getId(), aliasedRepo.getUrl(), aliasedRepo.getLayout(),
+                            snapshotPolicy, releasePolicy );
+
+            effectiveRepository.setAuthentication( aliasedRepo.getAuthentication() );
+
+            effectiveRepository.setProxy( aliasedRepo.getProxy() );
+
+            effectiveRepository.setMirroredRepositories( mirroredRepos );
+
+            effectiveRepositories.add( effectiveRepository );
+        }
+
+        return effectiveRepositories;
+    }
+
+    private ArtifactRepositoryPolicy getEffectivePolicy( Collection<ArtifactRepositoryPolicy> policies )
+    {
+        ArtifactRepositoryPolicy effectivePolicy = null;
+
+        for ( ArtifactRepositoryPolicy policy : policies )
+        {
+            if ( effectivePolicy == null )
+            {
+                effectivePolicy = new ArtifactRepositoryPolicy( policy );
+            }
+            else
+            {
+                effectivePolicy.merge( policy );
+            }
+        }
+
+        return effectivePolicy;
+    }
+
     public ArtifactRepository createLocalRepository( MavenExecutionRequest request, File localRepository )
         throws Exception
     {
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 3159fac..0bd94a8 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
@@ -33,6 +33,7 @@ import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.classrealm.ClassRealmManager;
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Extension;
@@ -44,7 +45,6 @@ import org.apache.maven.plugin.MavenPluginManager;
 import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginResolutionException;
 import org.apache.maven.plugin.version.PluginVersionResolutionException;
-import org.apache.maven.repository.RepositorySystem;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 import org.codehaus.plexus.component.annotations.Component;
@@ -78,7 +78,7 @@ public class DefaultProjectBuildingHelper
     private ProjectRealmCache projectRealmCache;
 
     @Requirement
-    private RepositorySystem repositorySystem;
+    private MavenRepositorySystem repositorySystem;
 
     @Requirement
     private MavenPluginManager pluginManager;
@@ -92,7 +92,7 @@ public class DefaultProjectBuildingHelper
 
         for ( Repository repository : pomRepositories )
         {
-            internalRepositories.add( repositorySystem.buildArtifactRepository( repository ) );
+            internalRepositories.add( MavenRepositorySystem.buildArtifactRepository( repository ) );
         }
 
         repositorySystem.injectMirror( request.getRepositorySession(), internalRepositories );