1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle.internal;
20
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.function.Function;
28 import java.util.stream.Collectors;
29
30 import org.apache.maven.artifact.ArtifactUtils;
31 import org.apache.maven.execution.MavenSession;
32 import org.apache.maven.project.MavenProject;
33
34
35
36
37
38
39
40
41
42
43 public class ProjectBuildList implements Iterable<ProjectSegment> {
44 private final List<ProjectSegment> items;
45
46 public ProjectBuildList(List<ProjectSegment> items) {
47 this.items = Collections.unmodifiableList(items);
48 }
49
50
51
52
53
54
55
56 public ProjectBuildList getByTaskSegment(TaskSegment taskSegment) {
57 return new ProjectBuildList(
58 items.stream().filter(pb -> taskSegment == pb.getTaskSegment()).collect(Collectors.toList()));
59 }
60
61 public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment taskSegment) {
62 return items.stream()
63 .filter(pb -> taskSegment == pb.getTaskSegment())
64 .collect(Collectors.toMap(ProjectSegment::getProject, Function.identity()));
65 }
66
67
68
69
70
71
72 public ProjectSegment findByMavenProject(MavenProject mavenProject) {
73 return items.stream()
74 .filter(pb -> mavenProject.equals(pb.getProject()))
75 .findFirst()
76 .orElse(null);
77 }
78
79 @Override
80 public Iterator<ProjectSegment> iterator() {
81 return items.iterator();
82 }
83
84 public void closeAll() {
85 for (ProjectSegment item : items) {
86 MavenSession sessionForThisModule = item.getSession();
87 sessionForThisModule.setCurrentProject(null);
88 }
89 }
90
91 public int size() {
92 return items.size();
93 }
94
95 public ProjectSegment get(int index) {
96 return items.get(index);
97 }
98
99 public Set<String> getReactorProjectKeys() {
100 Set<String> projectKeys = new HashSet<>(items.size() * 2);
101 for (ProjectSegment projectBuild : items) {
102 MavenProject project = projectBuild.getProject();
103 String key = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(), project.getVersion());
104 projectKeys.add(key);
105 }
106 return projectKeys;
107 }
108
109 public boolean isEmpty() {
110 return items.isEmpty();
111 }
112
113
114
115
116 public Set<MavenProject> getProjects() {
117 return items.stream().map(ProjectSegment::getProject).collect(Collectors.toSet());
118 }
119 }