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