Coverage Report - org.codehaus.plexus.component.discovery.PlexusXmlComponentDiscoverer
 
Classes in this File Line Coverage Branch Coverage Complexity
PlexusXmlComponentDiscoverer
82 %
14/17
66 %
4/6
3,5
 
 1  
 package org.codehaus.plexus.component.discovery;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 Codehaus Foundation.
 5  
  * 
 6  
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 7  
  * in compliance with the License. You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software distributed under the License
 12  
  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 13  
  * or implied. See the License for the specific language governing permissions and limitations under
 14  
  * the License.
 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  61
 public class PlexusXmlComponentDiscoverer
 28  
     extends AbstractResourceBasedComponentDiscoverer
 29  
 {
 30  
     public String getComponentDescriptorLocation()
 31  
     {
 32  139
         return "META-INF/plexus/plexus.xml";
 33  
     }
 34  
 
 35  
     @Override
 36  
     protected ComponentSetDescriptor createComponentDescriptors( Reader reader, String source, ClassRealm realm )
 37  
         throws PlexusConfigurationException
 38  
     {
 39  138
         ComponentSetDescriptor componentSetDescriptor = new ComponentSetDescriptor();
 40  
 
 41  138
         PlexusConfiguration configuration = PlexusTools.buildConfiguration( source, reader );
 42  
 
 43  138
         if ( configuration != null )
 44  
         {
 45  138
             PlexusConfiguration[] componentConfigurations = configuration.getChild( "components" ).getChildren( "component" );
 46  
 
 47  414
             for ( PlexusConfiguration componentConfiguration : componentConfigurations )
 48  
             {
 49  
                 ComponentDescriptor<?> componentDescriptor;
 50  
                 
 51  
                 try
 52  
                 {
 53  276
                     componentDescriptor = PlexusTools.buildComponentDescriptor( componentConfiguration, realm );
 54  
 
 55  276
                     if ( componentDescriptor == null )
 56  
                     {
 57  0
                         continue;
 58  
                     }
 59  
                 }
 60  0
                 catch ( PlexusConfigurationException e )
 61  
                 {
 62  0
                     throw new PlexusConfigurationException( "Cannot build component descriptor from resource found in:\n" + Arrays.asList( realm.getURLs() ), e );
 63  276
                 }
 64  
 
 65  276
                 componentDescriptor.setComponentType( "plexus" );
 66  
 
 67  276
                 componentDescriptor.setComponentSetDescriptor( componentSetDescriptor );
 68  
 
 69  276
                 componentSetDescriptor.addComponentDescriptor( componentDescriptor );
 70  
             }
 71  
         }
 72  
 
 73  138
         return componentSetDescriptor;
 74  
     }
 75  
 }