1 package org.apache.maven;
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.Collection;
24 import java.util.IdentityHashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.apache.maven.execution.ProjectDependencyGraph;
29 import org.apache.maven.project.MavenProject;
30
31
32
33
34
35
36 class FilteredProjectDependencyGraph
37 implements ProjectDependencyGraph
38 {
39
40 private ProjectDependencyGraph projectDependencyGraph;
41
42 private Map<MavenProject, ?> whiteList;
43
44 private List<MavenProject> sortedProjects;
45
46
47
48
49
50
51
52 public FilteredProjectDependencyGraph( ProjectDependencyGraph projectDependencyGraph,
53 Collection<? extends MavenProject> whiteList )
54 {
55 if ( projectDependencyGraph == null )
56 {
57 throw new IllegalArgumentException( "project dependency graph missing" );
58 }
59
60 this.projectDependencyGraph = projectDependencyGraph;
61
62 this.whiteList = new IdentityHashMap<MavenProject, Object>();
63
64 for ( MavenProject project : whiteList )
65 {
66 this.whiteList.put( project, null );
67 }
68 }
69
70 public List<MavenProject> getSortedProjects()
71 {
72 if ( sortedProjects == null )
73 {
74 sortedProjects = applyFilter( projectDependencyGraph.getSortedProjects() );
75 }
76
77 return new ArrayList<MavenProject>( sortedProjects );
78 }
79
80 public List<MavenProject> getDownstreamProjects( MavenProject project, boolean transitive )
81 {
82 return applyFilter( projectDependencyGraph.getDownstreamProjects( project, transitive ) );
83 }
84
85 public List<MavenProject> getUpstreamProjects( MavenProject project, boolean transitive )
86 {
87 return applyFilter( projectDependencyGraph.getUpstreamProjects( project, transitive ) );
88 }
89
90 private List<MavenProject> applyFilter( Collection<? extends MavenProject> projects )
91 {
92 List<MavenProject> filtered = new ArrayList<MavenProject>( projects.size() );
93
94 for ( MavenProject project : projects )
95 {
96 if ( whiteList.containsKey( project ) )
97 {
98 filtered.add( project );
99 }
100 }
101
102 return filtered;
103 }
104
105 @Override
106 public String toString()
107 {
108 return getSortedProjects().toString();
109 }
110
111 }