1 package org.codehaus.plexus.component.discovery;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.io.Reader;
18 import java.util.Arrays;
19
20 import org.codehaus.plexus.classworlds.realm.ClassRealm;
21 import org.codehaus.plexus.component.repository.ComponentDescriptor;
22 import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
23 import org.codehaus.plexus.component.repository.io.PlexusTools;
24 import org.codehaus.plexus.configuration.PlexusConfiguration;
25 import org.codehaus.plexus.configuration.PlexusConfigurationException;
26
27 public class PlexusXmlComponentDiscoverer extends AbstractResourceBasedComponentDiscoverer {
28 public String getComponentDescriptorLocation() {
29 return "META-INF/plexus/plexus.xml";
30 }
31
32 @Override
33 protected ComponentSetDescriptor createComponentDescriptors(Reader reader, String source, ClassRealm realm)
34 throws PlexusConfigurationException {
35 ComponentSetDescriptor componentSetDescriptor = new ComponentSetDescriptor();
36
37 PlexusConfiguration configuration = PlexusTools.buildConfiguration(source, reader);
38
39 if (configuration != null) {
40 PlexusConfiguration[] componentConfigurations =
41 configuration.getChild("components").getChildren("component");
42
43 for (PlexusConfiguration componentConfiguration : componentConfigurations) {
44 ComponentDescriptor<?> componentDescriptor;
45
46 try {
47 componentDescriptor = PlexusTools.buildComponentDescriptor(componentConfiguration, realm);
48
49 if (componentDescriptor == null) {
50 continue;
51 }
52 } catch (PlexusConfigurationException e) {
53 throw new PlexusConfigurationException(
54 "Cannot build component descriptor from resource found in:\n"
55 + Arrays.asList(realm.getURLs()),
56 e);
57 }
58
59 componentDescriptor.setComponentType("plexus");
60
61 componentDescriptor.setComponentSetDescriptor(componentSetDescriptor);
62
63 componentSetDescriptor.addComponentDescriptor(componentDescriptor);
64 }
65 }
66
67 return componentSetDescriptor;
68 }
69 }