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 org.apache.maven.execution.ProjectDependencyGraph;
23 import org.apache.maven.project.MavenProject;
24
25 import java.util.ArrayList;
26 import java.util.HashSet;
27 import java.util.List;
28
29
30
31
32
33
34
35
36
37 public class ConcurrencyDependencyGraph
38 {
39
40 private final ProjectBuildList projectBuilds;
41
42 private final ProjectDependencyGraph projectDependencyGraph;
43
44 private final HashSet<MavenProject> finishedProjects = new HashSet<MavenProject>();
45
46
47 public ConcurrencyDependencyGraph( ProjectBuildList projectBuilds, ProjectDependencyGraph projectDependencyGraph )
48 {
49 this.projectDependencyGraph = projectDependencyGraph;
50 this.projectBuilds = projectBuilds;
51 }
52
53
54 public int getNumberOfBuilds()
55 {
56 return projectBuilds.size();
57 }
58
59
60
61
62
63
64
65 public List<MavenProject> getRootSchedulableBuilds()
66 {
67 List<MavenProject> result = new ArrayList<MavenProject>();
68 for ( ProjectSegment projectBuild : projectBuilds )
69 {
70 if ( projectDependencyGraph.getUpstreamProjects( projectBuild.getProject(), false ).size() == 0 )
71 {
72 result.add( projectBuild.getProject() );
73 }
74 }
75 return result;
76 }
77
78
79
80
81
82
83
84 public List<MavenProject> markAsFinished( MavenProject mavenProject )
85 {
86 finishedProjects.add( mavenProject );
87 return getSchedulableNewProcesses( mavenProject );
88 }
89
90 private List<MavenProject> getSchedulableNewProcesses( MavenProject finishedProject )
91 {
92 List<MavenProject> result = new ArrayList<MavenProject>();
93
94 for ( MavenProject dependentProject : projectDependencyGraph.getDownstreamProjects( finishedProject, false ) )
95 {
96 final List<MavenProject> upstreamProjects =
97 projectDependencyGraph.getUpstreamProjects( dependentProject, false );
98 if ( finishedProjects.containsAll( upstreamProjects ) )
99 {
100 result.add( dependentProject );
101 }
102 }
103 return result;
104 }
105
106 public ProjectBuildList getProjectBuilds()
107 {
108 return projectBuilds;
109 }
110 }