1 package org.apache.maven.lifecycle.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30
31 import org.apache.maven.artifact.ArtifactUtils;
32 import org.apache.maven.execution.MavenSession;
33 import org.apache.maven.project.MavenProject;
34
35
36
37
38
39
40
41
42
43
44
45 public class ProjectBuildList
46 implements Iterable<ProjectSegment>
47 {
48 private final List<ProjectSegment> items;
49
50 public ProjectBuildList( List<ProjectSegment> items )
51 {
52 this.items = Collections.unmodifiableList( items );
53 }
54
55
56
57
58
59
60
61 public ProjectBuildList getByTaskSegment( TaskSegment taskSegment )
62 {
63 List<ProjectSegment> currentSegment = new ArrayList<>();
64 for ( ProjectSegment projectBuild : items )
65 {
66 if ( taskSegment == projectBuild.getTaskSegment() )
67 {
68 currentSegment.add( projectBuild );
69 }
70 }
71 return new ProjectBuildList( currentSegment );
72 }
73
74 public Map<MavenProject, ProjectSegment> selectSegment( TaskSegment taskSegment )
75 {
76 Map<MavenProject, ProjectSegment> result = new HashMap<>();
77 for ( ProjectSegment projectBuild : items )
78 {
79 if ( taskSegment == projectBuild.getTaskSegment() )
80 {
81 result.put( projectBuild.getProject(), projectBuild );
82 }
83 }
84 return result;
85 }
86
87
88
89
90
91
92 public ProjectSegment findByMavenProject( MavenProject mavenProject )
93 {
94 for ( ProjectSegment projectBuild : items )
95 {
96 if ( mavenProject.equals( projectBuild.getProject() ) )
97 {
98 return projectBuild;
99 }
100 }
101 return null;
102 }
103
104 public Iterator<ProjectSegment> iterator()
105 {
106 return items.iterator();
107 }
108
109 public void closeAll()
110 {
111 for ( ProjectSegment item : items )
112 {
113 MavenSession sessionForThisModule = item.getSession();
114 sessionForThisModule.setCurrentProject( null );
115 }
116 }
117
118 public int size()
119 {
120 return items.size();
121 }
122
123 public ProjectSegment get( int index )
124 {
125 return items.get( index );
126 }
127
128 public Set<String> getReactorProjectKeys()
129 {
130 Set<String> projectKeys = new HashSet<>( items.size() * 2 );
131 for ( ProjectSegment projectBuild : items )
132 {
133 MavenProject project = projectBuild.getProject();
134 String key = ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() );
135 projectKeys.add( key );
136 }
137 return projectKeys;
138 }
139
140
141 public boolean isEmpty()
142 {
143 return items.isEmpty();
144 }
145
146
147
148
149 public Set<MavenProject> getProjects()
150 {
151 Set<MavenProject> projects = new HashSet<>();
152
153 for ( ProjectSegment s : items )
154 {
155 projects.add( s.getProject() );
156 }
157 return projects;
158 }
159 }