1 package org.apache.maven.container;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.PlexusContainer;
23 import org.codehaus.plexus.component.repository.ComponentDescriptor;
24
25 import java.util.HashMap;
26 import java.util.LinkedHashMap;
27 import java.util.Map;
28 import java.util.Set;
29
30 public class ContainerUtils
31 {
32
33 public static Set<String> findChildComponentHints( String role, PlexusContainer parent, PlexusContainer child )
34 {
35 return findChildComponents( role, parent, child ).keySet();
36 }
37
38 @SuppressWarnings( "unchecked" )
39 public static Map<String, ComponentDescriptor> findChildComponents( String role, PlexusContainer parent, PlexusContainer child )
40 {
41 Map<String, ComponentDescriptor> parentComponents = parent.getComponentDescriptorMap( role );
42 if ( parentComponents != null )
43 {
44 parentComponents = new LinkedHashMap<String, ComponentDescriptor>( parentComponents );
45 }
46
47 Map<String, ComponentDescriptor> childComponents = child.getComponentDescriptorMap( role );
48 if ( childComponents == null )
49 {
50 return new HashMap<String, ComponentDescriptor>();
51 }
52 else
53 {
54 childComponents = new LinkedHashMap<String, ComponentDescriptor>( childComponents );
55 if ( parentComponents != null && !parentComponents.isEmpty() )
56 {
57 for ( Map.Entry<String, ComponentDescriptor> entry : parentComponents.entrySet() )
58 {
59 String hint = entry.getKey();
60
61 if ( childComponents.containsKey( hint ) && entry.getValue() == childComponents.get( hint ) )
62 {
63 childComponents.remove( hint );
64 }
65 }
66 }
67 }
68
69 return childComponents;
70 }
71
72 }