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

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


The following commit(s) were added to refs/heads/MNG-7764 by this push:
     new 1173f71b8 [MNG-7764] - followup
1173f71b8 is described below

commit 1173f71b88c14742c66b317b5f8e8ba60c4af806
Author: Karl Heinz Marbaise <khmarba...@apache.org>
AuthorDate: Sat Apr 29 12:52:36 2023 +0200

    [MNG-7764] - followup
---
 .../maven/lifecycle/internal/ProjectBuildList.java | 27 +++++------------
 .../maven/lifecycle/mapping/LifecyclePhase.java    | 34 +++++++++-------------
 .../java/org/apache/maven/model/DeveloperTest.java | 11 -------
 3 files changed, 22 insertions(+), 50 deletions(-)

diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ProjectBuildList.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ProjectBuildList.java
index 7447e7877..2ad171aa2 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ProjectBuildList.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ProjectBuildList.java
@@ -60,13 +60,9 @@ public class ProjectBuildList implements 
Iterable<ProjectSegment> {
     }
 
     public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment 
taskSegment) {
-        Map<MavenProject, ProjectSegment> result = new HashMap<>();
-        for (ProjectSegment projectBuild : items) {
-            if (taskSegment == projectBuild.getTaskSegment()) { // NOTE: 
There's no notion of taskSegment equality.
-                result.put(projectBuild.getProject(), projectBuild);
-            }
-        }
-        return result;
+        return items.stream()
+                .filter(pb -> taskSegment == pb.getTaskSegment())
+                .collect(Collectors.toMap(ProjectSegment::getProject, 
Function.identity()));
     }
 
     /**
@@ -75,12 +71,10 @@ public class ProjectBuildList implements 
Iterable<ProjectSegment> {
      * @return The projectSegment or null.
      */
     public ProjectSegment findByMavenProject(MavenProject mavenProject) {
-        for (ProjectSegment projectBuild : items) {
-            if (mavenProject.equals(projectBuild.getProject())) {
-                return projectBuild;
-            }
-        }
-        return null;
+        return items.stream()
+                .filter(pb -> mavenProject.equals(pb.getProject()))
+                .findFirst()
+                .orElse(null);
     }
 
     public Iterator<ProjectSegment> iterator() {
@@ -120,11 +114,6 @@ public class ProjectBuildList implements 
Iterable<ProjectSegment> {
      * @return a set of all the projects managed by the build
      */
     public Set<MavenProject> getProjects() {
-        Set<MavenProject> projects = new HashSet<>();
-
-        for (ProjectSegment s : items) {
-            projects.add(s.getProject());
-        }
-        return projects;
+        return 
items.stream().map(ProjectSegment::getProject).collect(Collectors.toSet());
     }
 }
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
index 441e23bcb..ad0210d6a 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
@@ -19,10 +19,14 @@
 package org.apache.maven.lifecycle.mapping;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import org.codehaus.plexus.util.StringUtils;
 
@@ -54,31 +58,21 @@ public class LifecyclePhase {
 
         if (StringUtils.isNotEmpty(goals)) {
             String[] mojoGoals = StringUtils.split(goals, ",");
-
-            for (String mojoGoal : mojoGoals) {
-                LifecycleMojo lifecycleMojo = new LifecycleMojo();
-                lifecycleMojo.setGoal(mojoGoal.trim());
-                mojos.add(lifecycleMojo);
-            }
+            mojos = 
Arrays.stream(mojoGoals).map(fromGoalIntoLifecycleMojo).collect(Collectors.toList());
         }
     }
 
+    private final Function<String, LifecycleMojo> fromGoalIntoLifecycleMojo = 
s -> {
+        LifecycleMojo lifecycleMojo = new LifecycleMojo();
+        lifecycleMojo.setGoal(s.trim());
+        return lifecycleMojo;
+    };
+
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        List<LifecycleMojo> mojos = getMojos();
-        if (mojos != null) {
-            for (LifecycleMojo mojo : mojos) {
-                if (first) {
-                    first = false;
-                } else {
-                    sb.append(',');
-                }
-                sb.append(mojo.getGoal());
-            }
-        }
-        return sb.toString();
+        return 
Optional.ofNullable(getMojos()).orElse(Collections.emptyList()).stream()
+                .map(LifecycleMojo::getGoal)
+                .collect(Collectors.joining(","));
     }
 
     @Deprecated
diff --git 
a/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java 
b/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java
index 2c31b756b..8aada02b3 100644
--- a/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java
+++ b/maven-model/src/test/java/org/apache/maven/model/DeveloperTest.java
@@ -53,15 +53,4 @@ class DeveloperTest {
     void testToStringNullSafe() {
         assertNotNull(new Developer().toString());
     }
-
-    public void testToStringNotNonsense() {
-        Developer dev = new Developer();
-        dev.setName("Maven Tester");
-        dev.setEmail("tester@acme.localdomain");
-        dev.setId("20220118");
-
-        String s = dev.toString();
-
-        assert "Developer {id=20220118, Contributor {name=Maven Tester, 
email=tester@acme.localdomain}}".equals(s) : s;
-    }
 }

Reply via email to