View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.configuration.internal;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import org.codehaus.plexus.classworlds.realm.ClassRealm;
25  import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
26  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
27  import org.codehaus.plexus.component.configurator.ConfigurationListener;
28  import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter;
29  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
30  import org.codehaus.plexus.configuration.PlexusConfiguration;
31  
32  /**
33   * A component configurator which can leverage the {@link EnhancedConfigurationConverter}
34   * and {@link EnhancedConverterLookup}.
35   */
36  @Singleton
37  @Named("enhanced")
38  public class EnhancedComponentConfigurator extends BasicComponentConfigurator {
39  
40      public EnhancedComponentConfigurator() {
41          converterLookup = new EnhancedConverterLookup();
42      }
43  
44      @Override
45      public void configureComponent(
46              final Object component,
47              final PlexusConfiguration configuration,
48              final ExpressionEvaluator evaluator,
49              final ClassRealm realm,
50              final ConfigurationListener listener)
51              throws ComponentConfigurationException {
52          try {
53              ClassRealmConverter.pushContextRealm(realm);
54  
55              this.configureComponent(component, configuration, evaluator, (ClassLoader) realm, listener);
56          } finally {
57              ClassRealmConverter.popContextRealm();
58          }
59      }
60  
61      public void configureComponent(
62              Object component,
63              PlexusConfiguration configuration,
64              ExpressionEvaluator evaluator,
65              ClassLoader loader,
66              ConfigurationListener listener)
67              throws ComponentConfigurationException {
68          new EnhancedConfigurationConverter()
69                  .processConfiguration(
70                          converterLookup,
71                          component,
72                          loader, //
73                          configuration,
74                          evaluator,
75                          listener);
76      }
77  }