/** * TODO: Enhance the ComponentRepository so that it can take entire ComponentSetDescriptors * instead of just ComponentDescriptors. */ public List discoverComponents(ClassRealm classRealm) throws PlexusConfigurationException, ComponentRepositoryException { List discoveredComponentDescriptors = new ArrayList(); for (Iterator i = componentDiscovererManager.getComponentDiscoverers().iterator(); i.hasNext(); ) { ComponentDiscoverer componentDiscoverer = (ComponentDiscoverer) i.next(); List componentSetDescriptors = componentDiscoverer.findComponents(getContext(), classRealm); for (Iterator j = componentSetDescriptors.iterator(); j.hasNext(); ) { ComponentSetDescriptor componentSet = (ComponentSetDescriptor) j.next(); List componentDescriptors = componentSet.getComponents(); if (componentDescriptors != null) { for (Iterator k = componentDescriptors.iterator(); k.hasNext(); ) { ComponentDescriptor componentDescriptor = (ComponentDescriptor) k.next(); componentDescriptor.setComponentSetDescriptor(componentSet); // If the user has already defined a component descriptor for this particular // component then do not let the discovered component descriptor override // the user defined one. if (getComponentDescriptor(componentDescriptor.getComponentKey()) == null) { addComponentDescriptor(componentDescriptor); // We only want to add components that have not yet been // discovered in a parent realm. We don't quite have fine // grained control over this right now but this is for // dynamic additions which are only happening from maven // at the moment. And plugins have a parent realm and // a grand parent realm so if the component has been // discovered it's most likely in those realms. // I actually need to keep track of what realm a component // was discovered in so that i can accurately search the // parents. discoveredComponentDescriptors.add(componentDescriptor); } } // discoveredComponentDescriptors.addAll( componentDescriptors ); } } } return discoveredComponentDescriptors; }
public static ComponentSetDescriptor buildComponentSet(PlexusConfiguration c) throws Exception { ComponentSetDescriptor csd = new ComponentSetDescriptor(); // ---------------------------------------------------------------------- // Components // ---------------------------------------------------------------------- PlexusConfiguration[] components = c.getChild("components").getChildren("component"); for (int i = 0; i < components.length; i++) { PlexusConfiguration component = components[i]; csd.addComponentDescriptor(buildComponentDescriptor(component)); } // ---------------------------------------------------------------------- // Dependencies // ---------------------------------------------------------------------- PlexusConfiguration[] dependencies = c.getChild("dependencies").getChildren("dependency"); for (int i = 0; i < dependencies.length; i++) { PlexusConfiguration d = dependencies[i]; ComponentDependency cd = new ComponentDependency(); cd.setArtifactId(d.getChild("artifact-id").getValue()); cd.setGroupId(d.getChild("group-id").getValue()); cd.setType(d.getChild("type").getValue()); cd.setVersion(d.getChild("version").getValue()); csd.addDependency(cd); } return csd; }