1 package org.codehaus.plexus.component.discovery;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.Reader;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.codehaus.plexus.classworlds.realm.ClassRealm;
24 import org.codehaus.plexus.component.repository.ComponentDescriptor;
25 import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
26 import org.codehaus.plexus.component.repository.io.PlexusTools;
27 import org.codehaus.plexus.configuration.PlexusConfiguration;
28 import org.codehaus.plexus.configuration.PlexusConfigurationException;
29
30
31
32
33 public class DefaultComponentDiscoverer extends AbstractResourceBasedComponentDiscoverer {
34 public String getComponentDescriptorLocation() {
35 return "META-INF/plexus/components.xml";
36 }
37
38 public ComponentSetDescriptor createComponentDescriptors(
39 Reader componentDescriptorReader, String source, ClassRealm realm) throws PlexusConfigurationException {
40 PlexusConfiguration componentDescriptorConfiguration =
41 PlexusTools.buildConfiguration(source, componentDescriptorReader);
42
43 ComponentSetDescriptor componentSetDescriptor = new ComponentSetDescriptor();
44
45 List<ComponentDescriptor<?>> componentDescriptors = new ArrayList<ComponentDescriptor<?>>();
46
47 PlexusConfiguration[] componentConfigurations =
48 componentDescriptorConfiguration.getChild("components").getChildren("component");
49
50 for (PlexusConfiguration componentConfiguration : componentConfigurations) {
51 ComponentDescriptor<?> componentDescriptor;
52 try {
53 componentDescriptor = PlexusTools.buildComponentDescriptor(componentConfiguration, realm);
54 } catch (PlexusConfigurationException e) {
55
56
57
58
59
60
61
62 continue;
63 }
64
65 componentDescriptor.setSource(source);
66
67 componentDescriptor.setComponentType("plexus");
68
69 componentDescriptor.setComponentSetDescriptor(componentSetDescriptor);
70
71 componentDescriptors.add(componentDescriptor);
72 }
73
74 componentSetDescriptor.setComponents(componentDescriptors);
75
76 componentSetDescriptor.setSource(source);
77
78 return componentSetDescriptor;
79 }
80 }