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 import org.apache.maven.artifact.ArtifactUtils;
30 import org.apache.maven.execution.MavenSession;
31 import org.apache.maven.project.MavenProject;
32
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 List<ProjectSegment> currentSegment = new ArrayList<>();
58 for (ProjectSegment projectBuild : items) {
59 if (taskSegment == projectBuild.getTaskSegment()) {
60 currentSegment.add(projectBuild);
61 }
62 }
63 return new ProjectBuildList(currentSegment);
64 }
65
66 public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment taskSegment) {
67 Map<MavenProject, ProjectSegment> result = new HashMap<>();
68 for (ProjectSegment projectBuild : items) {
69 if (taskSegment == projectBuild.getTaskSegment()) {
70 result.put(projectBuild.getProject(), projectBuild);
71 }
72 }
73 return result;
74 }
75
76
77
78
79
80
81 public ProjectSegment findByMavenProject(MavenProject mavenProject) {
82 for (ProjectSegment projectBuild : items) {
83 if (mavenProject.equals(projectBuild.getProject())) {
84 return projectBuild;
85 }
86 }
87 return null;
88 }
89
90 public Iterator<ProjectSegment> iterator() {
91 return items.iterator();
92 }
93
94 public void closeAll() {
95 for (ProjectSegment item : items) {
96 MavenSession sessionForThisModule = item.getSession();
97 sessionForThisModule.setCurrentProject(null);
98 }
99 }
100
101 public int size() {
102 return items.size();
103 }
104
105 public ProjectSegment get(int index) {
106 return items.get(index);
107 }
108
109 public Set<String> getReactorProjectKeys() {
110 Set<String> projectKeys = new HashSet<>(items.size() * 2);
111 for (ProjectSegment projectBuild : items) {
112 MavenProject project = projectBuild.getProject();
113 String key = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(), project.getVersion());
114 projectKeys.add(key);
115 }
116 return projectKeys;
117 }
118
119 public boolean isEmpty() {
120 return items.isEmpty();
121 }
122
123
124
125
126 public Set<MavenProject> getProjects() {
127 Set<MavenProject> projects = new HashSet<>();
128
129 for (ProjectSegment s : items) {
130 projects.add(s.getProject());
131 }
132 return projects;
133 }
134 }