1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.transport.wagon;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import org.apache.maven.wagon.Wagon;
26 import org.codehaus.plexus.PlexusContainer;
27 import org.codehaus.plexus.classworlds.realm.ClassRealm;
28 import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator;
29 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
30 import org.codehaus.plexus.component.configurator.ConfigurationListener;
31 import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter;
32 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
33 import org.codehaus.plexus.configuration.PlexusConfiguration;
34 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
35 import org.codehaus.plexus.util.xml.Xpp3Dom;
36 import org.eclipse.aether.transport.wagon.WagonConfigurator;
37
38 import static java.util.Objects.requireNonNull;
39
40
41
42
43 @Named("plexus")
44 @Singleton
45 public class PlexusWagonConfigurator implements WagonConfigurator {
46 private final PlexusContainer container;
47
48
49
50
51
52
53 @Inject
54 public PlexusWagonConfigurator(final PlexusContainer container) {
55 this.container = requireNonNull(container, "plexus container cannot be null");
56 }
57
58 public void configure(Wagon wagon, Object configuration) throws Exception {
59 requireNonNull(wagon, "wagon cannot be null");
60 requireNonNull(configuration, "configuration cannot be null");
61
62 PlexusConfiguration config;
63 if (configuration instanceof PlexusConfiguration) {
64 config = (PlexusConfiguration) configuration;
65 } else if (configuration instanceof Xpp3Dom) {
66 config = new XmlPlexusConfiguration((Xpp3Dom) configuration);
67 } else {
68 throw new IllegalArgumentException(
69 "unexpected configuration type: " + configuration.getClass().getName());
70 }
71
72 WagonComponentConfigurator configurator = new WagonComponentConfigurator();
73
74 configurator.configureComponent(wagon, config, container.getContainerRealm());
75 }
76
77 static class WagonComponentConfigurator extends AbstractComponentConfigurator {
78
79 @Override
80 public void configureComponent(
81 Object component,
82 PlexusConfiguration configuration,
83 ExpressionEvaluator expressionEvaluator,
84 ClassRealm containerRealm,
85 ConfigurationListener listener)
86 throws ComponentConfigurationException {
87 ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter();
88
89 converter.processConfiguration(
90 converterLookup, component, containerRealm, configuration, expressionEvaluator, listener);
91 }
92 }
93 }