1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.cli;
20
21 import java.util.function.Function;
22
23 import com.google.inject.Binder;
24 import com.google.inject.Module;
25 import com.google.inject.name.Names;
26 import org.apache.maven.api.services.Interpolator;
27 import org.apache.maven.api.xml.XmlNode;
28 import org.apache.maven.extension.internal.CoreExtensionEntry;
29 import org.apache.maven.internal.impl.model.DefaultInterpolator;
30 import org.apache.maven.internal.xml.XmlNodeImpl;
31 import org.apache.maven.internal.xml.XmlPlexusConfiguration;
32 import org.apache.maven.model.v4.MavenTransformer;
33 import org.codehaus.plexus.configuration.PlexusConfiguration;
34
35 @Deprecated
36 public class ExtensionConfigurationModule implements Module {
37
38 private final CoreExtensionEntry extension;
39 private final Function<String, String> callback;
40 private final DefaultInterpolator interpolator = new DefaultInterpolator();
41
42 public ExtensionConfigurationModule(CoreExtensionEntry extension, Function<String, String> callback) {
43 this.extension = extension;
44 this.callback = callback;
45 }
46
47 @Override
48 public void configure(Binder binder) {
49 if (extension.getKey() != null) {
50 XmlNode configuration = extension.getConfiguration();
51 if (configuration == null) {
52 configuration = new XmlNodeImpl("configuration");
53 }
54 Function<String, String> cb = Interpolator.memoize(callback);
55 Function<String, String> it = s -> interpolator.interpolate(s, cb);
56 configuration = new ExtensionInterpolator(it).transform(configuration);
57
58 binder.bind(XmlNode.class)
59 .annotatedWith(Names.named(extension.getKey()))
60 .toInstance(configuration);
61 binder.bind(PlexusConfiguration.class)
62 .annotatedWith(Names.named(extension.getKey()))
63 .toInstance(XmlPlexusConfiguration.toPlexusConfiguration(configuration));
64 }
65 }
66
67 static class ExtensionInterpolator extends MavenTransformer {
68 ExtensionInterpolator(Function<String, String> transformer) {
69 super(transformer);
70 }
71
72 public XmlNode transform(XmlNode node) {
73 return super.transform(node);
74 }
75 }
76 }