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.ArrayList;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
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
44 public class ProjectBuildList implements Iterable<ProjectSegment> {
45 private final List<ProjectSegment> items;
46
47 public ProjectBuildList(List<ProjectSegment> items) {
48 this.items = Collections.unmodifiableList(items);
49 }
50
51
52
53
54
55
56
57 public ProjectBuildList getByTaskSegment(TaskSegment taskSegment) {
58 List<ProjectSegment> currentSegment = new ArrayList<>();
59 for (ProjectSegment projectBuild : items) {
60 if (taskSegment == projectBuild.getTaskSegment()) {
61 currentSegment.add(projectBuild);
62 }
63 }
64 return new ProjectBuildList(currentSegment);
65 }
66
67 public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment taskSegment) {
68 Map<MavenProject, ProjectSegment> result = new HashMap<>();
69 for (ProjectSegment projectBuild : items) {
70 if (taskSegment == projectBuild.getTaskSegment()) {
71 result.put(projectBuild.getProject(), projectBuild);
72 }
73 }
74 return result;
75 }
76
77
78
79
80
81
82 public ProjectSegment findByMavenProject(MavenProject mavenProject) {
83 for (ProjectSegment projectBuild : items) {
84 if (mavenProject.equals(projectBuild.getProject())) {
85 return projectBuild;
86 }
87 }
88 return null;
89 }
90
91 public Iterator<ProjectSegment> iterator() {
92 return items.iterator();
93 }
94
95 public void closeAll() {
96 for (ProjectSegment item : items) {
97 MavenSession sessionForThisModule = item.getSession();
98 sessionForThisModule.setCurrentProject(null);
99 }
100 }
101
102 public int size() {
103 return items.size();
104 }
105
106 public ProjectSegment get(int index) {
107 return items.get(index);
108 }
109
110 public Set<String> getReactorProjectKeys() {
111 Set<String> projectKeys = new HashSet<>(items.size() * 2);
112 for (ProjectSegment projectBuild : items) {
113 MavenProject project = projectBuild.getProject();
114 String key = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(), project.getVersion());
115 projectKeys.add(key);
116 }
117 return projectKeys;
118 }
119
120 public boolean isEmpty() {
121 return items.isEmpty();
122 }
123
124
125
126
127 public Set<MavenProject> getProjects() {
128 Set<MavenProject> projects = new HashSet<>();
129
130 for (ProjectSegment s : items) {
131 projects.add(s.getProject());
132 }
133 return projects;
134 }
135 }