Search in sources :

Example 1 with ComponentConfigurator

use of org.codehaus.plexus.component.configurator.ComponentConfigurator in project maven-plugins by apache.

the class AbstractDeployMojo method configureWagon.

/**
     * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
     *
     * @param wagon
     * @param repositoryId
     * @param settings
     * @param container
     * @param log
     * @throws TransferFailedException
     * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
     */
private static void configureWagon(Wagon wagon, String repositoryId, Settings settings, PlexusContainer container, Log log) throws TransferFailedException {
    log.debug(" configureWagon ");
    // MSITE-25: Make sure that the server settings are inserted
    for (Server server : settings.getServers()) {
        String id = server.getId();
        log.debug("configureWagon server " + id);
        if (id != null && id.equals(repositoryId) && (server.getConfiguration() != null)) {
            final PlexusConfiguration plexusConf = new XmlPlexusConfiguration((Xpp3Dom) server.getConfiguration());
            ComponentConfigurator componentConfigurator = null;
            try {
                componentConfigurator = (ComponentConfigurator) container.lookup(ComponentConfigurator.ROLE, "basic");
                if (isMaven3OrMore()) {
                    componentConfigurator.configureComponent(wagon, plexusConf, container.getContainerRealm());
                } else {
                    configureWagonWithMaven2(componentConfigurator, wagon, plexusConf, container);
                }
            } catch (final ComponentLookupException e) {
                throw new TransferFailedException("While configuring wagon for \'" + repositoryId + "\': Unable to lookup wagon configurator." + " Wagon configuration cannot be applied.", e);
            } catch (ComponentConfigurationException e) {
                throw new TransferFailedException("While configuring wagon for \'" + repositoryId + "\': Unable to apply wagon configuration.", e);
            } finally {
                if (componentConfigurator != null) {
                    try {
                        container.release(componentConfigurator);
                    } catch (ComponentLifecycleException e) {
                        log.error("Problem releasing configurator - ignoring: " + e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Server(org.apache.maven.settings.Server) ComponentConfigurator(org.codehaus.plexus.component.configurator.ComponentConfigurator) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ComponentLifecycleException(org.codehaus.plexus.component.repository.exception.ComponentLifecycleException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 2 with ComponentConfigurator

use of org.codehaus.plexus.component.configurator.ComponentConfigurator in project maven-plugins by apache.

the class DefaultAssemblyArchiver method configureComponent.

private void configureComponent(final Object component, final Xpp3Dom config, final AssemblerConfigurationSource configSource) throws ComponentLookupException, ComponentConfigurationException {
    final ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, "basic");
    final ConfigurationListener listener = new DebugConfigurationListener(getLogger());
    final ExpressionEvaluator expressionEvaluator = new AssemblyExpressionEvaluator(configSource);
    final XmlPlexusConfiguration configuration = new XmlPlexusConfiguration(config);
    final Object[] containerRealm = getContainerRealm();
    /*
         * NOTE: The signature of configureComponent() has changed in Maven 3.x, the reflection prevents a linkage error
         * and makes the code work with both Maven 2 and 3.
         */
    try {
        final Method configureComponent = ComponentConfigurator.class.getMethod("configureComponent", Object.class, PlexusConfiguration.class, ExpressionEvaluator.class, (Class<?>) containerRealm[1], ConfigurationListener.class);
        configureComponent.invoke(configurator, component, configuration, expressionEvaluator, containerRealm[0], listener);
    } catch (final NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (final IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        if (e.getCause() instanceof ComponentConfigurationException) {
            throw (ComponentConfigurationException) e.getCause();
        }
        throw new RuntimeException(e.getCause());
    }
}
Also used : DebugConfigurationListener(org.apache.maven.plugin.DebugConfigurationListener) AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) ComponentConfigurator(org.codehaus.plexus.component.configurator.ComponentConfigurator) Method(java.lang.reflect.Method) AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator) InvocationTargetException(java.lang.reflect.InvocationTargetException) DebugConfigurationListener(org.apache.maven.plugin.DebugConfigurationListener) ConfigurationListener(org.codehaus.plexus.component.configurator.ConfigurationListener) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Aggregations

ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)2 ComponentConfigurator (org.codehaus.plexus.component.configurator.ComponentConfigurator)2 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DebugConfigurationListener (org.apache.maven.plugin.DebugConfigurationListener)1 AssemblyExpressionEvaluator (org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator)1 Server (org.apache.maven.settings.Server)1 TransferFailedException (org.apache.maven.wagon.TransferFailedException)1 ConfigurationListener (org.codehaus.plexus.component.configurator.ConfigurationListener)1 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)1 ComponentLifecycleException (org.codehaus.plexus.component.repository.exception.ComponentLifecycleException)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)1