You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2021/09/30 22:47:29 UTC

[maven] branch MNG-7276 updated (a0cdd78 -> 20e0b4f)

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

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


 discard a0cdd78  [MNG-7276] - Refactoring - Umbrella
     add 038201e  [MNG-7274] - JUnit Jupiter via BOM
     new 20e0b4f  [MNG-7276] - Refactoring - Umbrella

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (a0cdd78)
            \
             N -- N -- N   refs/heads/MNG-7276 (20e0b4f)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 maven-core/src/main/java/org/apache/maven/ReactorReader.java | 10 +++-------
 pom.xml                                                      | 10 +++++-----
 2 files changed, 8 insertions(+), 12 deletions(-)

[maven] 01/01: [MNG-7276] - Refactoring - Umbrella

Posted by kh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 20e0b4f8fe1e912517cbeef525879c9ace6ea7ca
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Thu Sep 30 19:10:44 2021 +0200

    [MNG-7276] - Refactoring - Umbrella
---
 .../main/java/org/apache/maven/ReactorReader.java  | 73 ++++++++--------------
 .../java/org/apache/maven/RepositoryUtils.java     | 43 ++++---------
 2 files changed, 40 insertions(+), 76 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
index 42c41ac..014b755 100644
--- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java
+++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java
@@ -24,20 +24,19 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-import javax.inject.Inject;
-import javax.inject.Named;
-
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Model;
@@ -49,6 +48,9 @@ import org.eclipse.aether.util.artifact.ArtifactIdUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.inject.Inject;
+import javax.inject.Named;
+
 /**
  * An implementation of a workspace reader that knows how to search the Maven reactor for artifacts, either as packaged
  * jar if it has been built, or only compile output directory if packaging hasn't happened yet.
@@ -75,26 +77,22 @@ class ReactorReader
 
     private WorkspaceRepository repository;
 
+    private Function<MavenProject, String> projectIntoKey =
+            s -> ArtifactUtils.key( s.getGroupId(), s.getArtifactId(), s.getVersion() );
+
+    private Function<MavenProject, String> projectIntoVersionlessKey =
+            s -> ArtifactUtils.versionlessKey( s.getGroupId(), s.getArtifactId() );
+
     @Inject
     ReactorReader( MavenSession session )
     {
         this.session = session;
-        this.projectsByGAV = new HashMap<>( session.getAllProjects().size() * 2 );
-        session.getAllProjects().forEach( project ->
-        {
-            String projectId = ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() );
-            this.projectsByGAV.put( projectId, project );
-        } );
-
-        projectsByGA = new HashMap<>( projectsByGAV.size() * 2 );
-        for ( MavenProject project : projectsByGAV.values() )
-        {
-            String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
+        this.projectsByGAV =
+                session.getAllProjects().stream()
+                        .collect( Collectors.toMap( k -> projectIntoKey.apply( k ), Function.identity() ) );
 
-            List<MavenProject> projects = projectsByGA.computeIfAbsent( key, k -> new ArrayList<>( 1 ) );
-
-            projects.add( project );
-        }
+        this.projectsByGA = projectsByGAV.values().stream()
+                .collect( Collectors.groupingBy( projectIntoVersionlessKey ) );
 
         repository = new WorkspaceRepository( "reactor", new HashSet<>( projectsByGAV.keySet() ) );
     }
@@ -131,23 +129,11 @@ class ReactorReader
     {
         String key = ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
 
-        List<MavenProject> projects = projectsByGA.get( key );
-        if ( projects == null || projects.isEmpty() )
-        {
-            return Collections.emptyList();
-        }
-
-        List<String> versions = new ArrayList<>();
-
-        for ( MavenProject project : projects )
-        {
-            if ( find( project, artifact ) != null )
-            {
-                versions.add( project.getVersion() );
-            }
-        }
-
-        return Collections.unmodifiableList( versions );
+        return Optional.ofNullable( projectsByGA.get( key ) )
+                .orElse( Collections.emptyList() ).stream()
+                .filter( s -> Objects.nonNull( find( s, artifact ) ) )
+                .map( s -> s.getVersion() )
+                .collect( Collectors.collectingAndThen( Collectors.toList(), Collections::unmodifiableList ) );
     }
 
     @Override
@@ -337,15 +323,10 @@ class ReactorReader
             return mainArtifact;
         }
 
-        for ( Artifact attachedArtifact : RepositoryUtils.toArtifacts( project.getAttachedArtifacts() ) )
-        {
-            if ( attachedArtifactComparison( requestedArtifact, attachedArtifact ) )
-            {
-                return attachedArtifact;
-            }
-        }
-
-        return null;
+        return RepositoryUtils.toArtifacts( project.getAttachedArtifacts() ).stream()
+                .filter( s -> attachedArtifactComparison( requestedArtifact, s ) )
+                .findFirst()
+                .orElse( null );
     }
 
     private boolean attachedArtifactComparison( Artifact requested, Artifact attached )
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 a49b670..4453b99 100644
--- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
@@ -121,7 +122,7 @@ public class RepositoryUtils
             nodeTrail.addAll( trail );
             nodeTrail.add( artifact.getId() );
 
-            if ( filter == null || filter.accept( node, Collections.<DependencyNode>emptyList() ) )
+            if ( filter == null || filter.accept( node, Collections.emptyList() ) )
             {
                 artifact.setDependencyTrail( nodeTrail );
                 artifacts.add( artifact );
@@ -173,11 +174,7 @@ public class RepositoryUtils
         List<Exclusion> excl = null;
         if ( exclusions != null )
         {
-            excl = new ArrayList<>( exclusions.size() );
-            for ( org.apache.maven.model.Exclusion exclusion : exclusions )
-            {
-                excl.add( toExclusion( exclusion ) );
-            }
+            excl = exclusions.stream().map( RepositoryUtils::toExclusion ).collect( Collectors.toList() );
         }
 
         return new Dependency( result, artifact.getScope(), artifact.isOptional(), excl );
@@ -190,12 +187,7 @@ public class RepositoryUtils
             return null;
         }
 
-        List<RemoteRepository> results = new ArrayList<>( repos.size() );
-        for ( ArtifactRepository repo : repos )
-        {
-            results.add( toRepo( repo ) );
-        }
-        return results;
+        return repos.stream().map( RepositoryUtils::toRepo ).collect( Collectors.toList() );
     }
 
     public static RemoteRepository toRepo( ArtifactRepository repo )
@@ -318,20 +310,16 @@ public class RepositoryUtils
             new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null,
                                  dependency.getVersion(), props, stereotype );
 
-        List<Exclusion> exclusions = new ArrayList<>( dependency.getExclusions().size() );
-        for ( org.apache.maven.model.Exclusion exclusion : dependency.getExclusions() )
-        {
-            exclusions.add( toExclusion( exclusion ) );
-        }
+        List<Exclusion> exclusions =
+                dependency.getExclusions().stream().map( RepositoryUtils::toExclusion ).collect( Collectors.toList() );
 
-        Dependency result = new Dependency( artifact,
-                                            dependency.getScope(),
-                                            dependency.getOptional() != null
-                                                ? dependency.isOptional()
-                                                : null,
-                                            exclusions );
+        return new Dependency( artifact,
+                dependency.getScope(),
+                dependency.getOptional() != null
+                        ? dependency.isOptional()
+                        : null,
+                exclusions );
 
-        return result;
     }
 
     private static Exclusion toExclusion( org.apache.maven.model.Exclusion exclusion )
@@ -365,12 +353,7 @@ public class RepositoryUtils
 
     public static Collection<Artifact> toArtifacts( Collection<org.apache.maven.artifact.Artifact> artifactsToConvert )
     {
-        List<Artifact> artifacts = new ArrayList<>();
-        for ( org.apache.maven.artifact.Artifact a : artifactsToConvert )
-        {
-            artifacts.add( toArtifact( a ) );
-        }
-        return artifacts;
+        return artifactsToConvert.stream().map( RepositoryUtils::toArtifact ).collect( Collectors.toList() );
     }
 
     public static WorkspaceRepository getWorkspace( RepositorySystemSession session )