View Javadoc
1   package org.eclipse.aether.internal.transport.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.wagon.Wagon;
23  import org.codehaus.plexus.PlexusContainer;
24  import org.codehaus.plexus.classworlds.realm.ClassRealm;
25  import org.codehaus.plexus.component.annotations.Component;
26  import org.codehaus.plexus.component.annotations.Requirement;
27  import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator;
28  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
29  import org.codehaus.plexus.component.configurator.ConfigurationListener;
30  import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter;
31  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
32  import org.codehaus.plexus.configuration.PlexusConfiguration;
33  import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
34  import org.codehaus.plexus.util.xml.Xpp3Dom;
35  import org.eclipse.aether.transport.wagon.WagonConfigurator;
36  
37  /**
38   * A wagon configurator based on the Plexus component configuration framework.
39   */
40  @Component( role = WagonConfigurator.class, hint = "plexus" )
41  public class PlexusWagonConfigurator
42      implements WagonConfigurator
43  {
44  
45      @Requirement
46      private PlexusContainer container;
47  
48      /**
49       * Creates an uninitialized wagon configurator.
50       * 
51       * @noreference This constructor only supports the Plexus IoC container and should not be called directly by
52       *              clients.
53       */
54      public PlexusWagonConfigurator()
55      {
56          // enables no-arg constructor
57      }
58  
59      /**
60       * Creates a wagon configurator using the specified Plexus container.
61       * 
62       * @param container The Plexus container instance to use, must not be {@code null}.
63       */
64      public PlexusWagonConfigurator( PlexusContainer container )
65      {
66          if ( container == null )
67          {
68              throw new IllegalArgumentException( "plexus container has not been specified" );
69          }
70          this.container = container;
71      }
72  
73      public void configure( Wagon wagon, Object configuration )
74          throws Exception
75      {
76          PlexusConfiguration config = null;
77          if ( configuration instanceof PlexusConfiguration )
78          {
79              config = (PlexusConfiguration) configuration;
80          }
81          else if ( configuration instanceof Xpp3Dom )
82          {
83              config = new XmlPlexusConfiguration( (Xpp3Dom) configuration );
84          }
85          else if ( configuration == null )
86          {
87              return;
88          }
89          else
90          {
91              throw new IllegalArgumentException( "Unexpected configuration type: " + configuration.getClass().getName() );
92          }
93  
94          WagonComponentConfigurator configurator = new WagonComponentConfigurator();
95  
96          configurator.configureComponent( wagon, config, container.getContainerRealm() );
97      }
98  
99      static class WagonComponentConfigurator
100         extends AbstractComponentConfigurator
101     {
102 
103         @Override
104         public void configureComponent( Object component, PlexusConfiguration configuration,
105                                         ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm,
106                                         ConfigurationListener listener )
107             throws ComponentConfigurationException
108         {
109             ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter();
110 
111             converter.processConfiguration( converterLookup, component, containerRealm, configuration,
112                                             expressionEvaluator, listener );
113         }
114 
115     }
116 
117 }